Home > Software design >  How to manage exoplayer with java in android studio?
How to manage exoplayer with java in android studio?

Time:01-08

I am searching Exoplayer using with ViewPager in java but can not find the full tutorial.

I have issue for stopping and pausing exoplayer while swiping another video. Is there any tutorial please suggest me.

CodePudding user response:

You can use addOnPageChangeListener for getting the user interaction for the view pager. add this code snippet in the onCreate method.In my project ,I handle it like this ::

  binding!!.mediaViewPager.addOnPageChangeListener(object : OnPageChangeListener {

                override fun onPageScrolled(
                    position: Int,
                    positionOffset: Float,
                    positionOffsetPixels: Int
                ) {
                    if (exoPlayer.isPlaying) {

                        exoPlayer.pause()


                    }

                }

                override fun onPageSelected(position: Int) {
                  
                        if (exoPlayer.isPlaying) {
                            exoPlayer.pause()
                        }
                       

                    

                }

                override fun onPageScrollStateChanged(state: Int) {
                  

                    exoPlayer.pause()
                   

                }
            })

CodePudding user response:

Play Exo Player With PageViwer

Link: https://github.com/google/ExoPlayer/issues/7947

Example: https://github.com/kakajika/PlayerPagerExample

  • Related