Yogesh Choudhary Paliyal
Yogesh Paliyal's Blog

Yogesh Paliyal's Blog

ExoPlayer : Getting Started

ExoPlayer : Getting Started

Yogesh Choudhary Paliyal
·Apr 26, 2021·

1 min read

Subscribe to my newsletter and never miss my upcoming articles

Play this article

Exoplayer is a Powerfull MediaPlayer Library that is developed by Google and better than the MediaPlayer API.

It has many advantages over MediaPlayer API.

It is used by many video platform applications like Youtube, Netflix, etc.

First thing first: Add Dependency

implementation 'com.google.android.exoplayer:exoplayer:2.13.3'

Add Player to UI


for now we are using default controller and player, we can customize as per requirement, we will create our custom controller in future posts.

Initialize Player

Declare a video player global variable

private var mPlayer: SimpleExoPlayer? = null

Initialize ExoPlayer object

mPlayer = SimpleExoPlayer.Builder(this).build()

Create A MediaItem : mediaItem is used to give source of video to play, here videoUrl is the Uri of the video.

val mediaItem = MediaItem.Builder()

set mediaItem to player

mPlayer?.playWhenReady = true
binding.videoPlayer.player = mPlayer

playWhenReady : It starts video playback when video is ready to play

binding.videoPlayer.player \= mPlayer : Attack player to UI

mPlayer?.prepare() : It will start preparing player to stating playing the video

Free up resources

override fun onDestroy() {
    mPlayer = null

mPlayer?.release() : This will release the memory taken by the player

Check out the source code on GitHub

Source Code

The post ExoPlayer : Getting Started appeared first on TechPaliyal.

Share this