Click here to Skip to main content
15,886,720 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using exoplayer for playing video in recyclerview. I retrieve videos from firebase and play it in exoplayer .But the problem I am facing is all the videos play simultaneously in background and get the messed up. Also it consumes lots of data. If onces the video complete playing the it don't get start again. How can I stop them playing in the background. Here is my code

val uri = Uri.parse(contentDTOs[p1].videourl)
    val view = viewholder.findViewById<SimpleExoPlayerView>(R.id.detailviewitem_video_contents)
    val exoplayer= ExoPlayerFactory.newSimpleInstance(context,trackSelector)
    val datasourcefactory = DefaultHttpDataSourceFactory("exoplayer")
    val extractorsFactory=DefaultExtractorsFactory()
    val media = ExtractorMediaSource(uri,datasourcefactory,extractorsFactory,null,null)
    view.player = exoplayer
    exoplayer.prepare(media)
    exoplayer.playWhenReady = true
    val loopingSource = LoopingMediaSource(media)
    exoplayer.playWhenReady = true
    exoplayer.prepare(loopingSource)


override fun onPause() {
    super.onPause()
    exoplayer.stop()
}
override fun onStop() {
    super.onStop()
    exoplayer.stop()
}


What I have tried:

I have tried to pause videos playing in the background of exoplayer
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900