在用模拟器播放音乐时,总是报一个错误: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) {
}
本文详细介绍了在使用Java模拟器播放音乐时遇到的PVMFErrNotSupportedPreparefailed错误,并提供了通过使用FileDescriptor替代直接设置文件路径来解决此问题的代码优化方案。

4097

被折叠的 条评论
为什么被折叠?



