I have a problem with seekTo() method from MediaPlayer. It seems it doesn't work at all! I followed other threads regarding this issue and tried different workarounds but still seekTo() does nothing! Here is my code:
private MediaPlayer mMediaPlayer;
@Override
protected void onCreate(Bundle savedInstanceState) {
...
final VideoView videoView = (VideoView)findViewById(R.id.videoView);
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(videoView);
final Uri video = Uri.parse("android.resource://"+getPackageName()+"/"+R.drawable.video_myopia);
videoView.setMediaController(mediaController);
videoView.setVideoURI(video);
videoView.setOnPreparedListener(new OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
mMediaPlayer = mp;
System.out.println("CURRENT POSITION 0: " + mp.getCurrentPosition());
mp.seekTo(3000);
System.out.println("CURRENT POSITION 1: " + mp.getCurrentPosition());
mp.start();
System.out.println("CURRENT POSITION 2: " + mp.getCurrentPosition());
}
});
The System.out.println() shows the following output:
(note: I also tried to start() before seekTo() and then start() again after the seekTo() method)
so after the mp.start() line the mp.getCurrentPosition() says that it is at 3000 but the problem is that it's not! The video starts from the beginning. In each situation that I tried seek, after seekTo(ms) and start() the video starts from the beginning no matter what.
I must mention that I also used mp.setOnSeekCompleteListener() to know when the seek finishes. In this callback I tried to start() the video again, but it always starts from the beginning.
Can someone help me please? I will be grateful for any suggestion :). Thanx!
I discovered that my videos were not seekable, and that's why every time I used seekTo it made my video start from the beginning. In order to solve the problem I converted them with H.264
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