VideoView and MediaPlayer seekTo always starts from beginning

Related searches

I have some problem with seeking video played in VideoView and resuming it.

Here's some part of my code:

videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
    @Override
    public void onPrepared(MediaPlayer mp) {
        mp.start();
        mp.setOnSeekCompleteListener(new MediaPlayer.OnSeekCompleteListener() {
            @Override
            public void onSeekComplete(MediaPlayer mp) {
                Log.d("V", "onSeekComplete1 " + videoView.getCurrentPosition());
                videoView.start();
                Log.d("V", "onSeekComplete1 " + videoView.getCurrentPosition());
            }
        });
    }
});
videoView.setVideoURI('some local uri');

At some point I'm pausing video using: videoView.pause();

After button click I'm seeking video to certain time, eg. 10 seconds (10 000 ms).

@OnClick(R2.id.ivMove)
void clickMove() {
   videoView.seekTo(10000);
}

After that in log I see:

onSeekComplete1 10000
onSeekComplete2 0

So after calling videoView.start() it is starting video from beginning!

But when I call start() without seeking video (eg. one button calls pause() and second calls start() then video is playing correctly - from the moment when it was paused, not from beginning.

Could you tell me what I'm doing wrong?

The problem was caused by MediaPlayer - it is seeking to closest keyframe of the video and it turns out that my testing video has keyframes every ~30 seconds.

I changed to ExoPlayer https://github.com/google/ExoPlayer - it can seek to exact time.

Playback position regularly moves back to pre-last position after , VideoView and MediaPlayer seekTo always starts from beginning - android. But when I call start() without seeking video (eg. one button calls pause() and� Some times it start from the beginning. There are two methods to resolve above problem. 1. Make Video Start After SeekTo Method Complete. This is one reason for the issue. The VidewView widget start to play video file while seekto method do not finish. You can add a MediaPlayer.OnPreparedListener to the VideoView object.

There is a new overload for the MediaPlayer seekTo method. It has a second int parameter, in which you can pass a SEEK_CLOSEST constant. According to Google, "This mode is used with seekTo(long, int) to move media position to a frame (not necessarily a key frame) associated with a data source that is located closest to or at the given time." In testing my own app, it solves the problem for API level >= 26. I'm not sure if there are any good options prior to API level 26.

How to Resume video after SeekTo() method in VideoView , did you seek while playing or seek to the position and actually start playing (that is: not in a For the second file I switched to the media player after starting to log. Playback position not always being remembered #2065. I have a VideoView and when I pause video, then leave the page and come back - I need to resume video from last position. But I have a problem - after SeekTo() method video starts from beginning. I tried to put SeekTo() in SetSource to AutoPlay but nothing is changed((Here is my VideoPlayerRender:

Try videoView.resume() instead of start()

videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
    @Override
    public void onPrepared(MediaPlayer mp) {
        mp.start();
        mp.setOnSeekCompleteListener(new MediaPlayer.OnSeekCompleteListener() {
            @Override
            public void onSeekComplete(MediaPlayer mp) {
                Log.d("V", "onSeekComplete1 " + videoView.getCurrentPosition());
                videoView.resume();
                Log.d("V", "onSeekComplete1 " + videoView.getCurrentPosition());
            }
        });
    }
});
videoView.setVideoURI('some local uri');

MediaPlayer, I have a VideoView and when I pause video, then leave the page and come back - I need to But I have a problem - after SeekTo() method video starts from beginning. Duration); var mediaPlayer = sender as MediaPlayer; var startTime = new TimeSpan(0, 0, 0); if Video starts from beginning always((. Use VideoView.start() to start the video playback, once the video is available for playing. Use VideoView.stopPlayback() to stop the video playback and release the resources the VideoView is using.

Try this solution. It works like charm....

   videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
        @Override
        public void onPrepared(MediaPlayer mp) {
            mp.start();
            mp.setOnSeekCompleteListener(new MediaPlayer.OnSeekCompleteListener() {
                @Override
                public void onSeekComplete(MediaPlayer mp) {
                    mp.start();
                }
            });

        }
    });

An example on how to use the methods in this class can be found in VideoView . Calling start() to resume playback for a paused MediaPlayer object, and the The playback position can be adjusted with a call to seekTo(long, int) . To help users get current playback position, this method always� Windows7 Home Prem 32BIT\Windows Media Player 12. When playing back a DVD Movie, Media Player opens, seek feature works. Playing the Movie a 2nd time, the Seek Feature will not work, it Re-starts the movie from the beginning.

VideoView . Calling start() to resume playback for a paused MediaPlayer object, The playback position can be adjusted with a call to seekTo(long,int) . To help users get current playback position, this method always� VideoView is a custommized component which is available of Android, it is the combination of MediaPlayer and SuffaceView which help you to play a video more easily.

Create a network proxy in your app which stands between the VideoView and the web server. You point your proxy to the web server and the VideoView to the proxy. The proxy starts downloading the data, saves it continuously for later use and passes it to the listening MediaPlayer (which was started by the VideoView).

A media player which plays MediaItems. The details on playback control and player states can be found in the documentation of the base class, SessionPlayer. Topic covered here: Audio focus and noisy intent. Audio focus and noisy intent. By default, MediaPlayer handles audio focus and noisy intent with AudioAttributesCompat set to this

Comments
  • the same situation with resume() as with start()... :( When I call start() without seeking video (eg. one button calls pause() and second calls start() then video is playing correctly - from the moment when it was paused, not from beginning.