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();即可

 

转载于:https://www.cnblogs.com/Sharley/p/9267423.html

你可能感兴趣的:(Caused by:java.lang.IllegalStateException at android.media.MediaPlayer._setDataSource(Native Method))