标签:
容易ANR的:reset release setDataSource prepare(所以要用prepareAsync,但是要设置prepared监听,准备完才能播放start)
media server died错误,需要实现接口 onErrorListener(on Error())。在what == MediaPlayer.MEDIA_ERROR_SERVER_DIED 时,重新reset,release,置null,然后 new MediaPlayer(), 再从setDataSource开始流程
@Override public boolean onError(MediaPlayer mp, int what, int extra) { if(what == MediaPlayer.MEDIA_ERROR_SERVER_DIED){ Log.d("VideoPlayer", "MEDIA_ERROR_SERVER_DIED"); try{ reInitVideoPlayer(); }catch(Exception e){ }finally{ playVideo(mLoadingImage); } } return false; }
reset()在重置MediaPlayer的时候用,重置完,播放下一首,重新setDataResource prepare start。
release()不是每首歌之后都release,而是最后不用MediaPlayer了。比如在onPause或者 onDestroy里边调用。
标签:
原文地址:http://www.cnblogs.com/maxiaodoubao/p/4651683.html