Include the following dependency in your build.gradle files.
// Project level build.gradle
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
- Added method to return playerview from MasterExoPlayerHelper, now we can customize player using getPlayer() on MasterExoPlayerHelper Example: masterExoPlayerHelper.getPlayerView().resizeMode = AspectRatioFrameLayout.RESIZE_MODE_ZOOM
<com.master.exoplayer.MasterExoPlayer
android:id="@+id/masterExoPlayer"
android:layout_width="match_parent"
android:layout_height="match_parent" />
binding.frame.url = model.sources
val recyclerView: RecyclerView = ....
val masterExoPlayerHelper = MasterExoPlayerHelper(mContext = this, id = R.id.masterExoPlayer)
masterExoPlayerHelper.makeLifeCycleAware(this)
masterExoPlayerHelper.attachToRecyclerView(recyclerView)
//Used to customize attributes
masterExoPlayerHelper.getPlayerView().apply {
resizeMode = AspectRatioFrameLayout.RESIZE_MODE_ZOOM
}
1. id : Int
View id of ExoPlayerView used in item layout
2. autoPlay : Boolean
If you want to autoplay video once loaded
3. playStrategy : Float
Visible area from 0 to 1, Which matches to play video, default value = PlayStrategy.DEFAULT i.e 0.75 means 75% area visible to starts play
4. muteStrategy : Values from MuteStratagy.ALL or MuteStratagy.INDIVIDUAL
Defines whether mute/unmute affects all rows or individual
5. defaultMute : Boolean
If default video should be muted or not
6. loop:Int
Defines if you want to loop the video, default is unlimited, if set to 1 it will play only 1 time then stoop.
7. useController : Boolean
Defines if you want use controller for exo player or not. if set true then controller will be visible else hide, default will be false.
8. thumbHideDelay : Long
Defines duration in millisecond, defines delay before hiding thumbnail image while video plays.
//Inside onBindViewHolder of your RecyclerViewAdapter
binding.masterExoPlayer.listener = object : ExoPlayerHelper.Listener {
//Listen for buffering listener
override fun onBuffering(isBuffering: Boolean) {
super.onBuffering(isBuffering)
Log.i("TAG", isBuffering.toString())
}
//Update mute/unmute icon on player ready callback.
override fun onPlayerReady() {
super.onPlayerReady()
binding.ivVolume.visibility = View.VISIBLE
if (binding.frame.isMute) {
binding.ivVolume.setImageResource(R.drawable.ic_volume_off)
} else {
binding.ivVolume.setImageResource(R.drawable.ic_volume_on)
}
}
override fun onStop() {
super.onStop()
binding.ivVolume.visibility = View.GONE
}
}
Exo Player by Google (link)
Coil Image Loading library for Kotlin (link)
Portfolio (link)
Copyright 2020 Abhishek Pathak