THEO Blog

Going Big Screen: How To Use Your Own Player on Samsung Tizen?

Listen to this blog:

In the previous blog posts, we’ve covered how to bring your applications to Samsung Tizen, discussed how to leverage Samsung Tizen's native playback component, AVPlay, as well as its use case limitations, and delved deeper into the technical limitations present across different Samsung Tizen versions and models. In this blog, we will take a look at how to utilise your own video player on Tizen and its benefits over the Native approach.

THIS IS A SNIPPET FROM OUR “GOING BIG SCREEN: BRINGING VIDEO TO SAMSUNG TIZEN” GUIDE WHICH YOU CAN DOWNLOAD HERE.

Build-Your-Own Approach: Leveraging MSE/EME APIs

Due to the limitations of native players such as AVPlay, the popularity of the “build your own” approach to video players is growing rapidly with OTT video publishers. This approach allows us to avoid the biggest issues with AVPlay due to the differences between Samsung TV models and Tizen versions.

When taking the build your own player approach, it is important that hardware capabilities for DRM decryption and media decoding can be leveraged. This has an impact on viewer experience as it allows to unlock capabilities such as HDR, but also is often important for battery efficiency. On Samsung’s Tizen platform media hardware access is possible thanks to the presence of the Media Source Extension (MSE) API and the Encrypted Media Extension (EME) API. Tizen has supported different versions of these APIs since Tizen 2.3 (2015 models). While versions differ, support is broad enough to implement all the most important use cases with only a limited set of limitations (but more on this later).

Big Screen Campaign Tizen_1

The MSE API provides access to the decoders. Samsung has gradually extended support on this over the last years, increasing frame rates, resolutions and bitrates as devices became more powerful. The API allows an application to allocate buffers on the audio and video decoders of the device and feed it with media data. This allows implementation of common streaming protocols such as HLS and MPEG-DASH (as well as others). A video player can download the required playlist or manifest, identify the relevant segments, download them and append them one after the other as playback happens.

Leveraging MSE for basic playback can be quite simple. In a rudimentary form, you should use the following steps:

  1. Get a handle on an HTML5 Video Element (or <video> tag).
    var video = document.getElementById('video');
  2. Create a new MediaSource through MSE-API.
    var mediaSource = new MediaSource();
  3. Wait for the MediaSource to "open" to create a SourceBuffer (the direct interface to the decoders buffer where you can store raw data) and load it in the video element.
    mediaSource.addEventListener('sourceopen',function(e){// ...var videoSourceBuffer=mediaSource.addSourceBuffer(‘videoMimeType’);// ...});video.src=window.URL.createObjectURL(mediaSource);
  4. Download and parse the right playlist for your stream (keeping in mind bitrate selection) and identify the segments you want to load.
  5. Download the appropriate segments and append them to your SourceBuffer.
    while(nextSegment){var segment = await download(nextSegment.uri);sourceBuffer.appendBuffer(segment);
    nextSegment = findNextSegment(playlist);}
In parallel the EME API enables applications to play back DRM protected content and provides access to the Content Decryption Modules (CDMs) which are available on the platform. On Tizen this allows you to access the underlying key systems for PlayReady and Widevine. When media is protected with one of these DRMs, the EME API will expose this and allow the application to configure the CDM with a response to its license challenge.

Leveraging the Encrypted Media Extensions API to enable playback of DRM protected content is relatively straightforward:

  1. Request access to the Key System
    navigator.requestMediaKeySystemAccess('com.widevine.alpha',options);
  2. Create a MediaKeys object on which the media session will live later on.
    var mediaKeys = keySystemAccess.createMediaKeys();
  3. Listen for an encrypted-event indicating a new DRM session to be started. 
    video.addEventListener('encrypted',function(event){var keySession= mediaKeys.createSession();keySession.generateRequest
    (event.initDataType, event.initData);
    // ...});
  4. Handle Messages from the session when it faces encrypted content with a key it doesn't know. 
    keySession.addEventListener("message",function(event){var request= event.message;var response=await postRequest(licenseServerURI, request);keySession.update(response);});
  5. With the License response the CDM can then start decryption of the content so it can be played. 
Thanks to these MSE/EME APIs, developing video playback with complex handling of media became possible. Where THEOplayer was the first media player to do complex handling of streaming media in browser environments (even without the use of MSE/EME), various other companies started providing libraries since the APIs became available. As MSE and EME are only APIs, there is however more than meets the eye: development based on these APIs still requires a proper understanding of media and the web as the entire implementation of the streaming protocols has to happen in dedicated code.

 

The very simple examples earlier in this article can already provide basic playback of the downloaded segments. A fully featured media player however does much, much more such as:

  • Identifying user behavior such as playing / pausing.
  • Reacting to the user seeking to a new timestamp.
  • Modifying the media player’s volume.
  • Following the appropriate autoplay policies to start playback upon the application being opened.
  • Providing support for changing the playback speed.
  • Monitoring the available network environment and dynamically switching to the appropriate bitrate.
  • Ensure continued playback in case media data is unavailable.
  • Avoiding and handling buffer underrun (and the resulting stalling behavior for viewers).
  • Exposing alternative audio and video tracks to the viewer and allowing them to switch.
  • Retrieving and overlaying subtitles and closed captions timed exactly right to ensure a good viewer experience.
  • Handling errors in the DRM license request flow.
  • And much, much more…

Even with all of the basics implemented, there is a large difference between different media player options. While there are open source libraries such as hls.js, dash.js and Shaka Player that provide basic playback support for the HLS and/or MPEG-DASH protocol, more advanced players such as THEOplayer provide even more support such as integrations with various DRM systems, monetization options with CSAI and SSAI, picture in picture support, support for offline downloading, etc.

In the next blogpost, we are going to lay out the key considerations when picking a media player for your Build-Your-Own approach. Additionally, we will also summarise with the key takeaways on how to pick the most suitable player strategy for Samsung Tizen.

You can download the complete version of this topic in our “GOING BIG SCREEN: BRINGING VIDEO TO SAMSUNG TIZEN” guide here.

Questions about our Tizen support? Contact our THEO experts.

Subscribe by email