Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/326.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从android资产打开wav文件时FileNotFoundException_Android_Filenotfoundexception_Android Assets_Android Maven Plugin - Fatal编程技术网

从android资产打开wav文件时FileNotFoundException

从android资产打开wav文件时FileNotFoundException,android,filenotfoundexception,android-assets,android-maven-plugin,Android,Filenotfoundexception,Android Assets,Android Maven Plugin,在我们的android应用程序中,我们打开位于assets/config/notification.wav中的wav文件。要打开并播放声音,我们使用以下代码: String soundClipPath = "config/notification.wav" AssetFileDescriptor afd = mContext.getAssets().openFd(soundClipPath); int soundID = mSoundPool.load(afd, 1); 这项工作已经进行了大约

在我们的android应用程序中,我们打开位于assets/config/notification.wav中的wav文件。要打开并播放声音,我们使用以下代码:

String soundClipPath = "config/notification.wav"
AssetFileDescriptor afd = mContext.getAssets().openFd(soundClipPath);
int soundID = mSoundPool.load(afd, 1);
这项工作已经进行了大约一年,没有任何问题。突然间,这一切都停止了。我们没有更新构建之间的任何依赖关系。我能发现的唯一区别是构建工作与去年不同。如果我们在netbeans中本地构建apk,它就可以工作,但是当我们使用hudson构建apk时,它就不工作了。我尝试了以下方法,但没有成功:

  • 将wav文件放在res/raw文件夹中
  • 将-0添加到maven android插件
  • 已验证文件结构,并且文件已存在且正在运行
使用上述代码时,我们得到以下stacktrace:

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)
...
尝试从res/raw文件夹加载时,请执行以下操作:

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)
...
有人能帮我们解决这个奇怪的问题吗

致以最良好的祝愿


Henrik

从原始资源文件夹播放,我建议您需要以下内容:

MediaPlayer mPlayer = MediaPlayer.create(PlayWorld.this, R.raw.notification);
然后你和MediaPlayer一起玩。
在您发布的第二个例外中,我看到了一些奇怪的东西:“文件res/raw/notification.wav fromdrawableresource ID”

让我猜猜,您是否使用
maven jarsigner plugin
进行应用程序签名?这个没有指定版本吗? 大约四周前,
maven jarsigner插件
更新为1.3版,现在我在应用程序上签名时,它对我的应用程序产生了一些奇怪的影响——在应用程序启动时签名后,我遇到了类似于你的异常。 我只需在
pom.xml
中的
maven-jarsigner-plugin
之后添加
1.2
就解决了这个问题


我希望它也能帮助您。

您的文件压缩了吗?Android中的资产会自动压缩。AssetManager用于根据需要打开和解压缩文件。但调用openFd恰恰可以做到这一点。您是否尝试过以下操作:soundPool.load(afd.getFileDescriptor(),0,afd.getLength(),1)或afd.getFileDescriptor().valid()?@JiteshUpadhyay:文件未压缩,我曾尝试使用-0作为maven android插件的参数,这意味着没有压缩。@Peter问题是,我从未获得afd对象,因为抛出错误的是openFd()方法。如果您是正确的,maven jarsigner插件的版本标记丢失。我将尝试添加它。谢谢!在过去的几天里,我们一直在努力解决这个问题。这个解决方案解决了我们的问题。谢谢