MediaController appear on demand only - android

I have a video player in my android app. By default, the MediaController becomes visible upon playing for 3 seconds, if no activity.
The app goes through a series of short clips and that is fine, however, the MediaController pops up every time the video changes.
Is it possible to have it only show on demand (tapping the video view)?
I tried calling controller.hide() and controller.show(0) after I call vidPlayer.start(), but neither have worked. Any ideas?

final MediaController mc = new MediaController(this);
vView.setMediaController(new MediaController(this)
{
#Override
public void hide()
{
mc.show();
}
});
vView.setMediaController(mc);
vView.start();

Related

Android videoview causes blocking UI elements

Hi in my android application I am using videoview for streaming my videos. I face very unwanted behaviour from my videoview. The scenario is like this. I have activity A and activity B. Activity A has one simple button and on click of that button I am starting activity B which contains videoview and starts playing video as soon as it start my activity. So my observation is like this: Once I start Activity B it will call setVideoURI and start(). there are few callback methods one of them is setOnPreparedListener. when I call start() after some time It is executing setOnPreparedListener and after that it will start playing video. But in between before executing setOnPreparedListener if I come back to Activity A it will block that activity UI for some time. But if I wait till setOnPreparedListener get executes and then come back to Activity A then its working properly. This is not happening with all devices only with google devices like moto g and nexus. But I tried with htc or intel device it is working properly. My code looks like :
VideoView mVideoView =(VideoView)findViewById(R.id.myVideo);
//Creating MediaController
MediaController mediaController= new MediaController(this);
mediaController.setAnchorView(mVideoView);
//specify the location of media file
Uri uri=Uri.parse("http://abcExample.com/playlist.m3u8");
//Setting MediaController and URI, then starting the videoView
mVideoView.setMediaController(mediaController);
mVideoView.setVideoURI(uri);
mVideoView.requestFocus();
mVideoView.start();
mVideoView.setOnErrorListener(new OnErrorListener() {
#Override
public boolean onError(MediaPlayer mp, int what, int extra) {
Log.i("this is video view sample ... ", "this is video view sample ... this is on error listener ");
return true;
}
});
mVideoView.setOnPreparedListener(new OnPreparedListener()
{
#Override
public void onPrepared(MediaPlayer mp)
{
Log.i("this is video view sample ... ", "this is video view sample ... this is on prepared listener ");
}
});
mVideoView.setOnCompletionListener(new OnCompletionListener()
{
#Override
public void onCompletion(MediaPlayer mp)
{
Log.i("this is video view sample ... ", "this is video view sample ... this is on complete listener ");
}
});
Am I missing something or doing something wrong? Need some help. Thank you.
I'm having the same behaviour with videoview. I was looking for a solution but i didn't find anything. Maybe, It's possible that making a new task fix that issue. I'll try it

display time on android media controller

Am I missing something? Once I play a video using videoview, I cannot see the current time of the video on the media controller. (Running app on a ICS device, there is no time; however on a Honeycomb device there is time)
Code:
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
VideoView videoView = (VideoView) findViewById(R.id.videoView);
// Use a media controller so that you can scroll the video contents
// and also to pause, start the video.
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(videoView);
videoView.setMediaController(mediaController);
videoView
.setVideoURI(Uri
.parse("rtsp://v6.cache5.c.youtube.com/CiILENy73wIaGQmCZld_oqDeJhMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp"));
videoView.start();
}
Actually I noticed the time is there but it's so dim and I cannot see it. Is there any way that I can change the theme of the media controller?
The answer is kind of general to all of the controllers such a mediacontroller, dialog, toast, etc.
you can use ContextThemeWrapper:
instead of:
MediaController mediaController = new MediaController(this);
you can use:
MediaController mediaController = new MediaController(new ContextThemeWrapper(this,R.style.CustomTheme));

Android mediacontroller Play Pause controls not refresh properly

