Welcome!

Welcome to the Official BlackBerry Support Community Forums. This is your resource to discuss support topics with your peers, and learn from each other. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Web and WebWorks Development

Reply
Developer
d_source
Posts: 116
Registered: ‎03-08-2011

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.

 

Thanks.

 

Please use plain text.
Trusted Contributor
mobilvar
Posts: 119
Registered: ‎11-28-2011
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.

Please use plain text.
Developer
d_source
Posts: 116
Registered: ‎03-08-2011

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.

Please use plain text.
Developer
greenback
Posts: 448
Registered: ‎10-17-2010

Re: How to add audio to HTML5 app

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.

:Cool2: 

Please use plain text.