android development tutorial uninstall sd card for MediaServer processing

  • 2020-05-27 07:09:05
  • OfStack

The following code is the processing code in Music in android:

MediaPlayer.OnErrorListener errorListener = new MediaPlayer.OnErrorListener() {
    public boolean onError(MediaPlayer mp, int what, int extra) {
        switch (what) {
        case MediaPlayer.MEDIA_ERROR_SERVER_DIED:
            mIsInitialized = false;
            mCurrentMediaPlayer = new CompatMediaPlayer(); 
            mCurrentMediaPlayer.setWakeMode(MediaPlaybackService.this, PowerManager.PARTIAL_WAKE_LOCK);
                 mHandler.sendMessageDelayed(mHandler.obtainMessage(SERVER_DIED), 2000);
            return true;
            Log.d("MultiPlayer", "Error: " + what + "," + extra);
        return false;

In simple terms, this means that in the case of MediaServer died, release drops the original MediaPlayer and recreates an MediaPlayer (which will be associated when MediaServer is restarted). And then you can do something based on your original state.

Related articles: