I have a video view which uses media controller. I want to hide the media controller somehow without doing video_view.setMediaController(null);
If I do that then the following code won't work:
this.setVolumeControlStream(AudioManager.STREAM_MUSIC);
So I want to hide the media controller permanently while the video is playing but still be able to turn the volume up and down. How can I do that
This might help if to remove permanently controller...
VideoView videoHolder = new VideoView(contex);
MediaController controller=new MediaController(this);
videoHolder.setMediaController(controller);
then apply this statement to hide permanently your controller...
controller.setVisibility(View.GONE);
just call this to show it again...
controller.setVisibility(View.VISIBLE);
Try this.
MediaController mediaController = new MediaController(this);
apply on touch listener on your video view.
in that place this code.
if(mediaController.isShowing ()){
mediaController.hide();
}
here is the link for more info.
Related
I am trying to play two video views using the same media controller but it seems impossible to play them and stop them and seek through both at the same time
can someone suggest a solution here is what I am trying :
//2 video views
videoview=(VideoView)findviewbyid(R.id.videowview);
videoviewtwo=(VideoView)findviewbyid(R.id.videowview2);
//the media controller
MediaController mc =new MediaController(this);
//setting uri for both:
videoview.setVideoURI(uri);
videoviewtwo.setVideoURI(uri1);
//setting same media controller object for both
videoview.setMediaController(mc);
videoviewtwo.setMediaController(mc);
//finally start both
videoview.Start();
videoviewtwo.Start();
after this both play well at the first time but when I try to repeat only one starts the other doesnt, thank you for your help.
Edit: I want them both to play at the same time each time I repeat the process .
You need to release and set the mediaplayer to null before you can start the new video. Try to call this when the video has stopped and before you start a new video so you know that the mediaplayer is not busy.
private void releaseMediaPlayer() {
mMediaPlayer.release();
mMediaPlayer = null;
}
So next is to find out when the mediaplayer have stopped playing your video. A hint: MediaPlayer.OnCompletionListener
I am using "android.widget.MediaController" for VideoView. Not sure when to use "android.media.session.MediaController" and what the difference is between them. Any idea?
MediaController mediaController = new MediaController(this);
videoView.setMediaController(mediaController);
videoView.start();
The documentation explains the difference very well. One is a view that offers controls for a media player; the other is an object fo interacting with an ongoing media session.
Description of android.widget.MediaController:
A view containing controls for a MediaPlayer. Typically contains the buttons like "Play/Pause", "Rewind", "Fast Forward" and a progress slider. It takes care of synchronizing the controls with the state of the MediaPlayer.
Description of android.media.session.MediaController:
Allows an app to interact with an ongoing media session. Media buttons and other commands can be sent to the session. A callback may be registered to receive updates from the session, such as metadata and play state changes.
I am working with streaming video and I want to change from one source to another dinamically.
First I set the video uri to the VideoView
view.setVideoURI(myUri);
And I know that I am capable of changing it afterwards by doing (this is in onPrepare method but it could go somewhere else where I have access to the MediaPlayer).
#Override
public void onPrepared(MediaPlayer mp)
{
Uri newUri = getOtherUri();
mp.reset();
mp.setDataSource(getApplicationContext(), newUri);
mp.prepare();
mp.start();
}
The thing is, I want to change the source without reseting the mediaPlayer (I do not want to disturb the user).
I tried to create a new VideoView with the new Uri and then change one object for the other, and likewise with the media player. However, none of that seems to work.
Is it possible to replace a video while it is playing in Android?
Any comments would be appreciated.
There is no option to reset the video without using mediaplayer.stopPlayback() or mediaplayer.reset. The reason is that; the previous object of the mediaplayer has to be released before you can play other video .
I want to change the source without reseting the mediaPlayer (I do not want to disturb the user).
Well, this cannot be achieved as the mediaplayer has to be reset. So there will be lag while changing videos. And to satisfy you, you can see these behavior in any videoplayer app like youtube or mxplayer.
So the only thing you can do is to show progressbar while loading or changing video.
Hope it helps. Cheeers.:)
I'm using VideoPlayer in my app. It play everything fine but when I want to scroll on the media player's bar, usually it gives me the error : Sorry, this video cannot be played. and I have to restart the video to watch it again. All I found is if I stop the video and scroll the bar it will be fine. I just wonder how can I fix this problem ? how can I access to media player's bar. Hens I can pause the video onClick. My code:
MediaController mediaController = new MediaController(
rootView.getContext());
mediaController.setAnchorView(video);
Uri uri = Uri.parse(passVideo.file_link);
video.setMediaController(mediaController);
video.setVideoURI(uri);
video.setOnPreparedListener(new OnPreparedListener() {
public void onPrepared(MediaPlayer arg0) {
mProgress.setVisibility(View.INVISIBLE);
video.requestFocus();
video.start();
}
});
Many people get this error like you,
Bugs :
Sorry this video is not valid for streaming to this device.
Sorry, this video can not be played.
You can find out at Sorry, this video is not valid for streaming to this device in Http streaming android
Thanks,
I use below call to play music:
vv = (VideoView)findViewById(R.id.screen_audio);
Uri music = Uri.parse(path);
vv.setVideoURI(music);
vv.start();
But when I playing, the volumn_up and volumn_down button can not press.
How can modify it to change the media volumn?
You have to use controls to change the volume. Check below example to know about it.
Implement a SeekBar to control the volume of Video Player