Playing Audio - error: PVMFErrNotSupported (Prepare failed.: status=0x1 )
This article is from the original REM DEV blog (2008–2010). Some of the technologies it covers (Flex, Flash, AIR, JavaFX 1.x) have since been retired.
When it comes to playing sound files in android, I've found plenty of code samples that look something like this...
try{
mp = new MediaPlayer();
mp.setDataSource(somePathToAudioFile);
mp.prepare();
mp.start();
}catch(Exception e){
}
But when I tried these samples I kept getting these errors...
PVMFErrNotSupported
Prepare failed.: status=0x1
I found that instead of passing a string into mp.setDataSource(string), I could pass in a FileDescriptor to avoid these errors. Here's a sample that worked for me (it's a few more lines of code, because you have to create a File object and a FileInputStream object in order to get the FileDescriptor object):
if(mediaPlayer != null){
mediaPlayer.release();
}
mediaPlayer = new MediaPlayer();
//in this case my sound file is in the application directory...
String audioFilePath = getFilesDir().getAbsolutePath() + File.separator + "test.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) {
}