首页 > android MediaPlayer 报错start called in state 1是怎么回事?

android MediaPlayer 报错start called in state 1是怎么回事?

mediaPlayer报错start called in state 1 error(-38,0)是怎么回事
我调用start()之前有prepare();
在onCreate里已经使用了initMediaPlayer()

private void initMediaPlayer() {

    try {
        File file = new File(Environment.getExternalStorageDirectory(),"music.mp3");
        mediaPlayer.setDataSource(file.getPath());
        mediaPlayer.prepare();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

@Override
public void onClick(View v) {
    switch (v.getId()){
        case R.id.play:
            if (!mediaPlayer.isPlaying())
                mediaPlayer.start();
            break;
        case R.id.pause:
            if (mediaPlayer.isPlaying())
                mediaPlayer.pause();
            break;
        case R.id.stop:
            if (mediaPlayer.isPlaying()){
                mediaPlayer.reset();
                initMediaPlayer();
            }
    }

}

你有没有加 读取存储卡的权限?
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

【热门文章】
【热门文章】