18

I have a list of cards using Recycler View of android. I am showing some text and below it video view.

The list was scrolling well with playing video smoothly until I enabled controls using setMediaControll().

After enabling this video media controls when I scroll the list up/down the control stays in the same position even when the video view moves freely along with list view scroll movement.

These control should move along with list view they stay stationary. What may have caused this? Is this expected platform behaviour?

Update code :

Layout :

<FrameLayout
                    android:layout_centerHorizontal="true"
                    android:layout_centerInParent="true"
                    android:layout_gravity="center_horizontal"
                    android:id="@+id/frame_layout_video_view"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content">

                    <VideoView
                        android:id="@+id/video_view"
                        android:layout_width="360sp"
                        android:layout_height="225sp"
                        android:layout_gravity="center" />

                    <ImageView
                        android:id="@+id/image_button_play"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center_vertical|center_horizontal"
                        android:contentDescription="play_pause_button"
                        app:srcCompat="@drawable/ic_play_circle_filled_white_24px" />

                    <ProgressBar
                        android:id="@+id/progressbar_video"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center_vertical|center_horizontal"
                        android:visibility="gone" />

                </FrameLayout>

In view holder :

MyViewHolder(View itemLayoutView) {
            super(itemLayoutView);
..........
myVideoView = itemLayoutView.findViewById(R.id.video_view);
..........
}

Code to start video playing :

    ..........
    Uri uri = Uri.parse(url);
            holder.myVideoView.setVideoURI(uri);
            MediaController fsm = new MediaController(mContext,finalistFragment , url, holder.myVideoView);
            fsm.setAnchorView(holder.myVideoView);
            holder.myVideoView.setMediaController(fsm);
..........

For the list, I am using RecyclerView.

Prashant
  • 4,474
  • 8
  • 34
  • 82
  • VideoView + Listview is not a good combination. But you can read this, not entirely your requirement but can help you https://medium.com/@v.danylo/implementing-video-playback-in-a-scrolled-list-listview-recyclerview-d04bc2148429 . – Sunil Sunny Jan 04 '18 at 05:50
  • Can you post some code in order for us to reproduce the problem. – Niza Siwale Jan 30 '18 at 12:11
  • did you tried mediaController.setAnchorView() method – Anu Martin Jan 31 '18 at 09:35

2 Answers2

0

this is indeed a known behavior with ListView and RecyclerView and is because these things only load the views that are visible to user and since user cannot reach the controls on scroll so they will freeze or maybe they stay in same place

my suggestion for you is to override setOnScrollListener for your RecyclerView, but for VideoView specifically I don't know how exactly.

I hope this helps

Pouya Danesh
  • 1,557
  • 2
  • 19
  • 36
0

This is indeed an issue related to the RecyclerView behavior as suggested by Mr. pouya if you have set a scrollistner in recyler adapter then overide the method in you activity or fragment of the same srcollistenr with the recyler view method if this not works then Just add & wrap the videoView in a FrameLayout inside your cardview and refer the below link for further instruction

https://stackoverflow.com/a/24529711/9287163

Note: Please provide us with your card view layout XML file and code where you are setting the media controller to.

krishank Tripathi
  • 616
  • 1
  • 7
  • 23