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

BlackBerry® World™ Development

Reply
Developer
Blanc
Posts: 638
Registered: ‎07-02-2009
My Device: Not Specified
Accepted Solution

Whats wrong with this playing audio files...!!!!????????

 

Hi all,

               am trying  to play two different audio files with following piece of code. individually they are playing well. when am trying  to play them at a same time that is simultaneously it is giving IllegalStateException and not playing any audio file.

when i play them separately they are playing well. my requirement is to play 1 file as background audio and another as foreground.

 

 

// code for playing audio. 

 

public class Audio implements Runnable//extends Thread { private Class clazz; private InputStream is; public Player player; private String audiofile; private int fileType; private int mode; public Audio(String path, int type, int mode) { audiofile = path; fileType = type; this.mode = mode; } public void run() { //this sample demonstrates playing an MP3 file that has been //added as a resource to the project try { //retrieve the MP3 file clazz = getClass(); //create an instance of the player from the InputStream is = clazz.getResourceAsStream(audiofile); // 1-- mpeg, 2-- wav audio files if(fileType == 1) player = javax.microedition.media.Manager.createPlayer(is, "audio/mpeg"); else if(fileType ==2) player = javax.microedition.media.Manager.createPlayer(is, "audio/x-wav"); player.setLoopCount(mode); player.realize(); player.prefetch(); player.start(); } catch (Exception ex) { UiApplication.getUiApplication().pushScreen(new CloseScreen("Hello")); } } }

 

 

// if call this, commenting section2 it works well //section1 Audio at = new Audio("/neon1.wav",2, -1); Thread at1 = new Thread(at); at1.start(); // if call this, commenting section1 it works well //section2 Audio at3 = new Audio("/neon1.wav",2, -1); Thread at2 = new Thread(at3); at2.start(); // when i uncomment both section1 and section2 and execute it is not playing giving an exception IllegalStateException.

 

 

any help should be of great use.

 

 

Thanks and Regards,

PraveenG 

 

Thanks and Regards,
PraveenGoparaju.
Please use plain text.
Developer
RLord321
Posts: 343
Registered: ‎02-23-2009
My Device: 8700 | 8310 | BOLD | STORM

Re: Whats wrong with this playing audio files...!!!!????????

[ Edited ]

Blanc,

 

Some phones (CDMA) will not let you play multiple sounds at once. You can however play background music and tones (from the Audio class) at the same time in these devices.

 

So what I am developing now is different options for sounds. For phones that can do multiple sounds (BOLD's, AT&T Curves, etc), I have background MIDI's and .wav (cool) sound effects. For the STORM, the user can select an option that gives them background MIDI music and tone (cheap 80's sounding) sound effects. The other option is for the STORM to only play the cool (.wav) sound effects and no background music.

 

I don't want to make this an option for the user to select so I think I'm going to add code upon startup of the application to play the background music with a volume of 0 and then play a .wav file. I'm then going to check the state of the background music to see if it is stopped. If so, then the logic will know if it can play more than one sound at once....

 

I hope this helps.

Message Edited by RLord321 on 08-21-2009 03:43 PM
Please use plain text.
Developer
Blanc
Posts: 638
Registered: ‎07-02-2009
My Device: Not Specified

Re: Whats wrong with this playing audio files...!!!!????????

Hi  RLord321,

                          Thanks for your reply. i didnt get exactly what you are saying or what you are suggesting me to do... can you be more eloborate or detail???

                       My requirement is to play one sound constantly throughout the app and other sounds at random places which come along with the app. so at a particulat instant of time i need to hear two sounds at the same time. is it possible..?? am developing for BBStrom. using 4.7version. 

 

           please be little bit detailed on....

 

"I don't want to make this an option for the user to select so I think I'm going to add code upon startup of the application to play the background music with a volume of 0 and then play a .wav file. I'm then going to check the state of the background music to see if it is stopped. If so, then the logic will know if it can play more than one sound at once...."

 

 

 

 

suggest me how to reach my requirement.....

 

 

Thanks and Regards,

PraveenG 

Thanks and Regards,
PraveenGoparaju.
Please use plain text.
Developer
RLord321
Posts: 343
Registered: ‎02-23-2009
My Device: 8700 | 8310 | BOLD | STORM

Re: Whats wrong with this playing audio files...!!!!????????

On the Storm, it is not possible to play 2 sounds loaded from a file at a time.  If you try this, the first sound will be cut off and the second sound will be played.

 

You can, however, load and play one sound (background music) and play the other sounds (Sound Effects) using Alert.startAudio( ).  The first sound will not be cut off.  The only problem with this is that the Alert.startAudio sounds are not the best.

 

 

Please use plain text.