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

 

posted @ 2018-07-05 11:28  Sharley  阅读(2435)  评论(0编辑  收藏  举报