Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Play sound on DIV click

Posted on 2011-09-10
12
Medium Priority
?
430 Views
Last Modified: 2012-05-12
I want to play audio, when a <div> is clicked.

I will have multiple .mp3s.   I need to ensure if one is clicked, then others will not play, or repeat.

It needs to run on an ipad
0
Comment
Question by:debbieau1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
  • 2
12 Comments
 
LVL 40

Accepted Solution

by:
Gurvinder Pal Singh earned 2000 total points
ID: 36518203
0
 
LVL 16

Expert Comment

by:Gurpreet Singh Randhawa
ID: 36518299
as in th example provided above you can simply do like this

<script language="javascript" type="text/javascript">
 function playSound(soundfile) {
 document.getElementById("playsound").innerHTML= "<embed src=\""+soundfile+"\" hidden=\"true\" autostart=\"true\" loop=\"false\" />";
 }
 </script>

<div id="playsound" onclick="playSound('abc.mp3');" style="border:1px solid red;"></div>

you can always refer you path within the innerhtml tag

I gave a border to Div just to check if this really works as expected or not!

i have placed my abc.mpe in same folder

0
 
LVL 1

Author Comment

by:debbieau1
ID: 36520458
Unfortunately several of these solutions do not work on the ipad.  I had tried most previously.  The desktop isn't hard, particularly if using a flash solution, but the ipad has real latency issues and I am having problems when using multiple audio, that it will sometimes replay previous audio.

If you have any sample scripts using several audios that do work on the ipad without repeating, it would be great to get.
0
Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

 
LVL 40

Expert Comment

by:Gurvinder Pal Singh
ID: 36520766
For Ipad, you HTML5 audio tag. Check this example
http://www.jezra.net/code_examples/html5_audio/

0
 
LVL 1

Author Comment

by:debbieau1
ID: 36520774
Thanks very much for your perseverance.  I have managed to get audio playing on the ipad.  I think I may have an answer for the latency, but the biggest issue is still with having several audio files, that it gives unpredictable results.

Sometimes I click on one audio, then another, but a previous one plays, instead of the one just clicked.

I was trying to find a sample that I can test on the ipad, that plays several audios.  I need to make sure if I click one that it only plays that one.
0
 
LVL 40

Expert Comment

by:Gurvinder Pal Singh
ID: 36520812
0
 
LVL 16

Expert Comment

by:Gurpreet Singh Randhawa
ID: 36520949
can u use some server side lanaguage also

with that you can set the play the one and when other is clicked, the one should be stopped
0
 
LVL 1

Author Comment

by:debbieau1
ID: 36520968
I'm using php, but this really needs to be handled client side.  Thanks anyway
0
 
LVL 40

Expert Comment

by:Gurvinder Pal Singh
ID: 36520975
did you checked the HTML5 audio tag on ipad?
0
 
LVL 1

Author Comment

by:debbieau1
ID: 36520984
Yep did that.  Have run audio successfully on the ipad, it's just when using multiple audio it has been a problem.
0
 
LVL 40

Expert Comment

by:Gurvinder Pal Singh
ID: 36520986
did you used the play and pause apis of audio tag?
If yes, please share that code snippet
0
 
LVL 1

Author Closing Comment

by:debbieau1
ID: 36526390
I'm going to have play more with that player when I get a chance

Thanks.
0

Featured Post

The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

660 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question