android 打开file not found,从android资源中打开wav文件时出现FileNotFoundException(FileNotFoundException when openi...

从android资源中打开wav文件时出现FileNotFoundException(FileNotFoundException when opening wav file from android assets)

在我们的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插件

验证了文件结构并且文件在那里并正在工作。

使用上面的代码时,我们得到以下堆栈跟踪:

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)

...

有人可以帮助我们解决这个奇怪的问题....

最好的祝福,

亨里克

In our android app we open wav file located in assets/config/notification.wav. To open and play the sound we are using the following code:

String soundClipPath = "config/notification.wav"

AssetFileDescriptor afd = mContext.getAssets().openFd(soundClipPath);

int soundID = mSoundPool.load(afd, 1);

This has been working witout any problem for about a year now. Suddenly this has stopped working. We have not updated any dependencies between the builds. The only difference i can find is that the builds working is from last year. It works if we build the apk locally in netbeans but when we build the apk using hudson it doesn't work. I have tried the following with no luck:

Place the wav file in res/raw folder

Add -0 to maven android plugin

Verified the file structure and the file is there and working.

We get the following stacktrace when using the code above:

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)

...

And the following when trying to load from res/raw folder:

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)

...

Can someone please help us out with this strange problem....

Best regards,

Henrik

原文:https://stackoverflow.com/questions/21136289

更新时间:2020-01-10 19:13

最满意答案

让我猜猜,你是否使用maven-jarsigner-plugin进行应用程序签名? 而这个没有指定版本? 将近四周前, maven-jarsigner-plugin已更新至1.3版,现在当我签名时,它对我的​​应用程序做了一些奇怪的事情 - 在签署应用程序之后,我收到了类似你的异常。 我在pom.xml maven-jarsigner-plugin后简单地添加了1.2来解决它。

我希望它也能帮助你。

Let me guess, do you use maven-jarsigner-plugin for application signing? And this one has no version specified? Near four weeks ago maven-jarsigner-plugin was updated to version 1.3 and now it do something strange with my application when I sign it - after signing on application start I got exceptions like yours. I solved it simply adding 1.2 after maven-jarsigner-plugin in pom.xml.

I hope it helps you too.

2014-02-01

相关问答

因此,对于ffmpeg的最新版本(build 03-Feb-2014),以下命令有效: ffmpeg -i 2353-1389698676.wav -ar 8000 -b 16k convert/2353-1389698676-convert.wav

所以SOX失败了这种转换...... So with the last version of ffmpeg (build 03-Feb-2014) the following command work : ffmpeg -i 2353-138969

...

WavFile类http://www.labbookpages.co.uk/audio/javaWavFiles.html宣称可以读取和写入wav文件并允许通过样本值数组进行每个样本的操作。 这当然是相当小的,总共23kbytes的源代码。 我确实挣扎了一段时间来构建一个包含Wavfile类的Android应用程序。 原来,这是因为WavFile和ReadExample(来自上面的链接)都是作为独立的Java程序使用的,所以包含一个方法main(String [] args){} 。 Eclips

...

本文表明使用rb效果很好。 请注意,此答案中没有任何内容是Windows特定的。 只是标准的C IO。 This article indicates that using rb works well. Note that nothing in this answer is Windows specific. Just standard C IO.

尝试创建原始文件夹并将文件放在那里,使用这个 public void number(int num, Context ctx) {

AssetManager am;

try {

am = ctx.getAssets();

AssetFileDescriptor afd = am.openFd("android.resource://"+getPackageName+"/"+R.raw.your_fil

...

关于你有的代码: 替换Uri uri = Uri.parse(f.getAbsolutePath()); 与Uri uri = Uri.fromFile(f); ,以获得有效的Uri 对于MIME类型,请使用audio/wav ,而不是audio/* 您的代码将在Android 7.0+上发生FileUriExposedException 。 FileProvider使用FileProvider ,在元数据XML资源中使用 ,并将FLAG_GRANT_READ_URI

...

通过转到源文件夹创建资产文件夹,然后右键单击 New->Folder->Asset Folder

然后粘贴到该资产文件夹中的文件看这个图像 请注意,资产文件夹位于主文件夹下 create asset folder by go to your source folder then right click New->Folder->Asset Folder

then paste to file in that asset folder look at this image note that as

...

让我猜猜,你是否使用maven-jarsigner-plugin进行应用程序签名? 而这个没有指定版本? 将近四周前, maven-jarsigner-plugin已更新至1.3版,现在当我签名时,它对我的应用程序做了一些奇怪的事情 - 在签署应用程序之后,我收到了类似你的异常。 我在pom.xml maven-jarsigner-plugin后简单地添加了1.2来解决它。 我希望它也能帮助你。 Let me

...

据我所知,CHANNEL_CONFIGURATION_MONO已弃用,请使用CHANNEL_IN_MONO。 考虑看rehearsalassistant项目,afaik也使用AudioRecord类。 应选择采样率以符合标准采样率,如本维基百科文章中所述 。 CHANNEL_CONFIGURATION_MONO is deprecated as far as i know, use CHANNEL_IN_MONO. consider looking at rehearsalassistant pr

...

下面的代码部分将作为已经进行了多少选择。选择意味着选择了多少文件。 将两个wav文件放在/ sdcard0 / SSoftAudioFiles /中作为1.wav和2.wav。 并且只需执行此方法。 public void SSoftAudCombine()

{

try {

String[] selection=new String[2];

selection[0]="1.wav";

selection[1]="2.wav";

DataOutputStream ampli

...

我同意亚历克斯。 我花时间整理了一个包含三行代码的小程序,用于打印wav文件的持续时间。 var stream=new MemoryStream(File.ReadAllBytes("test.wav"));

var wave = new WaveFileReader(stream);

Console.WriteLine(wave.TotalTime); // wave.TotalTime -> TimeSpan

下载NAudio库:你会在包中找到

...

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值