MediaPlayer isPlaying() always returning false

后端 未结 2 1293
不思量自难忘°
不思量自难忘° 2021-01-14 15:30

I am testing on 2 phones. In one device isPlaying() of mediaplayer always return false even when it is playing. but in other device (lg optimus gingerbread) isPlaying() retu

相关标签:
2条回答
  • 2021-01-14 16:09

    Also, while we're on the general MediaPlayer subject, note that isPlaying() can cause an ANR when called on the UI thread. In fact, Google recommends executing all MediaPlayer calls from a background handler thread. Which will also serialize execution of MediaPlayer calls.

    0 讨论(0)
  • 2021-01-14 16:17

    MediaPlayer is very odd and very fragile. You have very little you can do to tell what state it is in--and anything you do know could end up wrong.

    As a side note, I have discovered that sometimes Eclipse can make apps do VERY strange, inexplicable things. Cleaning the project and restarting Eclipse and uninstalling and reinstalling the app usually takes care of those really wonky things, so always try that when you find an error that seems impossible.

    When working with MediaPlayer, track for yourself what it should be doing, and then never, ever trust that MediaPlayer will be in the same state where you left it. Anytime you do anything with the MediaPlayer, be prepared for that lovely IllegalStateException--maybe it was playing, maybe it was prepared, maybe it was paused, but you should be prepared that, at any point, it may be in the wrong state. When you write your code this way, you are less reliant on isPlaying() being accurate.

    Not helpful I know, but unfortunately we don't have much in the way of alternatives to MediaPlayer.

    0 讨论(0)
提交回复
热议问题