I am just trying to play a simple three-second WAV file and everything I try seems to give me some weird error. I have been going at this for about half an hour and all of the other solutions online give me more errors.
The .wav is in the /res/raw/
directory and is 1.17MB, 2822kbps and about three seconds in length.
Code:
MediaPlayer mp = new MediaPlayer();
try {
FileDescriptor fd=getApplicationContext().getResources().openRawResourceFd(R.raw.flipwav).getFileDescriptor();
mp.setAudioStreamType(AudioManager.STREAM_MUSIC);
mp.setDataSource(fd);
mp.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer player) {
player.start();
}
});
mp.prepare();
} catch (Exception e) {
e.printStackTrace();
}
I get this error:
E/MediaPlayer: error (1, -2147483648)
I/System.out: java.io.IOException: Prepare failed.: status=0x1
I have tried changing mp.prepare()
to mp.prepareAsync()
but this happens:
E/MediaPlayer: error (1, -2147483648)
Is it a problem with my code or the file itself? I have tried multiple files including an mp3 and the result is always the same. I am using a Windows 10 computer with Android Studio.