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

New Developer
Posts: 11
Registered: ‎06-11-2009
My Device: Not Specified
Accepted Solution

Can't play a user selected audio file

I'm having problems getting a user selected audio file to play. I know you can't play the ones RIM supplies, but here's what I have:


Class cl = Class.forName("bb.cen.CallEnd");
InputStream input = cl.getResourceAsStream(soundToPlay);

m_player = Manager.createPlayer(input, "audio/mpeg");





soundToPlay is gotten from:


soundToPlay = "file:///" + oData.getStringElement(OptionsData.USERSOUND);


OptionsData.USERSOUND is gotten from a file selection popup screen using getFile().

It is usually something like /SDCard/Blackberry/ringtones/sound.wav


Whenever I run it though, I can select the file, but I always get a 

FRIDG:  cannot find......

I know I'm getting this because getResourceAsStream is returning null.

How do I get it to not return null?



Posts: 1,807
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-, Z10 (STL100-3)-, Z30 (STA100-5)-, Passport (SQW100-1)-, PlayBook (16GB)-
My Carrier: Verizon

Re: Can't play a user selected audio file

getResourceAsStream gets a file that is built into a RIM app. soundToPlay goes to a file location, try passing soundToPlay into Manager.createPlayer instead of trying to get it **bleep** a embedded resource. If it is a embedded resource then you need to access it like you do with Class.forName only you pass the String into getResourceAsStream.


Hope that makes sense.

---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.
New Developer
Posts: 11
Registered: ‎06-11-2009
My Device: Not Specified

Re: Can't play a user selected audio file

Yessiree bob. That did the trick.

Thank you.


I'm just confused as to why they would provide a method that lets you get files that you can't even use....