4

我已经从服务器下载了音频文件并使用

/data/data/packagename/sounds/filename.mp3

然后,如果我使用播放该音频

.MediaPlayer mp= new MediaPlayer();
            try {
                mp.setDataSource(PATH+"/"+fileName);
            } catch (IllegalArgumentException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IllegalStateException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

            mp.start();

但它显示一个错误

MediaPlayer:start called in state 2
MediaPlayer:Error(-38,0)
MediaPlayer:Error(-38,0)

有什么问题我对此进行了很多搜索,但没有解决方案请提出任何解决方案

4

1 回答 1

2

试试这个代码,

public void audioPlayer(String path, String fileName){
    //set up MediaPlayer    
    MediaPlayer mp = new MediaPlayer();

    try {
        mp.setDataSource(path+"/"+filename.mp3);
    } catch (IllegalArgumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IllegalStateException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    try {
        mp.prepare();
    } catch (IllegalStateException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    mp.start();
}
于 2012-05-28T12:54:33.407 回答