Skip to content Skip to sidebar Skip to footer

Mediaplayer Error -2147483648 When Playing File On Internal Storage

I'm using the Audio Capture sample on android.com to record and play back audio on actual devices. (Motorola touch pad, and Samsung Galaxy S). When I define the audio file path as

Solution 1:

Thanks to gtkandroid:

Instead of mPlayer.setDataSource(mFile); I did this:

FileInputStream fileInputStream = new FileInputStream(mFile);
mPlayer.setDataSource(fileInputStream.getFD());         
fileInputStream.close();
mPlayer.prepare();

Solution 2:

Tim Crowley is right. Better practice is to close the stream, like this:

FileInputStream stream = new FileInputStream(path);
mediaPlayer.setDataSource(stream.getFD());
stream.close();

It is noted in the documentation of the method:

android.media.MediaPlayer.setDataSource(FileDescriptor fd)

Sets the data source (FileDescriptor) to use. It is the caller's responsibility to close the file descriptor. It is safe to do so as soon as this call returns.

Post a Comment for "Mediaplayer Error -2147483648 When Playing File On Internal Storage"