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

Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.

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: 614
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.