MediaPlayer.seekTo () does not want to position on Android

I am working on an application in which the video pauses at three different intervals. After the second pause, if the button is pressed, it should start from the previous place.

Eg. if it is currently paused at 1:30, and then by pressing a single button, it goes to the previous bookmark, i.e. 00:45.

I thought using MediaPlayer.seekTo () would help me with this. But seekTo () is not looking for a position at all. CurrentPosition remains unchanged even after calling seekTo ();

Here is my code.

mediaPlayer.setOnSeekCompleteListener(new OnSeekCompleteListener() { @Override public void onSeekComplete(MediaPlayer mp) { Log.d("VID_PLAYER","Seek Complete. Current Position: " + mp.getCurrentPosition()); mp.start(); } }); 

and somewhere below, I have this ...

mediaPlayer.seekTo(45000);

What is the problem? Why not seekTo (); working? Any help would be appreciated.

I am currently testing it on Android v4.0.3 (ICS)

+6
source share
2 answers

One of the reasons Android cannot run seekTo is because of the weird video encoding. For example, in MP4 format, so-called “search points” (that is, a search index) can be indicated at the beginning and end of a file. If they are indicated at the beginning of the file, then seekTo will behave correctly. But if they are indicated at the end of the file, then seekTo will do nothing, and the video will start from the beginning after seekTo .

This is confirmed by a bug or feature in Android 4.4.2.

PS In Youtube, all videos are encoded using "search points" at the beginning of the file. Therefore, if you have this problem with seekTo in your application, first of all, check your application with some video files from Youtube. You may need to transcode your videos ...

+2
source

Your problem has something in common with this error: https://code.google.com/p/android/issues/detail?id=4124

I recall this about a year ago. I do not think that at that time I found a workaround.

+1
source

All Articles