In first case I have already used this player inside container and it is working fine. But on second case there is a container i.e: Recyclerview inside that there is a Viewpager and inside this I have to use this player. So can anyone guide me how can I achieve this. Below code is the View holder of the adapter set inside view pager. Here I am not able to play the player as nothing seems to display.
private val exoVideo = itemView.findViewById(R.id.exoVideo) as PlayerView
private val ivPost = itemView.findViewById(R.id.ivPost) as ImageView
private val ivThumbnail = itemView.findViewById(R.id.ivThumbnail) as ImageView
private val ivVolume = itemView.findViewById(R.id.ivSound) as ImageView
private val ivPlay = itemView.findViewById(R.id.ivPause) as ImageView
private val progressBar = itemView.findViewById(R.id.clpVideoProgressBar) as ProgressBar
private var helper: ExoPlayerViewHelper? = null
private var videoUri: Uri? = null
var listener: EventListener? = null
private val audioManager = itemView.context.getSystemService(AUDIO_SERVICE) as AudioManager
override fun bindFeed(objFeedFile: FeedFile?) {
if (objFeedFile != null) {
if (objFeedFile.fileType == Constant.IMAGE) {
ivPost.visibility = View.VISIBLE
ivThumbnail.visibility = View.GONE
Glide.with(itemView.context)
.load(objFeedFile.fileName)
.into(ivPost)
} else {
this.videoUri = Uri.parse(objFeedFile.fileName)
ivPost.visibility = View.GONE
Glide.with(itemView.context)
.load(objFeedFile.videoThumb)
.into(ivThumbnail)
}
}
}
override fun getPlayerView() = exoVideo
override fun getCurrentPlaybackInfo() = helper?.latestPlaybackInfo ?: PlaybackInfo()
override fun initialize(
container: Container,
playbackInfo: PlaybackInfo
) {
if (helper == null && videoUri != null) {
Log.i("videoUri",videoUri.toString())
helper = ExoPlayerViewHelper(this, videoUri!!)
}
if (listener == null) {
listener = object : EventListener {
override fun onFirstFrameRendered() {
progressBar.visibility = View.VISIBLE
ivPlay.visibility = View.GONE
ivVolume.visibility = View.GONE
ivThumbnail.visibility = View.VISIBLE
}
override fun onBuffering() {
progressBar.visibility = View.VISIBLE
ivPlay.visibility = View.GONE
ivVolume.visibility = View.GONE
ivThumbnail.visibility = View.VISIBLE
}
override fun onPlaying() {
progressBar.visibility = View.GONE
ivPlay.visibility = View.GONE
ivVolume.visibility = View.GONE
ivThumbnail.visibility = View.GONE
}
override fun onPaused() {
progressBar.visibility = View.GONE
ivPlay.visibility = View.VISIBLE
ivVolume.visibility = View.VISIBLE
ivThumbnail.visibility = View.VISIBLE
}
override fun onCompleted() {
progressBar.visibility = View.GONE
ivPlay.visibility = View.VISIBLE
ivVolume.visibility = View.VISIBLE
ivThumbnail.visibility = View.VISIBLE
}
}
helper!!.addPlayerEventListener(listener!!)
}
helper!!.initialize(container, playbackInfo)
}
override fun play() {
if (helper != null) {
helper!!.play()
}
}
override fun pause() {
helper!!.pause()
}
override fun isPlaying() = helper?.isPlaying ?: false
override fun release() {
if (listener != null) {
helper?.removePlayerEventListener(listener)
listener = null
}
helper?.release()
helper = null
}
override fun wantsToPlay() = visibleAreaOffset(this, itemView.parent) >= 0.65
override fun getPlayerOrder() = adapterPosition
}
In first case I have already used this player inside container and it is working fine. But on second case there is a container i.e: Recyclerview inside that there is a Viewpager and inside this I have to use this player. So can anyone guide me how can I achieve this. Below code is the View holder of the adapter set inside view pager. Here I am not able to play the player as nothing seems to display.