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.
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).
Then, in Javascript/core/EventHandlers.js:
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.