exoplayer android example

ExoPlayer Android Example- Best Alternative of Android VideoView

Today I am going to show you complete details about ExoPlayer Android Example. Earlier, I was using VideoView and MediaPlayer to play video and audio in android app. But the Android Videoview always create problems on some device like – white/black screen, audio is playing without video, buffering problem etc.

I was searching for an alternative to Android VideoView, then I found Android Exoplayer.

It is an open source project. Even Google also mention about Android Exoplayer in Android Documentation. I found it really gives feel like YouTube Player. So here I am giving step by step process, how to use Exoplayer in Android app.

Android Exoplayer

ExoPlayer is built on top of Android’s low-level media API’s. You can play both the Audio and Video file from android phone or from URL on Exoplayer.  Here are some pointers to know before start coding on ExoPlayer Android Example.

1) ExoPlayer has support for DASH(Dynamic Adaptive Streaming over HTTP), SmoothStreaming and for HTTP Live Streaming (HLS) which is unavailable on the traditional media player.
2) ExoPlayer has the ability to customize and extend the player as per the requirement allowing many components to be replaced with custom implementations.
3) ExoPlayer supports a variety of media formats which are MP4, MP3, WebM, M4A, MPEG-TS, and AAC.
4) You can update your ExoPlayer with the latest version to get more support. Latest Version

Video- ExoPlayer Android Example

Login & Download source code


50 days android course


Step By Step Guide –

1) Add ExoPlayer Gradle Dependency
2) Add SimpleExoPlayerView in Layout
3) Initialize ExoPlayerView and ExoPlayer
4) Add Internet Permission in AndroidManifest
5) Run the Code in Real Device

Add ExoPlayer Gradle Dependency

Create a new project on AndroidStudio, My project name is Exoplayer_video. You have to Add ExoPlayer dependency on android project gradle file. You can change ExoPlayerversion code. I included all the exoplayer library file explicitly because some time it failed to get some library.

Add SimpleExoPlayerView in Layout

Now open activity-main.xml file and type SimpleExo, so you will see the suggested SimpleExoPlayerView in Topup window. Just select it and set width and height as per your need. Also, give is ID like @+id/exoplayerview.

Initialize ExoPlayerView and ExoPlayer

First, understand how ExoPlayer does work. The first step is to initialize ExoPlayerView and configure it. Configuration parameters  are BandwidthMeter, TrackSelector, HttpDataSourceFactory and MediaSource.

BandwidthMeter – for monitoring bandwidth of internet connection.

TrackSelector – to buffer and keep player current status.

HttpDataSourceFactory – media file URL path.

MediaSource – to bind all these things with ExoPlayer.

Once you set all these parameters, You can set ExoPlayer with ExoPlayerView. Then call prepare() method.

One Important point about ExoPlayer is “There is no start and stop”. So you have to call when player ready like-  exoPlayer.setPlayWhenReady(true); If you pass false play will stop playing.


Add Internet Permission in AndroidManifest

In this ExoPlayer Android Example, I am trying to play video from URL. So we need to add internet permission on AndroidManifest file. If you are using a local file from the android device then you don’t need to do this task.

Run the Code in Real Device

Now Run this code in the Real device. you will see the video getting started.

Please leave your comment about video lesson and what more you want to learn from me.

Read MoreCreate Facebook Messenger type Floating Icon and Send FCM Notification to Device

50 days android course

Posted in andorid and tagged , , , .

kamal bunkar

I Am Post Graduation (M.Tech. C.S.E) from VNIT, Nagpur. I Have Published Two Research Paper On International Journal. My Apps on Google Play Store- Sanyukt Parivar(Mp Police ), NOTOtag- Digital Chhindwara, The Tubby-VoiceRecognizer & More.
Contact me at kamal.bunkar@blueappsoftware.in


  1. If I want to play Audio from server then what should be the changes?
    How I can put Audio Image(Song poster) instead of Video?

    • video caching is not possible for offline use. because video size can be any thing from 2 mb to 1000 mb and more. Even if you check youtube offline videos it will first store on your phone memory then you can watch it on offline mode. So if you want offline video then first store it on phone.

Leave a Reply

Your email address will not be published. Required fields are marked *