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.

inside custom component

Web and WebWorks Development

Reply
New Contributor
OscarTux
Posts: 2
Registered: ‎05-09-2012
My Device: 9800
Accepted Solution

Using blackberry.audio.Player to play audio in a WebWorks app

I am trying to play some audio when the user taps on a button in my WebWorks app... 

 

function playAudio() {

    var playerInstance = new blackberry.audio.Player("audio/blah.aac");

    playerInstance.play();

}

 

This isn't working. I've tried all sorts of combinations and the only time I can seem to get it to work is if I move the audio clip out of my project and put it on the memory card as follows:

 

function playAudio() {

    var playerInstance = new blackberry.audio.Player("file:///SDCard/blah.aac");

    playerInstance.play();

}


How can I play audio that's built in to my WebWorks app?

 

Thanks

New Contributor
OscarTux
Posts: 2
Registered: ‎05-09-2012
My Device: 9800

Re: Using blackberry.audio.Player to play audio in a WebWorks app

Ok fixed! I should have had a better look at the forum first :-O

 

http://supportforums.blackberry.com/t5/Web-and-WebWorks-Development/Sound-will-NOT-play/m-p/1098623/...

 

This is working for me now:

 

function playAudio(src) {

var fn = "local:///audio/" + src;
try {
    var playerInstance = new blackberry.audio.Player(fn, "audio/x-aac", true);
    playerInstance.play();
} catch(err) {
    txt="Error playing audio\n\n" + fn + "\n\n";
    txt+="Error: " + err.message + "\n\n";
    txt+="Click OK to continue.\n\n";
    alert(txt);
}