Android error MediaPlayer usage of media Player called in state *

Source: Internet
Author: User

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 *

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.