Android VideoView resume and seekTo
I am playing a Video using a VideoView in my app. On the click of a button, it records the current position of the video, and the app opens up the browser with some url. On pressing the back button, the app comes back to video app and resumes the video from where it left off.
I looked at the Android Activity lifecycle and saw that onStart() method gets called once the video activity comes to the foreground. So I am creating my layout in onStart() and playing the video by seeking to the current position.
My problem is that when the video resumes, it buffers from the start and then seeks to. Since it already buffered the first time, is there a way to eliminate buffering again while doing a seekTo?
Thanks Chris
I am having a similar problem. I have an OnPreparedListener that does the seekTo prior to the start. The seekTo works except that there is an audio glitch that is coming from the very beginning of the video, as if it is starting to play and then seeking. I don't know if my code would help the buffering problem described but it may help illuminate it.
mVideoView.setVisibility(View.VISIBLE);
//get current window information, and set format, set it up differently, if you need some special effects
getWindow().setFormat(PixelFormat.TRANSLUCENT);
//mVideoView.setVideoURI(Uri.parse(path));
mVideoView.setVideoPath(path);
//get focus, before playing the video.
mVideoView.requestFocus();
mVideoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
mVideoView.seekTo(mImageSeek);
mVideoView.start();
}
});
Define your Resource videoview then use this code
videoview = (VideoView) findViewById(R.id.videoview_play);
videoview.setVideoPath(dir + videoName);
//get focus, before playing the video.
videoview.setMediaController(new MediaController(this));
videoview.requestFocus();
videoview.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
public void onPrepared(MediaPlayer mp){
videoview.seekTo(5000);
videoview.start();
}
});
you have to add .setMediaController(new MediaController(this));
and
videoview.requestFocus();
before using the PrepareListener
hope it will help you
链接地址: http://www.djcxy.com/p/46484.html