06-13-2011 10:52 AM
Hi all,
I'm adding audio to my app. I'm using .MP3 for sound as i can't get .AAC to work (even though it's supposed to be supported).
My audio tags:
This works in a browser and works in a stand alone app: <audio src="sounds/sound1.MP3" preload id="sound1"></audio>
This works in a broswer but does NOT work in a stand alone app:
document.write('<audio src="sounds/sound1.MP3" preload id="sound1"></audio> ');
I write it to the screen and it prints properly, but no sound. Can anyone help explain why? I am testing on my actual Playbook, not the simulator. I need to print it using Javascript as there are too many sounds if i list them the other way. With javascript i limit the amount of sounds preloaded into the page depending on the other variables.
Thanks.
02-18-2012 10:46 PM
Did you ever get a resolution to this?
I'm having a problem with html5 audio as well.
02-20-2012 02:00 PM
Nope. Had to load all sounds when the page loads. Couldn't figure out another way to get it to work.
02-21-2012 04:06 AM
hi!
This sample code should be a good start. It works.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>audio/video sample code</title>
<!--local:///-->
<script>
function playSound(audio_file)
{
var ele = document.getElementById("audio");
ele.src="local:///files/" + audio_file;
ele.play();
//other methods available: pause, stop;
}
</script>
</head>
<body>
<audio preload="auto" style="visibility: hidden;" id="audio"></audio>
<div id="pianokey" onclick="playSound('C.mp3')"></div>
<div id="pianokey" onclick="playSound('Csharp.mp3')"></div>
<div id="pianokey" onclick="playSound('D.mp3')"></div>
</body>
</html>
Please "Like" this or Mark as a solution if my response helped. Thank you!
Good luck. Direct Message me if you need any other help.