在我们的android应用程序中,我们打开位于assets/config/notification.wav中的wav文件。要打开和播放声音,我们使用下面的代码:FileNotFoundException从Android资产中打开wav文件
String soundClipPath = "config/notification.wav"
AssetFileDescriptor afd = mContext.getAssets().openFd(soundClipPath);
int soundID = mSoundPool.load(afd, 1);
这一直在没有任何问题,约一年了。突然间,这已停止工作。我们没有更新构建之间的任何依赖关系。唯一的区别是我能找到的是这个版本的工作是从去年开始的。如果我们在NetBeans本地构建apk,但是当我们使用hudson构建apk时,它不起作用。我已经试过,没有运气以下:
将在资源的wav文件/文件夹的原始
添加-0到Maven Android插件
验证文件结构和文件是存在的,工作。
我们使用上面的代码时,遇到下列堆栈跟踪:
java.io.FileNotFoundException: This file can not be opened as a file descriptor; it is probably compressed
at android.content.res.AssetManager.openAssetFd(Native Method)
at android.content.res.AssetManager.openFd(AssetManager.java:331)
...
而且试图从资源加载时以下/原始文件夹:
android.content.res.Resources$NotFoundException: File res/raw/notification.wav from drawable resource ID #0x7f040000
at android.content.res.Resources.openRawResourceFd(Resources.java:981)
at android.media.SoundPool.load(SoundPool.java:191)
...
可有人请帮助我们有这个奇怪的问题....
此致敬礼,
亨里克
2014-01-15
noned
+0
是你的文件压缩? –
+0
Android中的资产会自动压缩。 AssetManager用于根据需要打开和解压缩文件。但调用openFd就是这样做的。 –
+0
您是否尝试过类似以下内容:soundPool.load(afd.getFileDescriptor(),0,afd.getLength(),1)或afd.getFileDescriptor()。valid()? –