Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Posts: 116
Registered: ‎03-08-2011
My Device: Not Specified

How to add audio to HTML5 app

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.




Trusted Contributor
Posts: 119
Registered: ‎11-28-2011
My Device: 9930
My Carrier: Verizon

Re: How to add audio to HTML5 app

Did you ever get a resolution to this?

I'm having a problem with html5 audio as well.

Posts: 116
Registered: ‎03-08-2011
My Device: Not Specified

Re: How to add audio to HTML5 app

Nope. Had to load all sounds when the page loads. Couldn't figure out another way to get it to work.

Posts: 610
Registered: ‎10-17-2010
My Device: (BlackBerry Z10)-> Q10/Passport Dual Use

Re: How to add audio to HTML5 app



This sample code should be a good start. It works.

<!DOCTYPE html>
<html lang="en">
    <meta charset="utf-8">
    <title>audio/video sample code</title>
        function playSound(audio_file)
            var ele = document.getElementById("audio");
            ele.src="local:///files/" + audio_file;

            //other methods available: pause, stop;
          <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>


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.