ExoPlayer 2 - Improved demo app

Olly Woodman
AndroidX Media3
Published in
3 min readSep 8, 2016

The ExoPlayer demo app is the de facto starting point for most newcomers to ExoPlayer. You can inspect the demo app’s source code, understand how it works and use this knowledge to build your own application. Unfortunately, doing this with the ExoPlayer 1 demo app was far from easy. At ~3500 lines of code it was a lot to take in, and whilst ~1500 of those lines were boilerplate that could be quickly identified and ignored, the remaining ~2000 lines (PlayerActivity, DemoPlayer and the RendererBuilder implementations) were essential reading.

In ExoPlayer 2 the demo app has been greatly simplified. There are ~1800 lines of code in total, a reduction of ~50%. Of these only ~600 lines (PlayerActivity) are essential reading, a reduction of ~70%.

It was important that this simplification did not come at the cost of removing features, in part because many developers use the demo app as a direct starting point from which to develop their own applications. Every feature removed would have been a feature that multiple developers would have had to re-implement for themselves. The simplification was instead achieved by adding higher level components such as SimpleExoPlayer to the library, making it possible to get up and running with far fewer lines of code. In fact, improvements to the library have not only allowed us to cut the size of the demo app in half, but have also allowed us to make it significantly more powerful at the same time. A rundown of some of the new features can be found below.

Easily play and share your own content

Lists of content defined in a simple JSON format can be loaded into the demo app. This provides a convenient way of sharing sample or test content without modifying the code. Playbacks can also be started using Android Intents, either from the terminal or from other applications. For more information, see: Demo Application: Playing your own content.

Playlist support

“next” and “previous” buttons for moving between items in a playlist

ExoPlayer 2 adds playlist support, allowing pieces of content to be played seamlessly one after another. The demo app now features “next” and “previous” buttons, allowing a user to move between items in a playlist. Static playlists can be defined in the JSON format mentioned above, and can also be specified when starting the demo app with an Intent.

Seeking in live streams (DASH and SmoothStreaming)

ExoPlayer 2 adds support for seeking in live streams for DASH and SmoothStreaming (support for seeking in live HLS streams is planned). The demo app supports this feature, displaying a seek bar whose duration is equal to the length of the live window.

Improved track selection

An adaptive selection consisting of only the 720p and 1080p streams

The ExoPlayer 2 demo app adds a number of improvements around track selection, including:

  • The ability to select a subset of video tracks that should be eligible for selection during an adaptive playback.
  • The ability to enable random adaptation between video tracks during an adaptive playback, for testing purposes.
  • A message is displayed if all tracks of a given type (i.e. all audio tracks or all video tracks) are unsupported by the device. Previously it was not possible to distinguish between this case and the content simply not containing any tracks of that type.
  • Detailed track information is output to logcat, including information about unsupported tracks. An example is shown below for a DASH stream consisting of four video tracks (all supported) and three audio tracks (unsupported DTS and AC3 tracks, and a supported AAC track). An [X] indicates a track that is selected for playback.

A build variant that includes extension decoders

In ExoPlayer 1, there was a whole separate demo app to demonstrate use of ExoPlayer’s software decoder extensions! In ExoPlayer 2 there’s simply a build variant of the standard demo app that includes and enables the extensions. For more information, see: Demo Application: Including extension decoders.

--

--