android开发教程之卸载sd卡对MediaServer的处理
程序员文章站
2022-06-19 20:05:50
下面这段代码是android中music中的处理代码:
复制代码 代码如下:mediaplayer.onerrorlistener errorlistener = new...
下面这段代码是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重新启动后关联起来)。然后可以根据原来的状态做相应的动作。