0

I am creating a recyclerview with multiple videoview in it. How can i play only one videoview at a time and stop the other videoview in the recyclerview.

PlayButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            int PlayStopButtonState = (int) PlayButton.getTag();

            int previousPosition = mCurrentPlayingPosition;
            if (PlayStopButtonState == 1) {

                mCurrentPlayingPosition = getAdapterPosition();

                mVideoAudioCallbacks.onClick(100 + getAdapterPosition());
                PlayButton.setImageResource(R.drawable.playstop);
                PlayButton.setTag(2);

            } else {
                mCurrentPlayingPosition = -1; // nothing wil be played after hitting stop
                mVideoAudioCallbacks.onClick(200 + getAdapterPosition());
                PlayButton.setImageResource(R.drawable.playarrow);
                PlayButton.setTag(1);
            }

            if(previousPosition != -1)
                notifyItemChanged(previousPosition);

        }
    });

when i click on video it plays fine. but when in click on other videoview in the list both start playing. i want only one must play at a time

Shikha Ratra
  • 697
  • 3
  • 12
  • 28
  • i have to modify it.but don't know how to do it – Shikha Ratra Apr 11 '16 at 11:08
  • You are expecting like facebook's videoView? If you want to do the same as facebook you should detect your recyclerView's item have to in the midde of screen to display the videoView. So take a look at my answer at http://stackoverflow.com/questions/34586637/get-center-visible-item-of-recycleview-when-scrolling This is horizontal recyclerView. And you can make another one with vertical recyclerview as well. – TranHieu Apr 12 '16 at 07:45
  • @TranHieu Well yes! that is what i want but ,Is there any way that when i click on play button the video play and when i click on next play button the previous video stop playback – Shikha Ratra Apr 12 '16 at 08:36
  • @user6071487 I understood your question, if you want to click on play button of another video. That's mean you have to scroll down isnt it?. In my code I had a recyclerView's function called: onScrollStateChanged. That's mean if you scroll down or up it will make callback to this function. You can make the videoView become pause or stop when you are scrolling. When the recyclerview stop scroll it'll make callback to onScrolled function, and you can make the videoView auto play – TranHieu Apr 12 '16 at 08:48
  • @TranHieu sir,i have a button called play on each videoview. when i play that button video plays but when i click on other video both video plays. i just want only one video must play at a time on click – Shikha Ratra Apr 12 '16 at 09:22
  • @user6071487 as I said, When you scroll recyclerview, the function onScrollStateChanged is called. You put your code to stop videoView inside this function. – TranHieu Apr 12 '16 at 09:28
  • ok @TranHieu i will try that.. thanks. – Shikha Ratra Apr 12 '16 at 09:37
  • was your problem solved? – Anjani Mittal Oct 26 '18 at 09:13

0 Answers0