×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Registered User
    Join Date
    Dec 2010
    Posts
    39

    issue with END OF MEDIA

    Hi,
    I've created a player (Manager.createPlayer ()) and have a playerListener attached to this.

    playerUpdate method also is declared properly.

    The issue is - END_OF_MEDIA is fired correctly for track 1 at the end but for track2 - END_OF_MEDIA is not at all occurring.


    The app plays tracks one by one. Since End_Of_Media didnt occur, the app stops at end of 2nd track always.

    Any clue ??

  2. #2
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Re: issue with END OF MEDIA

    Quote Originally Posted by nathviswa View Post

    The issue is - END_OF_MEDIA is fired correctly for track 1 at the end but for track2 - END_OF_MEDIA is not at all occurring.


    The app plays tracks one by one. Since End_Of_Media didnt occur, the app stops at end of 2nd track always.

    Any clue ??
    Code segment will be of interest to review, where you are detecting the end of media..

    Another part of interest would be that how are you trying to play the next song?
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  3. #3
    Registered User
    Join Date
    Dec 2010
    Posts
    39

    Re: issue with END OF MEDIA

    Here's how the player is created :

    player = Manager.createPlayer ("file://"+trackName);
    player.addPlayerListener (this);
    player.realize ();
    player.prefetch ();

    player.start () is called later ..


    public void playerUpdate(Player plyr, String evt, Object evtData) {


    if (evt == STARTED) {
    System.out.println ("playing");
    playerPlaying = true;
    this.playDur = player.getDuration ();
    } else if (evt == STOPPED) {
    } else if (evt == CLOSED) {

    player = null;
    audioPlayer.trackNext (); ------------> will start the next track
    } else if (evt == END_OF_MEDIA) {

    playerPlaying = false;
    audioPlayer.p ("endofmedia");
    audioPlayer.tAppend ("EOM");
    stopPlayer ();
    }

    }

    I jus found - there's no display from this method after Play start - for track 2 - meaning "playerListener" is not at all added for 2nd track onwards once 1st track ended.

  4. #4
    Registered User
    Join Date
    Dec 2010
    Posts
    39

    Re: issue with END OF MEDIA

    I found similar discussions here: http://supportforums.blackberry.com/...ges/td-p/96526

    My problem is the same ....... except that the link provided discuss on MP4 while mine is MP3 / AMR.
    The other difference - playerListener works fine for the first track and ends well in my case. When the 2nd track starts, while it plays well & stops, but playerListener not getting the events (STARTED, ENDOFMEDIA etc.). Meaning, I cannot start the 3rd track automatically.

    As stated in the URL, i can put a TIMER and use a work-around, but Im interested to know why playerListener is not receiving the events for 2nd track (onwards). Copy paste of the entire code below:


    Note - few methds viz. problematicFile, TimerCreate etc. are not at all used in the code - jus FYI.

    /**
    * Name: MyPlayer.java
    * Desc: Creates player, realize/prefetch/start & listens for player status change
    *
    */

    import javax.microedition.media.Player;
    import javax.microedition.media.Manager;
    import javax.microedition.media.MediaException;
    import javax.microedition.media.control.VolumeControl;
    import javax.microedition.media.PlayerListener;
    import javax.microedition.io.Connector;
    import javax.microedition.io.file.FileConnection;

    import java.util.Timer;
    import java.util.TimerTask;
    import java.io.InputStream;




    class MyPlayer extends Thread implements PlayerListener,Runnable {

    String trackName;
    Thread playerThread,realizeThread,progressBarUpd;
    Player player;
    AudioPlayer audioPlayer;
    long playDur;
    Screen mainScr;

    boolean playerPlaying = false,playerWaiting = false,filePblm;

    MyPlayer (AudioPlayer a,Screen mainScr) {

    this.audioPlayer = a;
    this.mainScr = mainScr;
    }

    void setTrackName (String trackName) {

    try {
    this.trackName = trackName;

    playerThread = new Thread (this);
    progressBarUpd = new Thread (this);

    audioPlayer.tAppend ("track : "+this.trackName);

    } catch (Throwable e){
    audioPlayer.tAppend ("Err setTrackName "+e.toString ());
    }

    }

    Player createPlayer (String s) {

    setTrackName (s);

    audioPlayer.p ("inside create player");

    this.player = null;
    this.playerPlaying = false;

    try {
    audioPlayer.tAppend ("create player "+trackName);

    if (trackName.endsWith (".wma") || trackName.endsWith (".WMA"))
    player = getWMAplayer ();
    else
    player = Manager.createPlayer ("file://"+trackName);

    player.addPlayerListener (this);
    audioPlayer.tAppend ("playerlistener added");

    player.realize ();

    player.prefetch ();

    audioPlayer.setVolumeControl ((VolumeControl)player.getControl ("VolumeControl"));

    // createTimer ();

    // realizeThread = new Thread (this);
    // realizeThread.setPriority(MAX_PRIORITY);
    // realizeThread.start ();

    playerPlaying = true;

    } catch (MediaException e) {
    player = null;
    } catch (Exception e) {
    player = null;
    } catch (Throwable e) {
    player = null;
    } finally {
    audioPlayer.tAppend ("returning player "+player.toString ());
    return player;
    }

    }

    Player getWMAplayer () {

    Player p = null;

    audioPlayer.tAppend ("create WMA player for "+this.trackName);

    try {
    FileConnection fc = (FileConnection)Connector.open ("file://localhost/"+this.trackName
    ,Connector.READ);
    InputStream is = fc.openInputStream();

    String tType = "audio/x-wma";
    audioPlayer.tAppend ("got IS");
    p = Manager.createPlayer (is,tType);

    is.close ();
    is = null;

    } catch (Exception e){
    p = null;
    audioPlayer.p (e.toString ());
    } catch (Throwable e){
    p = null;
    audioPlayer.p (e.toString ());
    } finally {
    return p;
    }


    }

    void createTimer () {

    Timer realizeTimer = new Timer ();
    filePblm = false;

    realizeTimer.schedule (

    new TimerTask () {
    public void run () {

    audioPlayer.p ("timer fired "+player.getState () );

    if (!playerReady ()) {

    handleProblematicFile ();
    }
    }
    },20000);
    }

    boolean playerReady () {

    if ( (player.getState () == Player.PREFETCHED) ||
    (player.getState () == Player.STARTED) )

    return true;
    else
    return false;

    }


    void handleProblematicFile () {

    mainScr.tickerAppend ("skip");

    filePblm = true;
    try {

    realizeThread.join ();
    } catch (InterruptedException e){
    }

    player.deallocate ();
    player.close ();

    }



    void startPlay () {

    audioPlayer.tAppend ("play to start");
    // mainScr.tickerSet ();
    playerThread.start ();
    progressBarUpd.start ();

    }

    void waitPlayer () {

    audioPlayer.p ("waitPlayer");

    try {

    player.stop ();
    playerThread.yield ();
    // playerPlaying = false;
    playerWaiting = true;
    } catch (MediaException e){
    } catch (Exception e){
    }

    }

    void stopPlayer () {

    audioPlayer.tAppend ("play to stop");
    try {

    player.stop ();//close ();
    playerThread.join ();
    player = null;
    } catch (MediaException e){
    } catch (InterruptedException e){
    }



    }

    long getDuration () {

    audioPlayer.p ("Duration: "+this.playDur);
    audioPlayer.tAppend ("play dur"+this.playDur);
    return this.playDur;
    }


    boolean playerPlays () {

    return this.playerPlaying;
    }

    void pausePlay () {

    if (playerWaiting)
    playStart ();
    else
    waitPlayer ();

    }

    public void run () {

    if (Thread.currentThread () == realizeThread)
    realizePlayer ();
    else if (Thread.currentThread () == playerThread)
    playStart ();
    else if (Thread.currentThread () == progressBarUpd)
    progressBarUpd ();

    }

    void playStart () {

    try {
    player.start ();

    audioPlayer.tAppend ("startd");
    playerWaiting = false;
    } catch (MediaException e) {
    e.printStackTrace ();
    stopPlayer ();
    } catch (Exception e) {
    e.printStackTrace ();
    }

    }

    void realizePlayer () {

    if(player.getState() == player.UNREALIZED) {

    try {

    audioPlayer.tAppend ("b4 real/pref");
    player.realize ();

    player.prefetch ();

    audioPlayer.setVolumeControl ((VolumeControl)player.getControl ("VolumeControl"));

    } catch (MediaException e){
    mainScr.tickerAppend ("ex "+e.toString ()+" "+getPlayerStatus ());
    } catch (Throwable e){
    mainScr.tickerAppend ("oth "+e.toString ()+" "+getPlayerStatus ());
    }
    }

    }

    void progressBarUpd () {

    try {

    while (playerPlays ()) {

    mainScr.updGauge (player.getMediaTime (),playDur);
    Thread.sleep (1);
    }

    } catch (InterruptedException e){
    } catch (IllegalStateException e) {
    } catch (NullPointerException e) {
    }


    }


    int getPlayerStatus () {
    return player.getState ();
    }


    public void playerUpdate(Player plyr, String evt, Object evtData) {

    audioPlayer.tAppend ("PLAYER_UPDATE "+evt);

    if (evt == STARTED) {

    playerPlaying = true;
    this.playDur = player.getDuration ();
    } else if (evt == STOPPED) {
    } else if (evt == CLOSED) {

    player = null;
    audioPlayer.tAppend ("playe closd");
    audioPlayer.trackNext ();
    } else if (evt == END_OF_MEDIA) {

    playerPlaying = false;
    audioPlayer.p ("endofmedia");
    audioPlayer.tAppend ("EOM");
    stopPlayer ();
    audioPlayer.trackNext ();
    }

    }


    }

Similar Threads

  1. problem with end of file detect
    By masoud_bayat in forum Symbian
    Replies: 15
    Last Post: 2008-10-06, 08:45
  2. TFileText Problem with end of line delimiter
    By Blkangel in forum Symbian
    Replies: 8
    Last Post: 2008-08-28, 10:55
  3. Replies: 1
    Last Post: 2008-08-27, 14:42
  4. End-to-end delivery time of text message
    By Nokia_Archive in forum Smart Messaging
    Replies: 1
    Last Post: 2002-05-22, 18:18

Posting Permissions

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