雅虎!联网电视播放事件

发布于 2024-09-28 17:46:58 字数 185 浏览 2 评论 0原文

我正在尝试订阅 onTimeIndexChanged mediaplayer 事件。只要我订阅的视图保持专注,它就可以正常工作。当我按下后退按钮或小部件按钮时,我的视图变得模糊并且不再接收事件。

是否可以通过切换视图来保持这个订阅?是否有小部件范围内的订阅?

我想知道是否可以计算客户端的播放时间。

I'm trying to subscribe to onTimeIndexChanged mediaplayer event. It works fine, as long as view that I'm subscribing in stays focused. When I press back button, or widgets button, my view gets blurred and it no longer receives events.

Is it possible for this subscription to persist through switching views? Are there widget-wide subscriptions?

I am trying to find out if it is possible to count time of playback client-side.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

耶耶耶 2024-10-05 17:46:58

雅虎上也对此做出了回答!联网电视论坛:http://developer.yahoo.net/forum/?showtopic=7383< /a>
是的,您走在正确的道路上。媒体播放器是一个单例,因此不绑定到任何特定视图。您可以定义一个监听器,在小部件的全局执行上下文中订阅它。这样,您仍然可以接收和处理视图被GC时发生的事件,并且您仍然可以接收这些事件。

我们将这些全局订阅放在 init.js 中,以便它们位于中心位置(最佳实践)。

 
EventHandlers.handlerPlayerEvent.subscribeTo(KONtx.mediaplayer, ['onStateChange', 'onTimeIndexChanged'], EventHandlers);

然后,在 Javascript/core/EventHandlers.js 中:


var EventHandlers = {

    //snipped for brevity;

    handlerPlayerEvent: function(event) {
            switch(event.type) {
                    case 'onStateChange':
                            switch(event.payload.newState) {
                                    case KONtx.mediaplayer.constants.states.PLAY:
                                            if(!this._snippetAdded) {
                                                    KONtx.application.addViewConfig({ id: 'snippet-nowplaying',

viewClass: VideoNowPlayingSnippetView });
this._snippetAdded = true;
}
休息;
案例 KONtx.mediaplayer.constants.states.UNKNOWN:
案例 KONtx.mediaplayer.constants.states.ERROR:
案例 KONtx.mediaplayer.constants.states.STOP:
案例 KONtx.mediaplayer.constants.states.EOF:
KONtx.application.removeView('snippet-nowplaying');
this._snippetAdded = false;
休息;
}
休息;

                    case 'onTimeIndexChanged':
                            //do something interesting;
                            break;
            }
    }

};

我还应该补充一点,如果您在视图中订阅事件,那么在视图的 hideView 侦听器中取消订阅它们非常重要。这可以防止内存泄漏和其他不良行为。

This was also answered on the Yahoo! Connected TV forums at: http://developer.yahoo.net/forum/?showtopic=7383
Yes, you're on the right track. The media player is a singleton and as such isn't bound to any particular view. You can define a listener that subscribes to it in the widget's global execution context. This way you can still receive and handle events that happen when a view is gc'd, and you can still receive those events.

We put these global subscriptions in init.js so they're centrally-located (best practice).

 
EventHandlers.handlerPlayerEvent.subscribeTo(KONtx.mediaplayer, ['onStateChange', 'onTimeIndexChanged'], EventHandlers);

Then, in Javascript/core/EventHandlers.js:


var EventHandlers = {

    //snipped for brevity;

    handlerPlayerEvent: function(event) {
            switch(event.type) {
                    case 'onStateChange':
                            switch(event.payload.newState) {
                                    case KONtx.mediaplayer.constants.states.PLAY:
                                            if(!this._snippetAdded) {
                                                    KONtx.application.addViewConfig({ id: 'snippet-nowplaying',

viewClass: VideoNowPlayingSnippetView });
this._snippetAdded = true;
}
break;
case KONtx.mediaplayer.constants.states.UNKNOWN:
case KONtx.mediaplayer.constants.states.ERROR:
case KONtx.mediaplayer.constants.states.STOP:
case KONtx.mediaplayer.constants.states.EOF:
KONtx.application.removeView('snippet-nowplaying');
this._snippetAdded = false;
break;
}
break;

                    case 'onTimeIndexChanged':
                            //do something interesting;
                            break;
            }
    }

};

I should also add that if you're subscribing to events in a view that it's very important to also unsubscribe from them in the view's hideView listener. This can prevent memory leaks and other undesirable behavior.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文