Caused by:java.lang.IllegalStateException at android.media.MediaPlayer._setDataSource(Native Method)

农村四月闲人少,勤学苦攻把名扬。这篇文章主要讲述Caused by:java.lang.IllegalStateException at android.media.MediaPlayer._setDataSource(Native Method)相关的知识,希望能为你提供帮助。
使用Mediaplayer播放本地音频,在第二次调用mediaplayer.setDataSource()时报错如下:

Caused by: java.lang.IllegalStateException at android.media.MediaPlayer._setDataSource(Native Method) at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1383) at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1367) at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1302) at android.media.MediaPlayer.setDataSource(MediaPlayer.java:1240) at android.media.MediaPlayer.setDataSource(MediaPlayer.java:986) at android.media.MediaPlayer.setDataSource(MediaPlayer.java:951) ...

那么,使用reset()可解决mediaplayer引起的吃饭不香IllegalStateException问题
在mMediaPlayer.setDataSource(path); 之前加一句mMediaPlayer.reset(); 即可
【Caused by:java.lang.IllegalStateException at android.media.MediaPlayer._setDataSource(Native Method)】 

    推荐阅读