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

Java Development

Reply
Contributor
stkhan
Posts: 10
Registered: ‎06-16-2010
My Device: Curve 9300
My Carrier: Rogers

Play Audio File on Blackberry

Hello,

I am trying to play a wav file on the blackberry and the debug is not giving me an Exception to work with.  I have imported the wav file ('notify.wav') into my project as a resource (in the 'res' folder).  Below is the snippet of code that should play the audio file, but there's no sound when I invoke the method.

 

try{

InputStream inptstrm =getClass().getResourceAsStream("/res/notify.wav");

Player p = javax.microedition.media.Manager.createPlayer(inptstrm, "audio/x-wav");

p.realize();

VolumeControl volume = (VolumeControl)p.getControl("VolumeControl");

volume.setLevel(99);

p.prefetch();

p.start();

}

catch(Exception me){

}

 

I suspect my issue is with the import and finding where the file is to play.

Any assistance would be greatly appreciated.

Please use plain text.
Developer
peter_strange
Posts: 19,603
Registered: ‎07-14-2008
My Device: Not Specified

Re: Play Audio File on Blackberry

Agree finding the input file is the trick.

 

Don't think you need the res, just try

....getResourceAsStream("/notify.wav");

 

Do put some System.out.println(..) output in your exception handler too. 

Please use plain text.