ExoPlayer 2 - New audio features

Andrew Lewis
AndroidX Media3
Published in
2 min readJul 21, 2016

ExoPlayer 2 includes new features for music players and other audio-focused apps. Read on to find out about gapless playback and improved audio extensions.

Gapless playback

Some lossy audio compression algorithms pad the audio stream with silence which can introduce an audible gap between tracks. To eliminate this gap players need to:

  1. Read gapless playback metadata from the container.
  2. Trim the right number of samples from the start/end of the each song, based on the gapless playback metadata.
  3. Ensure the start of the next song is buffered in time for the transition.

ExoPlayer’s extractors parse common gapless playback metadata formats: Mp3Extractor handles metadata in Xing and ID3 headers, and Mp4Extractor parses udta boxes and will interpret edit lists that truncate the first/last audio samples as gapless playback metadata.

MediaCodecAudioRenderer trims its output audio stream to take into account the extracted metadata, providing its AudioTrack with a gapless stream of audio samples.

In ExoPlayer 2, apps specify a MediaSource to play. This can consist of a sequence of MediaPeriods forming a playlist. The player applies a consistent buffering policy across transitions from one period to the next, which helps avoid buffering during playback. More details on playlists will follow once the API is finalized.

Audio extensions

In ExoPlayer 2, we’ve reduced the amount of code needed to implement audio extensions. Audio extensions now subclass an abstract SimpleDecoderAudioRenderer in the core library. This class uses the same event listener interface as MediaCodecAudioRenderer so apps no longer have to implement two listeners. Audio extensions provide decoding functionality by implementing a ‘decode’ method in a SimpleDecoder, which decodes a sample synchronously.

ExoPlayer 2 has three audio extensions:

Note for FLAC users: Android’s built-in support for FLAC is currently provided via MediaExtractor. In ExoPlayer 1, MediaExtractor could be used via the deprecated FrameworkSampleSource. We are removing FrameworkSampleSource in ExoPlayer 2, so if you choose to upgrade you’ll need to transition to using the flac extension.

In ExoPlayer 2, the DemoPlayer wrapper now lives inside the core library and is named SimpleExoPlayer. This provides a high level interface to the player. It also includes (via reflection) any extensions that have been compiled, so the separate extensions demo app is no longer needed.

To try out the extensions in the demo app, follow the README instructions in each extension to build its native part (ffmpeg, opus, flac), then select the demo_extDebug build variant in Android Studio.

To conclude, ExoPlayer 2 makes implementing custom audio renderers much easier, adds a new FFmpeg-based extension and adds built-in support for playlists with gapless transitions.

--

--