Android: MediaPlayer getCurrentPosition() gets stuck

I am updating a SeekBar according to the MediaPlayer. From time to time it stops to update the progress, it gets stuck, I am getting the same values. (The sound however goes on without stucking.) These are my logcat messages, I print out the progress, you can see it goes well until 2048, then it stops and after a while it continues to update. Why is that? (I noticed that since android 4.0, there is no such problem on my other phone with android 2.2)

01-28 16:41:21.446: D/MyMediaPlayer(10342): progress:  56 / 10472
01-28 16:41:21.501: D/MyMediaPlayer(10342): progress:  107 / 10472
01-28 16:41:21.556: D/MyMediaPlayer(10342): progress:  158 / 10472
01-28 16:41:21.610: D/MyMediaPlayer(10342): progress:  209 / 10472
01-28 16:41:21.657: D/MyMediaPlayer(10342): progress:  261 / 10472
01-28 16:41:21.704: D/MyMediaPlayer(10342): progress:  311 / 10472
01-28 16:41:21.759: D/MyMediaPlayer(10342): progress:  362 / 10472
01-28 16:41:21.806: D/MyMediaPlayer(10342): progress:  413 / 10472
01-28 16:41:21.837: D/dalvikvm(307): GC_CONCURRENT freed 1835K, 16% free 19932K/23495K, paused 3ms+12ms, total 101ms
01-28 16:41:21.860: D/MyMediaPlayer(10342): progress:  458 / 10472
01-28 16:41:21.907: D/MyMediaPlayer(10342): progress:  514 / 10472
01-28 16:41:21.962: D/MyMediaPlayer(10342): progress:  565 / 10472
01-28 16:41:22.009: D/MyMediaPlayer(10342): progress:  616 / 10472
01-28 16:41:22.063: D/MyMediaPlayer(10342): progress:  667 / 10472
01-28 16:41:22.118: D/MyMediaPlayer(10342): progress:  718 / 10472
01-28 16:41:22.165: D/MyMediaPlayer(10342): progress:  770 / 10472
01-28 16:41:22.212: D/MyMediaPlayer(10342): progress:  820 / 10472
01-28 16:41:22.267: D/MyMediaPlayer(10342): progress:  2048 / 10472
01-28 16:41:22.313: D/MyMediaPlayer(10342): progress:  2048 / 10472
01-28 16:41:22.368: D/MyMediaPlayer(10342): progress:  2048 / 10472
01-28 16:41:22.415: D/MyMediaPlayer(10342): progress:  2048 / 10472
01-28 16:41:22.470: D/MyMediaPlayer(10342): progress:  2048 / 10472
01-28 16:41:22.524: D/MyMediaPlayer(10342): progress:  2048 / 10472
01-28 16:41:22.571: D/MyMediaPlayer(10342): progress:  2048 / 10472
01-28 16:41:22.626: D/MyMediaPlayer(10342): progress:  2048 / 10472
01-28 16:41:22.673: D/MyMediaPlayer(10342): progress:  2048 / 10472
01-28 16:41:22.727: D/MyMediaPlayer(10342): progress:  2048 / 10472
01-28 16:41:22.774: D/MyMediaPlayer(10342): progress:  2048 / 10472
01-28 16:41:22.829: D/MyMediaPlayer(10342): progress:  2048 / 10472
01-28 16:41:22.884: D/MyMediaPlayer(10342): progress:  2048 / 10472
01-28 16:41:22.931: D/MyMediaPlayer(10342): progress:  2048 / 10472
01-28 16:41:22.985: D/MyMediaPlayer(10342): progress:  2048 / 10472
01-28 16:41:23.032: D/MyMediaPlayer(10342): progress:  2048 / 10472
01-28 16:41:23.087: D/MyMediaPlayer(10342): progress:  2048 / 10472
01-28 16:41:23.142: D/MyMediaPlayer(10342): progress:  2048 / 10472
01-28 16:41:23.188: D/MyMediaPlayer(10342): progress:  2048 / 10472
01-28 16:41:23.243: D/MyMediaPlayer(10342): progress:  2048 / 10472
01-28 16:41:23.290: D/MyMediaPlayer(10342): progress:  2048 / 10472
01-28 16:41:23.345: D/MyMediaPlayer(10342): progress:  2048 / 10472
01-28 16:41:23.392: D/MyMediaPlayer(10342): progress:  2048 / 10472
01-28 16:41:23.454: D/MyMediaPlayer(10342): progress:  2054 / 10472
01-28 16:41:23.501: D/MyMediaPlayer(10342): progress:  2105 / 10472
01-28 16:41:23.556: D/MyMediaPlayer(10342): progress:  2155 / 10472
01-28 16:41:23.602: D/MyMediaPlayer(10342): progress:  2207 / 10472
01-28 16:41:23.657: D/MyMediaPlayer(10342): progress:  2258 / 10472
01-28 16:41:23.712: D/MyMediaPlayer(10342): progress:  2309 / 10472
01-28 16:41:23.751: D/MyMediaPlayer(10342): progress:  2360 / 10472
01-28 16:41:23.813: D/MyMediaPlayer(10342): progress:  2411 / 10472

I once noticed a similar issue with getCurrentPosition() not returning the correct value.

See Here: VideoView getCurrentPosition() irregularity on Acer Iconia A200

I never found what was causing it to return the incorrect position. However the workaround that I employed was simply to keep track of the time myself by storing the timestamp that I start the video and refering to that timestamp to determine how long the video has been playing. Seems redundant but this at least gives me the correct value when the built in method does not.

链接地址: http://www.djcxy.com/p/88594.html

上一篇: Mediabar进度更新seekbar不顺利?

下一篇: Android:MediaPlayer getCurrentPosition()陷入困境