使用Mediaplayer播放本地音频
Caused by: java.lang.IllegalStateException
at android.media.MediaPlayer._setDataSource(Native Method)
at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1033)
at android.media.MediaPlayer.setDataSource(MediaPlayer.java:916)
at android.media.MediaPlayer.setDataSource(MediaPlayer.java:882)
at com.xxun.xunaddnew.AddNewMainActivity.playMusic(AddNewMainActivity.java:190)
at com.xxun.xunaddnew.AddNewMainActivity.onActivityResult(AddNewMainActivity.java:427)
at android.app.Activity.dispatchActivityResult(Activity.java:5480)
at android.app.ActivityThread.deliverResults(ActivityThread.java:3614)
那么,使用reset()可解决mediaplayer引起的IllegalStateException问题
在mMediaPlayer.setDataSource(path);
之前加一句mMediaPlayer.reset();即可.
网友评论