Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't MediaPlayer.seekTo(t) go to the exact specified instant "t"?

I'm trying to get the media player to play a specific range in a locally stored video. It doesn't seem to start at the specified time I tell it to.

Example: when I seek to 1000, it works. But when I seek to 1500, it goes to 2000 instead.

I also tried pausing seeking then starting on seek completion, it doesn't make any difference.

This is the code:

mediaPlayer.start();
mediaPlayer.seekTo(time);

Is this normal? Or am I using the media player the wrong way?

like image 836
mghareeb Avatar asked Oct 21 '22 02:10

mghareeb


1 Answers

This is an encoding issue. Videos have keyframes (i-frames) that store more information than other frames. A non keyframe can be built only given the previous keyframe. Trying to display a non keyframe will show green spots and pixelated jittery screen.

Now, on some android devices there's no workaround implemented for this so you get this weird behavior. On a Nexus S for example seekTo() doesn't necessarily go to the specified frame. I tried other devices with the same android version and they seek just fine.

like image 168
mghareeb Avatar answered Oct 29 '22 18:10

mghareeb