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
New Developer
sombhardwaj
Posts: 2
Registered: ‎04-20-2009
My Device: Not Specified

Pause/Resume player through code

Hi all,

 

I am developing an audio player but unable to find any solution for pausing and resuming the player. How can i resume/pause a player. please provide any solution.

 

Thanks

Please use plain text.
Developer
kzettel
Posts: 120
Registered: ‎07-16-2008
My Device: 9000

Re: Pause/Resume player through code

You can use the javax.microedition.media.Player object to play audio.  It has a start() and stop() method.  There is a simple playback example in the javadocs and some more detail in the Knowledge Base here and here

 

Alternatively, If you are trying to use the BlackBerry media player application to play audio you are limited to launching it and then it is out of your control.

Kurt Zettel | Chief Architect | Metova
www.metova.com
Please use plain text.
New Developer
only_vimal
Posts: 17
Registered: ‎02-06-2009
My Device: Not Specified

Re: Pause/Resume player through code

Hi Som,
 
try this... 
 
 // Create Media Player and play audio media file
 public class playaudioThread  implements PlayerListener
{
/**
* Creating Media player and start playing Audio media. 
*/
public playaudioThread()
{
         Player player; public InputStream str;
str = getClass().getResourceAsStream("Audio.mp3");
try {
player = javax.microedition.media.Manager.createPlayer(str, "audio/mpeg");
player.addPlayerListener(this); player.realize(); player.prefetch(); player.start();
}
catch (MediaException e) { //Do Nothing }
}
}
 
// ---------------------------------------------------------------------------------------------------
 
//When you go for pause event, get current media time and store it in variable. 
 
long getCurrentPosition;
 
getCurrentPosition = player.getMediaTime(); 
 
try
{
player.stop();              
}              
catch (MediaException e)
{
//Do Nothing
}
//---------------------------------------------------------------------------------------------------------------------------- 
 
 
//When you go for resume event
 
try
                {
              
               // Create Media Player and play audio media file
               pt1=new playaudioThread();        
                     
               player.setMediaTime(getCurrentPosition);
                      
                }               
                catch (MediaException e)
                {
                    System.out.println("MediaException "+e.toString());
                 } 
//-----------------------------------
 
 
Regards,
Vimal 
Please use plain text.
Super Contributor
yogesh1984
Posts: 308
Registered: ‎05-31-2011
My Device: Blackberry-SDK-9800
My Carrier: SimPakage 6.0.0.337_9800 asia.exe

Re: Pause/Resume player through code

hi,

  i am building an application on the base of info u have given but i am getting error...  can u tell me where i went wrong... 

             public boolean Pause()       

{                            

  if (_player == null || _player.getState() != Player.STARTED)          

      {                    // Not playing, nothing to do               

    return false;              

       }

                if (_player != null)            

         {     try                    

             {                   

 

        _player.stop();                       

      _player.getMediaTime();                   

}                    

catch (Exception e)                     {                    e.printStackTrace();                    }                }
                return true;         

  }          

 

public void Resume()          

  {           

try                

{                                            _

player = Manager.createPlayer("capture://audio?encoding=pcm");                   

// recordPlayer = Manager.createPlayer("capture://audio?encoding=amr");             

  _player.realize();                                            _recordControl.setRecordLocation("file:///store/home/user/test_audio2.pcm");                _player.setMediaTime(getCurrentPosition);                //_recordControl.setRecordLocation("file:/SDCard/voicenotes/Myvoice.pcm");                   //_recordControl.setRecordLocation("file://192.168.0.200/software/yogesh/test_audio2.pcm");                _recordControl.startRecord();             

  _player.start();                                    

 //screen.add("Recording...");                     
                }catch (final Exception e)                 {                UiApplication.getUiApplication().invokeAndWait(new Runnable()                 { public void run() { Dialog.inform(e.toString()); } });                }            }

Please use plain text.