Android MediaPlayer seekTo not working

I have a problem with the seekTo () method from MediaPlayer. This doesn't seem to work! I followed other topics on this issue and tried different workarounds, but seekTo () does nothing anyway! 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 following output is displayed in System.out.println ():

  • POSITION 0: 0
  • POSITION 1: 3000
  • POSITION 2: 3000

(note: I also tried running () before seekTo (), and then running () again after seekTo ())

so after the line mp.start () mp.getCurrentPosition () says that it is 3000, but the problem is that it is not! The video starts from the beginning. In each situation that I tried to search, after seekTo (ms) and start () the video starts from the beginning no matter what.

, mp.setOnSeekCompleteListener(), , . () , .

- ? :). Thanx!

+4
1

, , , seekTo, . , H.264

+6

Source: https://habr.com/ru/post/1539550/


All Articles