I am doing an Android project based on Video view. I want to show play button before the user clicks play, when user decides to pause video - pause button shows up. Clicking on pause button should trigger playing the video again from the same place where it was paused (like YouTube video).
im1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
vv1.setVideoURI(Uri.parse("android.resource://com.example.cm.filmfestival/" + R.raw.mission));
im1.setVisibility(View.INVISIBLE);
im2.setVisibility(View.INVISIBLE);
vv1.start();
}
});
im2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
vv1.stopPlayback();
im2.setVisibility(View.VISIBLE);
im1.setVisibility(View.INVISIBLE);
}
});
@Override
public boolean onTouch(View v, MotionEvent event) {
im1.setVisibility(View.VISIBLE);
vv1.start();
im2.setVisibility(View.VISIBLE);
vv1.stopPlayback();
return true;
}
Clicking on pause button should trigger playing the video again from the same place where it was paused (like YouTube video). Show activity on this post. Show activity on this post. Set an OntouchListener on your VideoView and then in Ontouch callback check if the video is playing or paused before pausing or playing it.
Android Media Player play/pause Button. MediaPlayer mPlayer = MediaPlayer.create(MyActivity.this, R.raw.myfile); mPlayer.start(); the above is coded in the onclick of the play button. I want to pause the playback by clicking the same button again.ie) single button for play/pause.
If you want to hide play/pause in Windows media player at the bottom, that will automatically get hidden when you are running the video and leave the video ideal for few seconds. If the issue still persists, then I would suggest you to provide us the screen short in-order to understand the issue better.
Shouldn't use video.pause (), video.resume (), because when you call it, the buffering data will be lost. That is also the reason WHY VideoView play at BEGINNING whenever you call video.resume (). See it: VideoView onResume loses buffered portion of the video
Use the code below
<VideoView
android:id="@+id/video_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center" />
public VideoView myVideoView;
private int position = 0;
private MediaController mediaControls;
// set the media controller buttons
if (mediaControls == null)
{
mediaControls = new MediaController(MainActivity.this);
}
// initialize the VideoView
myVideoView = (VideoView) findViewById(R.id.video_view);
try
{
// set the media controller in the VideoView
myVideoView.setMediaController(mediaControls);
// set the uri of the video to be played
myVideoView.setVideoURI(Uri.parse("your UrI"));
} catch (Exception e)
{
Log.e("Error", e.getMessage());
e.printStackTrace();
}
myVideoView.requestFocus();
// we also set an setOnPreparedListener in order to know when the video
// file is ready for playback
myVideoView.setOnPreparedListener(new OnPreparedListener()
{
public void onPrepared(MediaPlayer mediaPlayer)
{
// if we have a position on savedInstanceState, the video
// playback should start from here
myVideoView.seekTo(position);
System.out.println("vidio is ready for playing");
if (position == 0)
{
myVideoView.start();
} else
{
// if we come from a resumed activity, video playback will
// be paused
myVideoView.pause();
}
}
});
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