ExoPlayer 2 : Playing Audio and Video

ExoPlayer is an application level media player for Android. It provides an alternative to Android’s MediaPlayer API for playing audio and video both locally and over the Internet.

New article

We have been using ExoPlayer 1.x.x for our some tv and radio projects. We are thinking about using ExoPlayer 2.x.x. I developed basic audio and video player for test. I think its performance is impressive. A lot of things changed from ExoPlayer 1.x.x. There is a post for beginners about changes, classes. Also you are considering what is ExoPlayer and why use, you can check this post.

Playing Audio

ExoPlayer supports many audio types, you can see all supported type from ExoPlayer’s website.

You need to set up a specific chain structure between classes, but you can play audio files in this way simply to show it.

If you want to play audio you can use 
 player.setPlayWhenReady(true); 
for pause 
 player.setPlayWhenReady(false);

Playing Video

ExoPlayer supports many video and stream formats. You can check with same url, which I share for audio formats.

When we are playing videos, we need to be careful about video formats. Because we need different MediaSource classes for different types.

HLS -> HlsMediaSource
DASH -> DashMediaSource
SS -> SsMediaSource
MP4 and others -> ExtractorMediaSource

Also you can play audio files with ExtractorMediaSource.

I created a repo for how to play audio and video basic way. I am still exploring and learning ExoPlayer 2. If you have some feedbacks for me, please share.

Useful Resources