0

I have a tiny uncompress .wav file in my /res/raw directory called keyclick.wav (/res/raw/keyclick.wav).

However, I'm occasionally seeing an exception thrown which causes the activity to crash:

java.io.FileNotFoundException: This file can not be opened as a file descriptor; it is probably compressed at ...
android.content.res.AssetManager.openNonAssetFdNative(Native Method)
android.content.res.AssetManager.openNonAssetFd(AssetManager.java:427)
android.content.res.Resources.openRawResourceFd(Resources.java:857)
android.media.MediaPlayer.create(MediaPlayer.java:662)

It says "it is probably compressed" but I've double checked, it is not compressed.

This is how I instantiate the MediaPlayer:

this.clickPlayer = MediaPlayer.create(this.getActivity(), R.raw.keyclick);

I uploaded the file so you can see it directly:

http://inadaydevelopment.com/stackoverflow/keyclick.wav

The file is only 664 bytes and it's not compressed. Why is the system failing to get a file descriptor?

4

1 回答 1

1

肯尼,您是否尝试过使用这种方法播放文件:

MediaPlayer mp = new MediaPlayer();
AssetFileDescriptor afd = getResources().openRawResourceFd(R.raw.keyclick);
mp.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength());
mp.prepare();
mp.start();
于 2013-04-06T01:49:20.457 回答