Playing Audio - error: PVMFErrNotSupported (Prepare failed.: status=0x1 )

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) {

}

 

8 Comments - Average Rating:4.13

Comments:
Thanks for that. I had been struggling with this for a couple of days too. My program would play a .wav file in the emulator, but not on a real Galaxy Tab. Using the above solved the problem! Cheers - K.
Rating: 5
Date Posted: July 10th, 2011


This solution does not work for streaming from a web URL. Any other ideas?
Rating: 3
Date Posted: February 16th, 2011


i tried this bt nw i m gettin failed binder transaction error ..can someone help
Rating: 2
Date Posted: January 20th, 2011


Thanks! Your solution worked.

The other solution from the comments of "mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);" didn't work for me.
Rating: 5
Date Posted: November 23rd, 2010


Thanks. That's the second thing like this that was solved by simply using a different argument type.
Rating: 5
Date Posted: October 27th, 2010


This is really weird. I had to use the following syntax to get the player to play dcf files (OMA DRM protected music)
mp.setDataSource(new MyContext(), Uri.fromFile(file));

mp.setAudioStreamType(AudioManager.STREAM_MUSIC);

Where MyContext is an extended class of Context.

Hope this can help others.
Rating: 5
Date Posted: September 16th, 2010


I have found that I needed to set the audio stream type. See here. http://smartandroidians.blogspot.com/2010/06/live-audio-streaming-using-mediaplayer.html

Rating: 3
Date Posted: July 22nd, 2010


Thanks! I've been wrestling with this for 2 days. I' running an android app with the Processing tool. Stuck at a file not found exception, cant seem to get the path but its a processing thng. At least I know if I get the path there will be no errors now!
Rating: 5
Date Posted: June 17th, 2010



RECENT ARTICLES