0

I'm having multiple VideoView inside a RecyclerView. The problem is that on scroll they remain at the same position while the parent view moves.

I have coded the media controller anchored to the ImageView-

mediaController = new MediaController(imageView.getContext());
mediaController.setAnchorView(imageView);
mediaController.setMediaPlayer(imageView);
imageView.setMediaController(mediaController);

Here is the behavior in the video.

Although this is usable but definitely destroys the UX.

Any workaround other than to permanently hide the media Controller.

Pradyut Bhattacharya
  • 5,440
  • 13
  • 53
  • 83

1 Answers1

0

I solved a similar problem by hiding the media controller when the video view is not FULLY visible.

This is a custom media controller. It will check the visibility before showing.

package com.example.sixths.view;

import android.content.Context;
import android.widget.MediaController;

public class AutoMediaController extends MediaController {

    public interface Checker {
        boolean check();
    }

    public Checker checker;

    public AutoMediaController(Context context) {
        super(context);
    }

    public void setChecker(Checker checker) {
        this.checker = checker;
    }

    @Override
    public void show() {
        if (!checker.check()) {
            /* refuse to show if video_view is not fully visible */
            return;
        }
        super.show();
    }
}

check whether the video view is fully visible in your activity.

public class SomeActivity extends AppCompatActivity implements AutoMediaController.Checker {

    /* .... */

    public boolean check() {
        Rect scrollBounds = new Rect();
        scroll_view.getDrawingRect(scrollBounds);

        float top = video_view.getY();
        float bottom = top + video_view.getHeight();

        /* if fully visible */
        return scrollBounds.top <= top && scrollBounds.bottom >= bottom;
    }

}

pass the checker to the controller.

        AutoMediaController mediaController = new AutoMediaController(this);
        mediaController.setChecker(this);

ref: Android: how to check if a View inside of ScrollView is visible?

GlassesQ
  • 21
  • 4