I have a very simple task - just to show playback controls while playing video on VideoView
. But I can't solve it.
Here is the piece of code that I use for initializing VideoView
and setting MediaController
:
videoView.setVideoURI(Uri.parse(videoUrl));
MediaController mediaController = new MediaController(this);
videoView.setMediaController(mediaController);
videoView.setKeepScreenOn(true);
videoView.setOnPreparedListener(mp -> {
progress.setVisibility(View.GONE);
videoView.start();
mediaController.show(0);
});
The thing is that mediaController.show(0)
doesn't give any effect. Controls just show up for 3 seconds and then disappear.
Also I have tried to override MediaController's hide()
method:
@Override public void hide() {}
Well, it works - controls never hide, but unfortunately hardware 'back' button stops working. Without override hardware 'back' button on first tap close media controls, on second tap - brings user to previous screen, as expected.
Are there any working solutions?
android.widget.VideoView. Displays a video file. The VideoView class can load images from various sources (such as resources or content providers), takes care of computing its measurement from the video so that it can be used in any layout manager, and provides various display options such as scaling and tinting.
The basics The following classes are used to play sound and video in the Android framework: MediaPlayer. This class is the primary API for playing sound and video. AudioManager.
If you try to display media controler buttons as below :
videoView.start();
mediaController.show(0);
for some reasons show(0) is ignored.
But if you delay the call of show(0) a few milliseconds, it will work :
....
public Handler handler = new Handler();
....
videoView.start();
handler.postDelayed(
new Runnable() {
public void run() {
mediaController.show(0);
}},
100);
It looks a bit buggy to me and if it is design intent, it is poorly documentated.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With