Solved

Play sound on DIV click

Posted on 2011-09-10
12
424 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:
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
WordPress Tutorial 1: Installation & Setup

WordPress is a very popular option for running your web site and can be used to get your content online quickly for the world to see. This guide will walk you through installing the WordPress server software and the initial setup process.

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

630 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