Solved

Play sound on DIV click

Posted on 2011-09-10
12
405 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
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
This article discusses how to create an extensible mechanism for linked drop downs.
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…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

777 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