首页 > 系统 > Android > 正文

android开发教程之卸载sd卡对MediaServer的处理

2020-04-11 11:54:37
字体:
来源:转载
供稿:网友

下面这段代码是android中Music中的处理代码:

复制代码 代码如下:

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.release();
            mCurrentMediaPlayer = new CompatMediaPlayer();
            mCurrentMediaPlayer.setWakeMode(MediaPlaybackService.this, PowerManager.PARTIAL_WAKE_LOCK);
                 mHandler.sendMessageDelayed(mHandler.obtainMessage(SERVER_DIED), 2000);
            return true;
        default:
            Log.d("MultiPlayer", "Error: " + what + "," + extra);
            break;
        }
        return false;
   }
};

简单来看,就是遇到MediaServer died这种情况,就release掉原来的MediaPlayer,然后重新创建一个MediaPlayer(会在MediaServer重新启动后关联起来)。然后可以根据原来的状态做相应的动作。

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表