今天做android的一个音乐播放器时,当播放列表里的歌曲时,总是报一个错误: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中有一个[color=red]FileDescriptor[/color];我们可以通过[color=red]getFD()[/color]方法得到一个FileDescriptor;以避免这些错误;
代码修改后如下:
String audioFilePath = getFilesDir().getAbsolutePath() + File.separator + "aa.mp4";
try {
File file = new File(audioFilePath);
FileInputStream fis = new FileInputStream(file);
[color=red]mediaPlayer.setDataSource(fis.getFD());[/color]
mediaPlayer.prepare();
mediaPlayer.start();
} catch(FileNotFoundException e){
} catch (IllegalArgumentException e) {
} catch (IllegalStateException e) {
} catch (IOException e) {
}
经过测试通过;
Prepare failed.: status=0x1
检查了半天也没看出是哪里的错误;后来经过查阅资料发现里面有一段代码:
try{
mp = new MediaPlayer();
mp.setDataSource(somePathToAudioFile);
mp.prepare();
mp.start();
}catch(Exception e){
}
里面mp.setDataSource(somePathToAudioFile);这个方法中调用的是setDataSource(String);在Java中有一个[color=red]FileDescriptor[/color];我们可以通过[color=red]getFD()[/color]方法得到一个FileDescriptor;以避免这些错误;
代码修改后如下:
String audioFilePath = getFilesDir().getAbsolutePath() + File.separator + "aa.mp4";
try {
File file = new File(audioFilePath);
FileInputStream fis = new FileInputStream(file);
[color=red]mediaPlayer.setDataSource(fis.getFD());[/color]
mediaPlayer.prepare();
mediaPlayer.start();
} catch(FileNotFoundException e){
} catch (IllegalArgumentException e) {
} catch (IllegalStateException e) {
} catch (IOException e) {
}
经过测试通过;