AndroidのMediaPlayerでのseekTo()がずれる問題 [未解決]
MediaPlayerを使って動画プレイヤーを作っていたのですが、seekTo()が上手く動いていない様子でした。
seekTo()を使うと指定した位置からずれた位置に移動してしまいます。
まだ解決はしていませんが、原因や試したことをメモしておきます。解決策をご存知ならば是非教えて下さい。
色々と調べた結果、次のような書き込みを見つけました。
Seek to Key frame – The video when encoded will usually have something called as the I frame or the Key frame, it means that this frame has lot of information and can be used to decode a frame in its entirety. To reduce the amount of space all the frames are not encoded as key frames instead they are encoded as P (Predicted) frames or predicted frames, meaning you can decode a P frame with the help from the key frame.
(http://stackoverflow.com/questions/6845161/accuracy-of-mediaplayer-seektoint-msecsより)
MediaPlayerのseekTo()では、指定した時間の近くのキーフレームにしか移動できないようです。
0.1秒ごとにseekTo()してみると、一定の間は同じ場所に飛んで、急に少し先の場所に飛ぶ、というのが繰り返されていたのですが、このためだと思われます。
そこで、seekTo()で移動した位置から実際に指定した位置まで再生して移動させようと試したのですが、これも上手くいきませんでした。
こうしたかった
mediaPlayer.seekTo(seekPosition); int diff = seekPosition - mediaPlayer.getCurrentPosition(); mediaPlayer.start(); try { Thread.sleep(diff); } catch (InterruptedException e) { e.printStackTrace(); } mediaPlayer.pause();
しかし、getCurrentPosition()からはseekPositionが返ってきてしまって失敗。
もう少し試してみて何か分かったら追記します。