×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Regular Contributor
    Join Date
    Apr 2007
    Posts
    233

    play mp3 in a position

    Hi all,

    I would like to play a mp3 file, starting the playing from a time. I need it to simulate a pause in a mp3 player. I have found in other posts that can be used setMediaTime, but the following error appears:

    javax.microedition.media.MediaException: Could not set time: -5

    I am using a Nokia N91, so it is a good device in which there shouldn't be problems with that.

    If anyone knows other way to simulate a pause, I would be happy

    Regards,

  2. #2
    Regular Contributor
    Join Date
    Aug 2006
    Posts
    307

    Re: play mp3 in a position

    You can simply pause a thread in which your player is living. After N seconds of sleep thread will start playing your mp3 file:

    Code:
    player.prefetch(); // make player ready to play data
    
    thread.sleep(5000L); // try to sleep for 5 seconds
    
    player.start(); // play media
    Not all MMAPI implementations are allowing to set the media time, but using a sleeping thread you'll be able to emulate it virtually on all mobile platforms.

  3. #3
    Regular Contributor
    Join Date
    Apr 2007
    Posts
    233

    Re: play mp3 in a position

    But, once the player has been started, I can't pause the thread..., my code is the following...

    public void run()
    {
    MSTrack currTrack = null;
    boolean errorPlaying = true;
    synchronized (localLockObj)
    {
    while (errorPlaying)
    {
    try
    {
    if(!bIsStreaming)
    {
    Logger.debug("MSPlayerThread.run: Entry");

    System.gc();

    // TODO: will need updated when we play a clip
    currTrack = (MSTrack) tracksToPlay.elementAt(currentTrackIdx);
    Logger.debug("MSPlayerThread.run: [" + currTrack.localURI + "]");

    // create player for current track

    Logger.debug("MSPlayerThread.run: Creating player");

    fileConn = (FileConnection) Connector.open(currTrack.localURI);
    player = Manager.createPlayer(fileConn.getURL());
    player.addPlayerListener(this);

    player.realize();

    //set volume
    VolumeControl vc = (VolumeControl) player.getControl("VolumeControl");
    if(vc != null)
    vc.setLevel(VolumeLevel);

    player.setLoopCount(1);

    /*
    if(mediaTime > 0)
    player.setMediaTime(mediaTime);
    */

    player.start();

    // we're playing if we get here, so set our local state vars
    playing = true;
    isPaused = false;
    errorPlaying = false;

    isInStreaming = false;

    localPlayStartTime = new Date().getTime();
    localTrack = (MSTrack) tracksToPlay.elementAt(currentTrackIdx);

    // send playing event
    Logger.debug("MSPlayerThread.playerUpdate: sending 'playing' event");
    MyStrandsMIDlet.midlet.communicator.userTrackPlaying(localTrack);


    MyStrandsMIDlet.midlet.get_currentTrackTicker().setString(currTrack.name + " (" + currTrack.artistName + ")");
    }
    else
    {
    try
    {
    //OS streaming link
    //Player player = Manager.createPlayer(
    // "rtsp://a1176.v128388.c12838.g.vr.akamaistream.net/ondemand/7/1176/12838/v40614/muze.download.akamai.com/2890/us/usrm/320/277320_1_13.rm"
    // );

    System.gc();

    Logger.debug("Va a hacer streaming de : " + strRMClipURI);
    player = Manager.createPlayer(strRMClipURI);
    player.addPlayerListener(this);
    //player = Manager.createPlayer("rtsp://a1176.v128388.c12838.g.vr.akamaistream.net/ondemand/7/1176/12838/v40614/muze.download.akamai.com/2890/us/usrm/320/277320_1_13.rm");
    player.prefetch();
    player.start();
    player.realize();

    // get volume control for player and set volume to max
    VolumeControl vc = (VolumeControl)player.getControl("VolumeControl");
    if ( vc != null )
    vc.setLevel(VolumeLevel);



    playing = true;
    isPaused = false;
    errorPlaying = false;
    }
    catch (Exception e)
    {
    isInStreaming = false;
    MyStrandsMIDlet.showError(LocalizationSupport.getMessage("Streaming_failed!") );
    Logger.debug(e.toString());
    }
    }
    }
    catch (MediaException e) {
    Logger.error("MSPlayerThread.run: ME [" + currTrack.localURI + "]",
    e);
    destroy();
    }
    catch (SecurityException e) {
    Logger.error("MSPlayerThread.run: SE [" + currTrack.localURI + "]",
    e);
    destroy();
    }
    catch (IOException e) {
    Logger.error(
    "MSPlayerThread.run: IOE [" + currTrack.localURI + "]", e);
    destroy();
    }
    catch (Exception e) {
    Logger.error("MSPlayerThread.run: E [" + currTrack.localURI + "]",
    e);
    destroy();
    }
    catch (Throwable t) {
    Logger.error("MSPlayerThread.run: Throwable", t);
    destroy();
    }
    }

  4. #4
    Regular Contributor
    Join Date
    Apr 2007
    Posts
    233

    Re: play mp3 in a position

    For more info, in other thread have commented to me that if you sleep the thread, the Player will not pause, because internally MMA has its own threads..., which is logical on the other hand.

Similar Threads

  1. Recording in Amr Format
    By losym in forum Symbian Media (Closed)
    Replies: 12
    Last Post: 2009-03-26, 06:41
  2. Replies: 1
    Last Post: 2008-06-17, 10:40
  3. what i need to install to play mp3 files
    By ravibabu in forum Mobile Java Media (Graphics & Sounds)
    Replies: 2
    Last Post: 2006-10-18, 06:04
  4. Cannot play MP3 with chinese filename in MMAPI
    By domicch in forum Mobile Java Media (Graphics & Sounds)
    Replies: 6
    Last Post: 2006-05-17, 07:36
  5. how to play mp3 file?
    By zwgoal in forum Symbian Media (Closed)
    Replies: 3
    Last Post: 2005-11-14, 08:21

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×