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
Developer
Posts: 18
Registered: ‎03-11-2009
My Device: 9530 Simulator 2.11.0.86

How do you loop sounds without skipping?

I have a WAV file that should loop just fine but when I try to set looping to infinite it always has a silence gap.  I've tried lots of different formats including 8 bit, 16 bit, 11 khz, 22 khz, 44 khz, and different prefetch strategies with no success.  This is using the latest eclipse plugin with Storm simulator.  I have not yet tried on the actual device but the simulator results are making me nervous.  Is there a way to increase the amount of read ahead buffers?  Can I load the whole WAV file into memory and not have a silence gap?  Is the Player the only way to play audio or can I get lower level access?

 

Here is code that I wrote which helped reduce the silence gap by prefetching the end at startup but sadly does not completely remove:

 

                //Create a new Player from the InputStream//                   

                  _player = Manager.createPlayer(inputStream,"audio/wav");

                  _player.setLoopCount(-1);

 

                //Realize Player

                _player.realize();                             


                    // prefetch the beginning of wav file
                    _player.prefetch();
                   
                    // go to the end of wav file
                    long duration = _player.getDuration();
                    _player.setMediaTime(duration-1);
                   
                    // prefetch the end so we don't skip on first play
                    _player.prefetch();
                      
                    //Add listener to catch Player events
                    _player.addPlayerListener(this);
                       
                    //Start the Player
                    _player.start();

 

 

This is my first post and my first day at creating an application so please be gentle Smiley Happy

 

Thanks in advanced!

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

Re: How do you loop sounds without skipping?

Just a thought, not tried. Instead of setting loop count, implement the playerListener and wat for the event End of media and call play.start().

Use Search. "Accept Solution" If the problem is resolved.
Developer
Posts: 18
Registered: ‎03-11-2009
My Device: 9530 Simulator 2.11.0.86

Re: How do you loop sounds without skipping?

Thanks for the suggestion.  I gave that a shot and it had the exact same result.  I also tried handling the BUFFERING_STOPPED event to prefetch and that didn't work either.  Anything else I can try?

 

 

Developer
Posts: 163
Registered: ‎07-16-2008
My Device: Not Specified
My Carrier: Sprint

Re: How do you loop sounds without skipping?

My suggestion sucks, but I will offer it anyways.

Have you considered having 2 player objects, and immediately calling player2.start() when the first player sends an end of media event (with the calls to realize, prefetch, etc. having already been made)?

Andrew Cowart | Metova
www.metova.com
Developer
Posts: 18
Registered: ‎03-11-2009
My Device: 9530 Simulator 2.11.0.86

Re: How do you loop sounds without skipping?

I gave that a shot alternating between two players and got simular results.  I think once you get to END_OF_MEDIA there is just going to be a gap in sound no matter what.  Unless I could start the player a couple milliseconds prior to this condition but not sure how that could be done unless I launched a thread to monitor playback position.

 

Are there any options for caching the InputStream?

 

Developer
Posts: 209
Registered: ‎11-08-2008
My Device: Not Specified

Re: How do you loop sounds without skipping?

Hi Mooret,

I am facing similar problem. I have tried all the possible ways to skip gap.

And i wonder how to do it ?

If you got the possible solution,then please do help me...

 

Thanks and Regards
New Developer
Posts: 1
Registered: ‎12-24-2008
My Device: Not Specified

Re: How do you loop sounds without skipping?

Hello All,

  I was able to do this by extending one of the Stream classes and making it circular!

 

I tried everything from 2 players, threads, timers etc.  but I finally had success with extending the stream class with my own functions.

 

Basically... the player thinks my wav file is a couple hours long Smiley Happy

 

-Carmine

 

Highlighted
Developer
Posts: 209
Registered: ‎11-08-2008
My Device: Not Specified

Re: How do you loop sounds without skipping?

 

Hi carmine thanks for the reply...

I even tried millions of things but no success.

You must have done the trick in read() of InputStream.Can you please more describe how you did that?

And How You made it circular ?

 

 

Thanks and Regards