0

Mediaplayer onPlaylistEnd event issue

Hi,

My Mediaplayer code is working different way on the simulator and my real Tv (Samsung B651 European 2009 model)

When I call the mediaplayer and the playlist has two (or more) film movies the onPlayListEnd is firing after the FIRST movie and not after the LAST movie.

Here I fill the Playlist

CODE
	
updateView: function() {
this.config.miPlaylist = new KONtx.media.Playlist();
this.config.miPlaylist.addEntryByURL($videos_mediaplayer[i]);
KONtx.mediaplayer.playlist.set(this.config.miPlaylist);
KONtx.mediaplayer.playlist.start();

by
17 Replies
  • (continued from the previous post, sorry but I can't edit or remove it)

    THIS is the code:

    CODE
    var ViewMediaPlayer = new KONtx.Class({
    ClassName: 'ViewMediaPlayer',
    Extends: KONtx.system.FullscreenView,

    config: {
    myPlaylist: null
    },

    // fisrt time
    createView: function() {

    KONtx.mediaplayer.initialize();
    var overlay = new KONtx.control.MediaTransportOverlay({}).appendTo(this);
    _myPlayerDispatcher.subscribeTo(KONtx.mediaplayer, ['onStateChange', 'onVideoLoadError','onPlaylistEnd']);

    function _myPlayerDispatcher(event) {
    if(event.type == "onStateChange") {
    if(event.payload.newState == KONtx.mediaplayer.constants.states.ERROR) {
    new KONtx.dialogs.Alert({
    title: "Error",
    message: "Error playing video",
    buttons: [
    { label: 'Return', callback: function() {
    KONtx.application.previousView();
    } }
    ]
    }).show();

    }
    else if(event.payload.newState == KONtx.mediaplayer.constants.states.STOP) {
    new KONtx.dialogs.Alert({
    title: "Stop",
    message: "Stop key pressed",
    buttons: [
    { label: 'Return', callback: function() {
    KONtx.application.previousView();;
    } }
    ]
    }).show();
    }
    }
    if(event.type == "onVideoLoadError") {
    new KONtx.dialogs.Alert({
    title: "Error",
    message: "Error loading video", ]
    buttons: [
    { label: 'Return', callback: function() {
    KONtx.application.previousView();;
    } }
    ]
    }).show();
    }
    if(event.type == "onPlaylistEnd") {
    new KONtx.dialogs.Alert({
    title: "End",
    message: "End of the playlist",
    buttons: [
    { label: 'Return', callback: function() {
    KONtx.application.previousView();;
    } }
    ]
    }).show();
    }
    }

    },

    //put focus
    focusView: function() {
    this.controls.overlay.focus();
    },

    // on each load window
    updateView: function() {

    this.config.miPlaylist.addEntryByURL("http://cosmos.bcst.yahoo.com/getPlaylist.php?node_id=11886648&bitrate=300&tech=wmp");
    this.config.miPlaylist.addEntryByURL("http://cosmos.bcst.yahoo.com/getPlaylist.php?node_id=12101875&bitrate=300&tech=wmp");

    KONtx.mediaplayer.playlist.set(this.config.myPlaylist);
    KONtx.mediaplayer.playlist.start();
    },
    });


    Running this code into simulator works well, but into real TV after first movie I can see the 'End of the playlist' message on screen, if I press the 'Return' button I can´t see the second movie, if I dont press the 'Return' button the second movie start after a few seconds and below the Alert Dialog.

    Any idea about how to handle the end of the playlist ?

    Raul de Frutos
    --------------------
    0
  • QUOTE (Raul @ Sep 19 2010, 11:31 PM) <{POST_SNAPBACK}>
    Running this code into simulator works well, but into real TV after first movie I can see the 'End of the playlist' message on screen, if I press the 'Return' button I can´t see the second movie, if I dont press the 'Return' button the second movie start after a few seconds and below the Alert Dialog.

    Any idea about how to handle the end of the playlist ?

    Raul de Frutos
    --------------------

    Hi Raul,
    I was confused by your comments. I wasn't sure if the second code contained the complete code or if the code from the first post was to be mixed in. Anyway, I rewrote it and tested on Samsung 2010. It works as expected. Note how I restructured the code. Also, always make sure to unsubscribe any listeners that were subscribing to any events when the view exits or you could run into unexpected behavior.

    CODE
    var Home = new KONtx.Class({
    ClassName: "Home",
    Extends: KONtx.system.FullscreenView,

    // fisrt time
    createView: function() {
    KONtx.mediaplayer.initialize();
    var overlay = new KONtx.control.MediaTransportOverlay({}).appendTo(this);
    },

    _myPlayerDispatcher: function(event) {
    if(event.type == "onStateChange") {
    if(event.payload.newState == KONtx.mediaplayer.constants.states.ERROR) {
    new KONtx.dialogs.Alert({
    title: "Error",
    message: "Error playing video",
    buttons: [
    { label: 'Return', callback: function() {
    KONtx.application.previousView();
    } }
    ]
    }).show();

    }
    else if(event.payload.newState == KONtx.mediaplayer.constants.states.STOP) {
    new KONtx.dialogs.Alert({
    title: "Stop",
    message: "Stop key pressed",
    buttons: [
    { label: 'Return', callback: function() {
    KONtx.application.previousView();;
    } }
    ]
    }).show();
    }
    }
    if(event.type == "onVideoLoadError") {
    new KONtx.dialogs.Alert({
    title: "Error",
    message: "Error loading video",
    buttons: [
    { label: 'Return', callback: function() {
    KONtx.application.previousView();;
    } }
    ]
    }).show();
    }
    if(event.type == "onPlaylistEnd") {
    new KONtx.dialogs.Alert({
    title: "End",
    message: "End of the playlist",
    buttons: [
    { label: 'Return', callback: function() {
    KONtx.application.previousView();;
    } }
    ]
    }).show();
    }

    },

    //put focus
    focusView: function() {
    this.controls.overlay.focus();
    },

    hideView: function() {
    this._myPlayerDispatcher.unsubscribeFrom(KONtx.mediaplayer, ['onStateChange', 'onVideoLoadError','onPlaylistEnd']);
    },

    // on each load window
    updateView: function() {

    this._myPlayerDispatcher.subscribeTo(KONtx.mediaplayer, ['onStateChange', 'onVideoLoadError','onPlaylistEnd']);

    var myPlaylist = new KONtx.media.Playlist();
    myPlaylist.addEntryByURL("http://cosmos.bcst.yahoo.com/getPlaylist.php?node_id=11886648&bitrate=300&tech=wmp");
    myPlaylist.addEntryByURL("http://cosmos.bcst.yahoo.com/getPlaylist.php?node_id=12101875&bitrate=300&tech=wmp");

    KONtx.mediaplayer.playlist.set(myPlaylist);
    KONtx.mediaplayer.playlist.start();
    }
    });


    - Ben
    0
  • QUOTE (Benjamin Toll @ Sep 24 2010, 12:24 PM) <{POST_SNAPBACK}>
    Hi Raul,
    I was confused by your comments. I wasn't sure if the second code contained the complete code or if the code from the first post was to be mixed in. Anyway, I rewrote it and tested on Samsung 2010. It works as expected. Note how I restructured the code. Also, always make sure to unsubscribe any listeners that were subscribing to any events when the view exits or you could run into unexpected behavior.


    First post is incorrect, but I can`t delete it.

    I will try your solution as soon as possible.

    Thank you very much.

    Raul
    -------
    0
  • Benjamin:

    Your solution is not working in my TV (Samsung B651 european model year 2009)

    When I run the code this happens:

    1) The first video start playing
    2) the first video end
    3) A pop-up alert on the screen says 'End of the playlist' and prompt me to press a RETURN button
    4) If I do nothing I can see the SECOND video starting under the alert dialog.
    5) At the moment I press the RETURN button the player closes and the dock view its showed.

    Seems like my tv is not firing this event at the right moment.

    Any idea ?

    Regards.

    Raul de Frutos
    ---------------------
    0
  • Raul,
    Which version of the framework and engine are on your tv?

    - Ben
    0
  • QUOTE (Benjamin Toll @ Oct 1 2010, 11:13 AM) <{POST_SNAPBACK}>
    Raul,
    Which version of the framework and engine are on your tv?

    - Ben


    This is the data from the Widget Gallery of my Samsung B651 european model year 2009:

    Yahoo Widget engine: 5.0.0
    Widget Aplication framework: 1.3.12.C
    Launcher bootstrap: 1.2.10
    Profiles: 1.2.21
    Widget container: 1.2.66.C
    Out of Box Tutorial: 1.2.4.C

    Regards

    Raul
    -------
    0
  • Raul,
    See this sticky about 2009 Samsungs. There's a patch file you can include in your widget that may help with your issue. Please try this out.

    - Ben
    0
  • QUOTE (Benjamin Toll @ Oct 5 2010, 02:12 PM) <{POST_SNAPBACK}>
    Raul,
    See this sticky about 2009 Samsungs. There's a patch file you can include in your widget that may help with your issue. Please try this out.

    - Ben


    Benjamin:

    I know that post very well. I wrote on it. I always include the patch file 'patch-pre_fw1.3.27-mediaplayer.js' on all of my Mediaplayer code.

    Now I am sure THERE IS A PROBLEM with the on PlayListEnd event on Samsung European 2009 tv.

    I tried the MediaPlayer sample from the SDK, I get the code from my simularor $HOME/TVWidgets/Konfabulator-Latest-540/TV/Widgets/com.yahoo.widgets.videosample.widget

    I did this little changes:

    - Added this line to init.js file: include("Javascript/patch-pre_fw1.3.27-mediaplayer.js");
    - Changed the widget id from com.yahoo.widgets.tv.videosample to com.raul.widgets.tv.videosample
    - Changed the mp4 files to other shorter for a more easy test

    The widget works fine into simulator, but deployed on my tv the two films button ITS NOT WORKING, IT ONLY SHOWS THE FIRST MOVIE

    I am sure there is a problem. HELP PLEASE TO 'OLD' EUROPEAN SAMSUNG OWNERS.

    Raul de Frutos
    ------------------
    0
  • Raul,
    Sorry for the delay. I'm currently looking into this. A co-worker is having similar issues with that event, and we're troubleshooting. I'll report back here when I have something.

    - Ben
    0
  • QUOTE (Benjamin Toll @ Oct 12 2010, 11:03 AM) <{POST_SNAPBACK}>
    Raul,
    Sorry for the delay. I'm currently looking into this. A co-worker is having similar issues with that event, and we're troubleshooting. I'll report back here when I have something.

    - Ben


    Thanks a lot, I'm waiting your news.

    Regards

    Raul de Frutos
    -------------------
    0
  • QUOTE (Raul @ Oct 13 2010, 12:40 AM) <{POST_SNAPBACK}>
    Thanks a lot, I'm waiting your news.

    Regards

    Raul de Frutos
    -------------------


    Still waiting.... no news?
    0
  • Unfortunatly I don't have an answer to this question however, I have sent this off to our development team and someone should respond shortly. Thanks!

    -Austin
    0
  • QUOTE (Raul @ Oct 18 2010, 10:29 PM) <{POST_SNAPBACK}>
    Still waiting.... no news?

    Raul,
    I'm still looking into it. I have several media player issues that I'm researching right now, and yours is one of them.

    - Ben
    0
  • Raul,

    I've looked into this and have found the cause.

    Whenever the state is changed (play, pause, eof, etc.), an event is broadcast from the engine that bubbles up and is handled in the framework, specifically in the mediaplayer api. Whenever an eof event occurs, the media player checks to see if the index of the next video is less than the length of the playlist. If it is, it wraps the call to play the next video in a callback to a timer that is called after a half second (maybe more depending upon what the processor is servicing). If not, it doesn't wrap the call to the next video, it just calls it immediately. So, if another eof event occurs before the callback is executed (upwards of a half second), another timer is then also created.

    This explains what you're seeing, and what I've been able to easily reproduce. When the first callback is executed, it begins the process of loading and playing a new video. When the second timer callback is executed, it realizes that the playlist is at an end and the dialog box is presented on the tv.

    I have a patch that fixes this behavior, but I've yet to test it on other OEMs and on more recent engines. Since the issues seems to be isolated to 5.0 engines, it could mean that it's a problem with Samsung's 2009 media player or an engine bug that has since been fixed. Either way, aggressive regression testing is needed before I can say anything conclusively about how the fix for this particular issue will perform across all OEMs and engines.

    - Ben
    0
  • I have issue with two EOF state too, so i just add checking into patch-pre_fw1.3.27-mediaplayer.js

    CODE
    	internals.handleStateChange = function(newstate) {
    var previousState = internals.tvapi.state;
    internals.tvapi.state = newstate;
    internals.log("State Change from " + previousState + " to " + newstate);

    // FIX by vova.leskiv 28/10/2010
    // this happen sometimes while playing playlist with several items, and this cause skipping next item from playlist
    // SAMSUNG LE32B650
    if(previousState == internals.constants.states.EOF && newstate == internals.constants.states.EOF) {
    return;
    }

    if (internals.fire("onStateChange", { newState: newstate, previousState: previousState })) {
    if(newstate == internals.constants.states.BUFFERING) {
    internals.media.buffering_count++;
    if(internals.fire("onPlaybackBuffering")) {
    KONtx.utility.WaitIndicator.on();
    }
    } else {
    KONtx.utility.WaitIndicator.off();
    }
    if(newstate == internals.constants.states.EOF) {
    if(internals.media.playlist_index + 1 < internals.media.playlist.entries.length) {
    // if we will be for sure playing more clips, add a slight delay between clips to let low level player recover
    internals.delayStartNextClip();
    } else {
    // otherwise, just let the normal logic handle it without a delay
    internals.next_playlist_entry();
    }
    }
    if(newstate == internals.constants.states.PAUSE || newstate == internals.constants.states.STOP) {
    if(internals.fire("onSetScreensaverMode", { mode: "on" })) {
    KONtx.HostEventManager.send("setScreensaver", true);
    }
    } else {
    if(internals.fire("onSetScreensaverMode", { mode: "off" })) {
    KONtx.HostEventManager.send("setScreensaver", false);
    }
    }
    }
    };


    And it work. Is this fix will be enough?
    0
  • QUOTE (vova.leskiv @ Oct 29 2010, 12:14 AM) <{POST_SNAPBACK}>
    I have issue with two EOF state too, so i just add checking into patch-pre_fw1.3.27-mediaplayer.js

    CODE
    	internals.handleStateChange = function(newstate) {
    var previousState = internals.tvapi.state;
    internals.tvapi.state = newstate;
    internals.log("State Change from " + previousState + " to " + newstate);

    // FIX by vova.leskiv 28/10/2010
    // this happen sometimes while playing playlist with several items, and this cause skipping next item from playlist
    // SAMSUNG LE32B650
    if(previousState == internals.constants.states.EOF && newstate == internals.constants.states.EOF) {
    return;
    }

    if (internals.fire("onStateChange", { newState: newstate, previousState: previousState })) {
    if(newstate == internals.constants.states.BUFFERING) {
    internals.media.buffering_count++;
    if(internals.fire("onPlaybackBuffering")) {
    KONtx.utility.WaitIndicator.on();
    }
    } else {
    KONtx.utility.WaitIndicator.off();
    }
    if(newstate == internals.constants.states.EOF) {
    if(internals.media.playlist_index + 1 < internals.media.playlist.entries.length) {
    // if we will be for sure playing more clips, add a slight delay between clips to let low level player recover
    internals.delayStartNextClip();
    } else {
    // otherwise, just let the normal logic handle it without a delay
    internals.next_playlist_entry();
    }
    }
    if(newstate == internals.constants.states.PAUSE || newstate == internals.constants.states.STOP) {
    if(internals.fire("onSetScreensaverMode", { mode: "on" })) {
    KONtx.HostEventManager.send("setScreensaver", true);
    }
    } else {
    if(internals.fire("onSetScreensaverMode", { mode: "off" })) {
    KONtx.HostEventManager.send("setScreensaver", false);
    }
    }
    }
    };


    And it work. Is this fix will be enough?

    Hi,
    That's the right approach. I definitely found that when the previous state and the new state are both eof that that's when the bug happens. I'm looking into the timers that are built into the api and wanting to re-engineer the api. This is what's going to take some time.

    What engine(s) did you test on?

    - Ben
    0
  • Still waiting.... no news?
    0

Recent Posts

in General - Yahoo! TV Widgets