Play sound on DIV click

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
LVL 1
debbieau1Asked:
Who is Participating?
 
Gurpreet Singh RandhawaWeb DeveloperCommented:
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
 
debbieau1Author Commented:
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
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

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

0
 
debbieau1Author Commented:
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
 
Gurpreet Singh RandhawaWeb DeveloperCommented:
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
 
debbieau1Author Commented:
I'm using php, but this really needs to be handled client side.  Thanks anyway
0
 
Gurvinder Pal SinghCommented:
did you checked the HTML5 audio tag on ipad?
0
 
debbieau1Author Commented:
Yep did that.  Have run audio successfully on the ipad, it's just when using multiple audio it has been a problem.
0
 
Gurvinder Pal SinghCommented:
did you used the play and pause apis of audio tag?
If yes, please share that code snippet
0
 
debbieau1Author Commented:
I'm going to have play more with that player when I get a chance

Thanks.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.