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
Highlighted
New Developer
Posts: 8
Registered: ‎04-03-2009
My Device: Not Specified
Accepted Solution

Problem while playing MP3 in loop

Hello,

 

I am trying to play a mp3 file in loop on Blackberry pearl 8100, below is the code:

try
        {
           
            player=javax.microedition.media.Manager.createPlayer(getClass().getResourceAsStream("/Sound.mp3"),"audio/mpeg");
           
            player.realize();
            player.prefetch();
            player.setLoopCount(-1);
            player.start();
        }
        catch(Exception e)
        {
            System.out.println("Error in setting media:"+e);
           
        }

 

The problem is the sound plays for single time and after that I get below exception:

MEDIA_NATIVES: unload0() mediaHandle=0
MN: unload 1
MEDIA_NATIVES: init0() mediaHandle=0 status=0
MN: load 0
MEDIA_NATIVES: seekComplete0() mediaHandle=0
MEDIA_NATIVES: unload0() mediaHandle=0
MN: unload 1
Streaming done reason=1 prev-state=300
AUDIOMANAGER: IOException
Streaming done reason=1000 prev-state=300

 

This exception is coming automatically without and println statement...

 

Is there anything I am missing, please give me the solution.....

 

Regards,

Sanniv

 

Developer
Posts: 3,951
Registered: ‎07-15-2008
My Device: Not Specified

Re: Problem while playing MP3 in loop

Is it happening for other mp3 samples too? Did you get a chance to test for any other supported audio format. Is that working as desired on simulator.

 

Try a work around using PlayerListener and start the player again when the player stopped event is called.


Use Search. "Accept Solution" If the problem is resolved.
New Developer
Posts: 8
Registered: ‎04-03-2009
My Device: Not Specified

Re: Problem while playing MP3 in loop

Yes, it is happening with other mp3 samples too. I tried wav format too but again got same error. I am testing on simulator, same result.

I used PlayerListener too and when I get END_OF_MEDIA event I start the player, it doesn't give any exception in start method but after that again gives same "AUDIOMANAGER: IOEXCEPTION" error and doesn't play the sound in loop after one time play.

Developer
Posts: 218
Registered: ‎02-20-2009
My Device: Not Specified

Re: Problem while playing MP3 in loop

Please try this one 

class SND { Player _musicPlayer; // Java media player VolumeControl vc; static String _crntSndOpt ="Sound off"; SND() { } String getCrntSndOpt() { return _crntSndOpt; } public void setCrntSndOpt(String sndOption) { _crntSndOpt = sndOption; } // Play a mp3 file for background music void playMusic(String passMusic) { try { // Set InputStream to a midi file included as resource, as specified by // passMusic InputStream in = getClass().getResourceAsStream("/" + passMusic); // Create a media player with mime type of audio/mp3 using our inputstream _musicPlayer = javax.microedition.media.Manager.createPlayer(in, "audio/mp3"); // Ready the data and start playing it. To loop indefinitely, we set loopcount // to -1. _musicPlayer.realize(); _musicPlayer.prefetch(); _musicPlayer.setLoopCount(-1); _musicPlayer.start(); } catch (Exception e) { Dialog.alert("Error playing music"); } } }

 

Developer
Posts: 3,951
Registered: ‎07-15-2008
My Device: Not Specified

Re: Problem while playing MP3 in loop

[ Edited ]

I tried it on 8100 Simulator. JDE 4.2.1.40. Works as expected.

 

 

InputStream fis = getClass().getResourceAsStream("/res/sample.mp3");
String ct = "audio/mpeg";
Player p;
p = Manager.createPlayer(fis, ct);
p.realize();
p.prefetch();
p.setLoopCount(-1);
p.start();

 

 

 PSSmiley Frustratedorry I was in Edit mode when Narendra posted.

Message Edited by BBDeveloper on 09-04-2009 12:09 PM

Use Search. "Accept Solution" If the problem is resolved.
Developer
Posts: 218
Registered: ‎02-20-2009
My Device: Not Specified

Re: Problem while playing MP3 in loop

Hi,

 

Smiley Happy

 

Its doesnt matter.

 

 

I am waiting for reply :

 

problem is solved or not .... ???

New Developer
Posts: 8
Registered: ‎04-03-2009
My Device: Not Specified

Re: Problem while playing MP3 in loop

Not Solved!!! I changed "mpeg to mp3" but still sound is being played only one time after that I get error....
Developer
Posts: 3,951
Registered: ‎07-15-2008
My Device: Not Specified

Re: Problem while playing MP3 in loop

what is the JDE version you are using. JDE 4.2.1.40 and 8100 didn't have any problem playing the mp3 in loop.

Use Search. "Accept Solution" If the problem is resolved.
New Developer
Posts: 8
Registered: ‎04-03-2009
My Device: Not Specified

Re: Problem while playing MP3 in loop

I am using JDE version 4.2.0.98, does it matter.??
Developer
Posts: 3,951
Registered: ‎07-15-2008
My Device: Not Specified

Re: Problem while playing MP3 in loop

If you have any recent versions installed, give a try.

Use Search. "Accept Solution" If the problem is resolved.