I have used MediaController in my activity its working fine but when I play video for first time then there should b pause button visible but instead there is play and when I press that button then the video is paused correctly and state remains the same and after that its working properly. And same thing happens when Video Completed.
Is this a bug or I am doing any thing wrong?
videoView.setOnPreparedListener(new OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer mp) {
mediaController = new MediaController(VideoPlayerActivity.this){
public void hide(){
}
public void show(){
if(isPlayingAd){
super.hide();
}else{
super.show();
}
}
};
videoView.setMediaController(mediaController);
mediaController.setMediaPlayer(videoView);
mediaController.show();
}
});
I've been having the same issue. I was not calling MediaController.setVideoView as you were, as I thought VideoView.setMediaController was sufficient for wiring things up. I tried adding that, then moving the call to show within onPrepared, and now it is working.
I wish I had a better understanding; my best guess is that perhaps everything needs to be wired up properly before the media is prepared, and before calling show. In any case, here is what I have:
mMediaController = new MediaController(VideoPlayerActivity.this, false);
mVideoView.setOnPreparedListener( new MediaPlayer.OnPreparedListener() {
#Override
public void onPrepared(MediaPlayer pMp) {
mMediaController.show();
}
});
mVideoView.setMediaController(mMediaController);
mMediaController.setMediaPlayer(mVideoView);
mVideoView.setVideoPath(uri); // may not be applicable in your case
mVideoView.requestFocus();
mVideoView.start();
As Oneworld mentioned on the other answer, I had same issue with old Samsung devices. Even though MediaController wired with VideoView properly, play button loses its sync until pause and play again with MediaController.
This thing seems only happens on old Samsung devices(KitKat and below i guess).
The only solution I found was play video programmically by videoview.start() before showing controller by mc.show().

How to make the MediaController visible throughout my video play

I am using MediaController in my app. But unfortunately the MediaController disappears after a time period of 3 secs. But I want my MediaController to be visible until my video plays fully.
How to achieve this.
By default the MediaController hides itself after 3 secs of time. In order to make it visible throughout our video playback we will have to override the hide() of MediaController. I have given the code snippet below.
final MediaController mc = new MediaController(this);
video.setMediaController(new MediaController(this) {
#Override
public void hide()
{
mc.show();
}
});
video.setMediaController(mc);
For stop hiding the MediaController we can make a new Mediacontroller by extending the base class. Then we can disable the hide method by simply overriding it. For getting the actual hide functionality, we can fetch the hide() method in base class. We can hide the Mediacontroller after playback is completed using that.
Here is the code for MediaController:
public class MediaController_2 extends MediaController{
public MediaController_2(Context context) {
super(context);
}
public void hide() {
}
public void hidecontroller() {
super.hide();
}
}
Now the mediacontroller won't be hiding even after the completion of the playback. For hiding the controllers after completing playback we can use OnCompletionListener.
MediaController_2 mediaController = new MediaController_2(getActivity());
mediaPlayer.prepare();
mediaPlayer.start();
mediaController.show(0);
mediaPlayer.setOnCompletionListener(new OnCompletionListener() {
#Override
public void onCompletion(MediaPlayer mp) {
mediaController.hidecontroller();
}
});
More Succinct
First off, using an int timeout as a parameter in the show() method did nothing for me.
Secondly, this succinct piece of code forced the controls to stay on the screen after the first touch:
// Assumes you have a VideoView in your layout called 'video_preview'.
VideoView videoPreview = (VideoView) findViewById(R.id.video_preview);
MediaController mediaController = new MediaController(this) {
#Override
public void hide() {} // Prevent hiding of controls.
};
videoPreview.setMediaController(mediaController);
VideoView videoPlayer;
MediaController mediaController;
videoPlayer = view.findViewById(R.id.videoPlayer);
Uri uri = Uri.parse(URL);
videoPlayer.setVideoURI(uri);
mediaController = new MediaController(getContext()) {
#Override
public void hide() {} // on hide do nothing
};
videoPlayer.setMediaController(mediaController);
videoPlayer.requestFocus();
videoPlayer.start();

Android Show MediaController

I am adding MediaController to a VideoView, but it does not show up unless I tap the phone. The controller disappears after a while.
Is there a way I can have the MediaController show always?
Thanks
Chris
As Default mediacontroller will hide in 3 seconds of user's inactivity. you can set the timeout seconds by
new media controller().show(50000);
check this link
The below code shows MediaController always:
VideoView videoView;
MediaController mc;
videoView.setMediaController(new MediaController(this)
{
public void hide()
{
System.out.println("HIDEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEHELLLOO");
mc.show();
}
});

Categories

Resources