This section outlines the steps to migrate an app from using the older KONtx.videoplayer interface to using the newer KONtx.mediaplayer interface. Migrating to the new interface is not mandatory, but highly encouraged. Your apps using the older interface will continue to work. The new KONtx Framework (1.3 and above) with the new KONtx.mediaplayer interface is backward compatible and includes the older KONtx.videoplayer interface.
The benefits of using the new KONtx.mediaplayer interface are numerous and outlined above, in the section: Media Player (KONtx 1.3 and above).
Which interface you choose should be dependent on the stability and complexity of your video player, and how far you have deviated from the standard video player interface. In Yahoo!’s experience, it has been much faster to migrate to, and to fix bugs against, the new KONtx.mediaplayer interface. If you are already far down the path with the older interface, go ahead and finish up the app and submit it to Yahoo! for QA review.
The examples included below are simplified to help you migrate quickly to the new media player. If you have implemented a lot of customization on top of the older interface, additional work may be required.
If you are implementing the media player for the first time, or you are willing to start over, see the section on Media Player Examples above
and use the
MediaPlayerSample app (located in the WDK in the directory $HOME/YCTV-ADK/YCTV-SIM-Latest/TV/Widgets/) as a template. In order to use the
KONtx.mediaplayer interface, your app must use the KONtx Framework version 1.3 and above.
In the old interface, you created the player object by instantiating the KONtx.videoplayer class. In the new interface, the media player is a global object that you initialize by calling its initialize() method. Change your player object instantiation to the following call:
In the old interface, events are subscribed to in the KONtx.videoplayer constructor within the events object. In the new interface, a listener is created for each event, and a dispatcher function subscribes to the media player object. These event listeners exist outside of the media player object.
The following example will show how to transform a video player events object into media player event listeners. Here is a simple video player constructor:
The first step is to transform each event handler function into a switch case in a dispatcher function. Note this dispatcher function name starts with an underscore (_) to indicate that it is a private method in the fullscreen media player view—for example:
Most of the older video player event handlers map directly to the new media player handlers. See the section on Media Player Events below for more details.
Now that the event listeners are encapsulated in a single dispatcher function, the next step is to subscribe this dispatcher function to the media player object so it can listen for events—for example:
When your fullscreen view is no longer displayed you should avoid catching media player events. It is important to make sure the handlers are unsubscribed when the view is unloaded. Unsubscribe from the media player object as follows:
Call _registerHandlers()in your player view’s updateView() method and call _unregisterHandlers()in your player view’s hideView() method.
The transport overlay user interface control provides optional media playback buttons and a visual indication of the playback progress. In the deprecated video player interface, this control is implemented through the KONtx.control.VideoTransportOverlay class, which is an accessory to the KONtx.videoplayer class, and must be attached to an instantiation of the video player.
In the new interface, the KONtx.control.MediaTransportOverlay class is not attached to the KONtx.mediaplayer object but accesses the global KONtx.mediaplayer object directly. If you have not performed any customization on this control, simply replace the video transport overlay instantiation with the following:
Since the KONtx.mediaplayer is a singleton, there will always be just one instance, so it can automatically bind itself. Attaching the accessory to the media player object is no longer necessary.
With the new media player interface, playlists are full objects instead of just arrays. Playlist objects can be instantiated and populated with multiple streams of media, supporting varying connection speeds—for example.
The KONtx.media.Playlist and KONtx.media.PlaylistEntry classes are normal extendable KONtx classes that you can extend for more powerful behavior, as shown in the Fast Expiring Content Example above.
The default viewport configuration for the media player has the (x,y) position at (0,0) and sets the width and height of the viewport to 1920 x 1080. To use the default viewport configuration for the media player use the following methods in your views updateView() method:
See the Aspect Ratio Example above to configure the aspect ratio of video playback for 4:3 content without stretching.
At this point you can set the playlist and play the media—for example:
This completes the simple migration from KONtx.videoplayer to KONtx.mediaplayer. To support additional features see the Media Player Examples section above.