Migrating to KONtx.mediaplayer

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.

Change the Constructor Instantiation to an Object Initialization

In your fullscreen view that implements the deprecated video player, find the JavaScript where KONtx.videoplayer is instantiated. It should be similar to the following:

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:

Transform the Events Object to Event Listeners

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.

Subscribe the Dispatcher Function to the Media Player Object

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.

Replace the Video Transport Overlay with the Media Transport Overlay

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.

Transform Playlist Arrays to Playlist Objects

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.

Set the Viewport Bounds

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.

Start the Media Playlist

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.

Table of Contents