top of page

Migrating to ExoPlayer 2.9.0

  • Writer: Deepan
    Deepan
  • Jun 10, 2019
  • 4 min read


What?

ExoPlayer is an application level API for android which replaces the MediaPlayer API for playing audio and video both locally and over the internet. ExoPlayer is easily customisable and has many features which can be used in any android application. Recently, ExoPlayer 2.9.0 included DASH streaming support and JAVA 8 and it has been the talk of the day for a while now. Migration from an older ExoPlayer versions to the new one involves a few steps and it is quite easy. We will go through that later.

What’s new?

1. Java 8

2. Audio focus handling

3. Simplified player setup with BandwidthMeter

4. Support for spherical (180°/360°) playback

5. Load error handling policy customisation

6. Improved seeking in progressive streams

Things you should know

Before diving into the comparisons and actual migration, you should know about a few terms in video encoding such as Adaptive Streams, H.264, HLS, MPEG-DASH, SmoothStreaming, Adobe HDS

Adaptive Streams

Adaptive streams (DASH, SmoothStreaming and HLS) consist of multiple media tracks, often the same content in different qualities (for example there can be SD, HD and 4K video) or in different languages (for audio and subtitle). For playback, a client can pick any of these tracks to play depending on the device and network capabilities. Similarly for downloading, it is often enough to download only a few of the tracks. The tracks which need to be downloaded should be chosen manually before the download starts.

H.264

H.264 is a type of video compression, which converts the digital video format into something that occupies less amount of space suitable for streaming.

HLS — HTTP Live Stream

HTTP Live Stream was developed as a part of Apple’s Quicktime, Safari, OS X and iOS software by Apple. Soon, several other products such as Google Chrome, Mozilla, Microsoft Edge started to adapt to this streaming service. HLS is similar to MPEG-DASH as both breaks the overall media stream into small chunks of files and each file is downloaded and processed into one big stream. It supports H.264 formats and this is one of the reasons it became a huge thing back then. HLS supports a wide range of devices globally and is still growing in numbers. Well, Apple did a great job in developing this service. The overall stream is usually broken into chunks of 5–10 seconds streams and the client player takes care of playing the whole file in an adaptive fashion. Alternative low, mid and high streams are produced for each chunk and the client player listens to the bandwidth changes in order to choose the respective stream.



MPEG-DASH

Dynamic Adaptive Streaming over HTTP (DASH), also known as MPEG-DASH, is an adaptive bitrate streaming technique. It follows adaptive bitrate method in order to provide the highest possible quality output for a given network service. DASH is open source and supports a wide range of devices except for the Apple devices. If you are willing to compromise that, I would surely recommend you to migrate to DASH. When it comes to android development, you don’t need to look at this disadvantage as you will be supporting only the Android devices. ExoPlayer 2.9.0 supports DASH streaming. (So, ‘Voila’ for all the android developers out there!)



Microsoft SmoothStreaming

Smooth Streaming is a feature of Internet Information Services (IIS) Media Services, an integrated HTTP-based media delivery platform developed by Microsoft. Minimal buffering and fast start-up time by adapting the quality of the video stream in real-time based upon the consumer’s changing bandwidth and CPU conditions, are the major features of SmoothStreaming.

Adobe HDS (no support in ExoPlayer)

Adobe HTTP Dynamic Streaming (HDS) is the best way to deliver multi-bitrate content over HTTP to Adobe Flash Player or Adobe AIR. Adobe HDS provides all of the capabilities required for delivering premium digital video and audio, including intelligent multi-bitrate adaptive logic and robust content protection using Adobe Primetime DRM. Adobe HDS is based on the Fragmented F4V File Format (F4F).

Please refer the link above for the feature table for each of these streaming services. Choosing between the different streaming services totally depends on the use case of the application and on the developer.

Migrating to ExoPlayer 2.9.0

Previously, in the older versions of ExoPlayer, you will have to create a Handler object, a BandwidthMeter object and create a TrackSelection object with the help of those two objects. The DataSourceFactory is then created with the help of a TrackSelector and then the MediaSource has to be derived from the DataSourceFactory. The MediaSource can be ExtractorMediaSource, HlsMediaSource depending on the video type. If the type is “m3u8”, HLS is preferred and for the rest, ExtractorMediaSource is preferred. This consists a lot of boilerplate code and is tiresome for the developer to instantiate each objects every time he wants to play a video and is also memory expensive. A workaround is to create a static class (object in kotlin) and pass the Handler and BandwidthMeter objects to the Player instantiation methods inside the activity. This leads to memory leaks and usage of memory that fails to under go garbage collection.



To avoid this, ExoPlayer 2.9.0 removes the need to create the Handler and the BandwidthMeter objects as it creates and handles those objects on its own. Still, the developer can modify the BandwidthMeter if they want by writing a custom BandwidthMeter and passing it to the TrackSelector. All you need to do is create a DataSourceFactory and identify the MediaSource, pass it to the player in order to play a video. This is so easy and fun to code with. In addition to its simplicity, ExoPlayer 2.9.0 has added DashMediaSource support in order to support MPEG-DASH streaming in android devices. You can now use either HLS or DASH adaptive streaming service while using ExoPlayer in your android application.



Thanks for reading!

 
 
 

Comments


bottom of page