Solved

Play sound on DIV click

Posted on 2011-09-10
12
396 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
  • 5
  • 5
  • 2
12 Comments
 
LVL 40

Accepted Solution

by:
gurvinder372 earned 500 total points
ID: 36518203
0
 
LVL 15

Expert Comment

by:myselfrandhawa
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
 
LVL 40

Expert Comment

by:gurvinder372
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:gurvinder372
ID: 36520812
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 15

Expert Comment

by:myselfrandhawa
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:gurvinder372
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:gurvinder372
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
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…
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…

705 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now