Solved

Play Sound in HTML 5

Posted on 2012-04-03
12
257 Views
Last Modified: 2012-06-27
Hello,

Please look at this.

https://englishbenchmarks.com/html5_sound_test.htm

This was the simplest POSSIBLE test I could think of.

It doesn't work.

Why?
0
Comment
Question by:Richard Korts
  • 7
  • 3
  • 2
12 Comments
 
LVL 17

Expert Comment

by:sonawanekiran
ID: 37800732
Try like this- Change code on click event of button

onclick="document.getElementById("sound1").play()"
0
 
LVL 17

Expert Comment

by:sonawanekiran
ID: 37800749
Place single quote

onclick="document.getElementById('sound1').play();"
0
 

Author Comment

by:Richard Korts
ID: 37800759
To sonawanekiran

That eliminates the error, but no sound plays.

Thanks.
0
Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

 
LVL 17

Assisted Solution

by:sonawanekiran
sonawanekiran earned 150 total points
ID: 37800761
Here is complete code. Tested

<!DOCTYPE html>

<html>
<head>
<title>HTML 5 Audio test</title>
</head>
<body>
<audio src="audio/soundcheck_demo.mp3" preload="auto" autobuffer id="sound1"></audio>
<input type="button" value="Sound Check" name="go1" onClick="document.getElementById('sound1').play();">

</body>
</html>

Open in new window

0
 

Author Comment

by:Richard Korts
ID: 37800762
To sonawanekiran

I fixed the quotes problem.

No sound plays.
0
 

Author Comment

by:Richard Korts
ID: 37800843
To sonawanekiran

VERY strange.

I copied your code exactly.

Here are the results by browser:

FireFox Vers 11.o - No sound plays
IE Vers 8 - gets the attached error
Google Chrome - works perfectly

Crazy!!

I HAVE to make it work in IE & FireFox
html5-sound-IE.jpg
0
 

Author Comment

by:Richard Korts
ID: 37801713
One more comment.

My WHOLE reason for doing this is that I want to get an iPad version working.

This last version DOES work on the iPad; so, I can programatically (using php) use either the current version (you have not seen that) which works in IE & FireFox or this version on the iPad.

Of course it would be nicer is ONE version worked on all 4 browsers.
0
 
LVL 53

Accepted Solution

by:
COBOLdinosaur earned 350 total points
ID: 37801738
To work cross browser it requires more than one format for the audio file.  It will not work for older
browser that do not support HTML5 tags.  That means it will work in IE9 but probably nothing earlier:
<audio preload="auto" autobuffer id="sound1"></audio>
  <source src="song.ogg" type="audio/ogg" />
  <source src="song.mp3" type="audio/mp3" />
  Your browser does not support the audio tag.
</audio>

Open in new window


You can get a free mp3/ogg converter here:
http://download.cnet.com/Free-MP3-WMA-OGG-Converter/3000-2140_4-10793572.html


Cd&
0
 

Author Comment

by:Richard Korts
ID: 37801828
COBOLdinosaur

I'm sort of shocked that FireFox does not support HTML 5.

I have the VERY latest version of FireFox (Version 11.0).
0
 

Author Comment

by:Richard Korts
ID: 37801851
To COBOLdinosaur

Never mind, I found the answer, I need the ogg format.
0
 

Author Closing Comment

by:Richard Korts
ID: 37801970
Amazing that it requires IE 9, does NOT work in IE 8.

It now works PERFECT in FireFox (with an ogg version of the sound file).

Thanks
0
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 37802291
IE8 only supports about 10% of HTML5... IE9 is up to around 45%... FF and Chrome are over 90%.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

This article discusses four methods for overlaying images in a container on a web page
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 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…
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…

772 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