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
bbwebusr
Posts: 2
Registered: ‎02-07-2012
My Device: Playbook

help - Playing an audio file using WebWorks on Playbook or SmartPhone

Hi

Just spent a few hours downloading and setting up smartphone (version 7) simulators and PlayBook simulator with VMWare. 

 

DOwnloaded KitchenSink app showcasing html5 webworks - built this and ran on PB and BB (.cod and .bar files) deployed, after several attempts. 

 

However, I cannot find a way to play a sound file (mp3, wav or anything else) in Ripple, simulator or real devices.

 

Can someone post the appropriate javascript code (with webworks or native support) to play an audio file on click of a hyperlink.

 

I don't want to show natie html5 (browser control) - I want to add an eventListener or call a javascript function to run the audio when the user clicks/taps a link.

 

This is the last thing I need to do to get my mini app working on pb.

 

thanks.

 

New Contributor
bbwebusr
Posts: 2
Registered: ‎02-07-2012
My Device: Playbook

Re: help - Playing an audio file using WebWorks on Playbook or SmartPhone

Found some posts stating problems with simulator - ok, thats fine, but this still doesn't work on a real device either, once I've packaged and deployed. Snippit of sample javascript anyone?

cheers

Developer
Puzzling
Posts: 51
Registered: ‎10-22-2011
My Device: 9800

Re: help - Playing an audio file using WebWorks on Playbook or SmartPhone

Developer
colforbin13
Posts: 28
Registered: ‎03-21-2011
My Device: Torch 9800

Re: help - Playing an audio file using WebWorks on Playbook or SmartPhone

The simplest way I've found is to set up the HTML5 audio tag:

<audio preload="auto" autobuffer id="audio">
  <source src="audio/1.wav">
</audio>

 Then put this in any HTML tag (a, img, div, etc.):

onclick="document.getElementById('audio').play()"

 This will pre-buffer the audio file with no controls, and then clicking your link, image, whatever will start it playing.  There is also a .pause() function to stop playback if that's required.

------------------------------------
Twitter: @ChiSoxRunner
Script. Bake. Run.
Regular Contributor
fgoyti
Posts: 70
Registered: ‎06-15-2011
My Device: Bold 9900

Re: help - Playing an audio file using WebWorks on Playbook or SmartPhone

That works but on the Playbook, it pauses any other music you have on.  Any way to keep it separate?

Retired
astanley
Posts: 1,382
Registered: ‎07-02-2009
My Device: BlackBerry Bold 9900
My Carrier: Bell

Re: help - Playing an audio file using WebWorks on Playbook or SmartPhone

Unfortunately no, HTML5 audio currently supports single audio channel on PlayBook.  If you start playing a second audio file, you can expect the first to be stopped.  The BrowserDev team is working on expanding this (no ETA).

 

Understand that single channel audio restricts ability to provide certain features (e.g. background music + foreground sound effects), however it is what it is today, but will improve with a future build.


Flash does allow you to play multiple audio files, and we have an extension published as part of a WebGL-sample.  You can see and download the code here if interested to enable this capability in your WebWOrks apps:

https://github.com/blackberry/WebGL-Samples/tree/master/tunneltilt

 

 

Follow me on Twitter: @n_adam_stanley
-------------------------------------------------------------------------------------------------------------------------
Your app doesn't work? Use BlackBerry remote web inspector to find out why.
Regular Contributor
fgoyti
Posts: 70
Registered: ‎06-15-2011
My Device: Bold 9900

Re: help - Playing an audio file using WebWorks on Playbook or SmartPhone

Hi astanley,

 

Thanks for your feedback. I finally had time to experiment and I was able to play audio using the WebGL sample (using blackberry.custom.audio).  Great workaround!  Just one problem now: it works fine in the playbook but if the exact same code causes my javascript loop to stop in Ripple.  In other words, either Ripple did not see that the "blackberry.custom.audio" extension was added into the "ext" folder or it needs to be refreshed?  I can't figure out how to do that... Please help!

Regular Contributor
fgoyti
Posts: 70
Registered: ‎06-15-2011
My Device: Bold 9900

Re: help - Playing an audio file using WebWorks on Playbook or SmartPhone

On second thought.... .I just tested the tunneltilt app in Ripple and that doesn't work either.  I guess Ripple is still somewhat limited