Solved

Play sound on DIV click

Posted on 2011-09-10
12
406 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 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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
 
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: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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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…
Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
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)

830 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