I have an android code for playing a video using videoview and control buttons such as pause,rewind and forward using mediacontroller. It works on nexus S as well as many samsung phones, but the mediacontroller buttons dont seem to work on nexus 7! I need it to work on all devices. Is there something extra that i need to do?
MediaController mediacontroller = new MediaController(Activity.this);
mediacontroller.setAnchorView(videoview);
Uri video = Uri.parse("path/to/video");
videoview.setMediaController(mediacontroller);
videoview.setVideoURI(video);
videoview.start();
Just stumbled upon this answer in Unable to pause/forward/backward video using mediacontroller in android. Some LG devices seem to have this issue as well.
As mentioned by @Vineela Yarlagadda, you need to override the VideoView methods below
@Override
public boolean canSeekForward() {
    return true;
}
@Override
public boolean canSeekBackward() {
    return true;
}
@Override
public boolean canPause() {
    return true;
}
Tested & works on Nexus 7.
Alternate solution: Use a SurfaceView instead of a VideoView as suggested in the sample code in ApiDemos.
 setContentView(R.layout.media_player2);
 mSurface = (SurfaceView) findViewById(R.id.surface);
 holder = mSurface.getHolder();
 holder.addCallback(this);
 mMediaPlayer = new MediaPlayer();
 mMediaPlayer.setDataSource(stream);
 mMediaPlayer.setDisplay(holder);
 mMediaPlayer.prepareAsync();
 mController = new MediaController(this);
 mMediaPlayer.setOnBufferingUpdateListener(this);
 mMediaPlayer.setOnCompletionListener(this);
 mMediaPlayer.setOnPreparedListener(this);
 mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
 mController.setMediaPlayer(this);
 mController.setAnchorView(mSurface);
I opened the bug code.google.com/p/android/issues/detail?id=59776 after encountering the same issue as @kriswiz when I used VideoView and Player. The video will play on a Nexus 7 and on Samsung Nexus now.
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