- Java code
...... mMediaPlayer = new MediaPlayer(); initialMediaPlayerData(); ......private void initialMediaPlayerData() { Log.e(TAG, "initialMediaPlayerData"); try { Log.d(MYTAG,"mMediaPlayer prepare !"); mMediaPlayer.setDataSource(parentContext, mSelectedUri); mMediaPlayer.setOnCompletionListener(listener); mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); mMediaPlayer.prepare(); } catch (IOException e) { Log.e("MusicPicker", "Unable to play track", e); } }
以上的代码在我的一个APK中,现在发现一个奇怪的问题:
在AP第一次运行的时候,一切正常。
按back建关闭AP以后,再次启动AP的时候,运行到mMediaPlayer.prepare()函数的时候,发生IllegalStateException异常,求解释~
------解决方案--------------------
mMediaPlayer并没有关闭。。。。。
------解决方案--------------------
When a MediaPlayer object is just created using new or after reset() is called, it is in the Idle state; and after release() is called, it is in the End state. Between these two states is the life cycle of the MediaPlayer object.