在播放音樂時報PVMFErrNotSupported Prepare failed的解決方法

在用模擬器播放音樂時,總是報一個錯誤:PVMFErrNotSupported Prepare failed.: status=0x1

錯誤在這段代碼裏:

try{

    mp = new MediaPlayer();

    mp.setDataSource(somePathToAudioFile);

    mp.prepare();

    mp.start();

}catch(Exception e){
}


裏面mp.setDataSource(somePathToAudioFile);這個方法中調用的是setDataSource(String);在Java中有一個FileDescriptor;我們可以通過getFD()方法得到一個FileDescriptor;以避免這些錯誤;

代碼修改後如下:
String audioFilePath = getFilesDir().getAbsolutePath() + File.separator + "aa.mp4";
       
try {
   

    File file = new File(audioFilePath);
    FileInputStream fis = new FileInputStream(file);
    mediaPlayer.setDataSource(fis.getFD());
    mediaPlayer.prepare();
    mediaPlayer.start();


} catch(FileNotFoundException e){

} catch (IllegalArgumentException e) {

} catch (IllegalStateException e) {

} catch (IOException e) {

}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章