With media Player, there are a few questions, remember
Usage is not said, when using the best reference to the MediaPlayer of this picture
The first error is media Player called in State 8
This is because there was no prepare before calling start, because I used the
MediaPlayer = mediaplayer.create (context, r.raw.notice);
To initialize the player, this interface illustrates
As long as a successful return to the player does not need to go to prepare, but I call stop and start many times later, resulting in the above error,
It can also be seen on the control chart that if you use stop when you pause, you must re-prepare before start or error media Player called in State 8
If pause is paused, the direct start can be used without prepare.
The second error is media Player called in State 0
This error is due to
public void Play () {try {mediaplayer.prepare ();} catch (IllegalStateException e) {e.printstacktrace ();}Mediaplayer.start ();
}
Change it to the following.
public void Play () {try {mediaplayer.setonpreparedlistener (preparedlistener); Mediaplayer.prepareasync ();} catch ( IllegalStateException e) {//TODO auto-generated catch Blocke.printstacktrace ();}} Onpreparedlistener Preparedlistener = new Onpreparedlistener () {@Overridepublic void onprepared (MediaPlayer MP) { Mediaplayer.start ();}};
A look to understand, just at the beginning I finished prepare went directly to start, but this time may prepare has not succeeded, so reported the above error.
jason0539
Weibo: http://weibo.com/2553717707
Blog: http://blog.csdn.net/jason0539 (reprint please indicate the source)
Android error MediaPlayer usage of media Player called in state *