音频无法在android中播放. android.content.res.Resources $ NotFoundException:资源ID#0x0 [英] Audio not playing in android. android.content.res.Resources$NotFoundException: Resource ID #0x0

查看:301
本文介绍了音频无法在android中播放. android.content.res.Resources $ NotFoundException:资源ID#0x0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Android中播放音频文件,但似乎崩溃了,并给出了ResourcesNotFoundException.音频文件保存在res内的原始文件夹中.音频文件的名称由随机生成的数字确定,然后将其连接为音频".

I am trying to play an audio file in Android but it seems to crash and give a the ResourcesNotFoundException. The audio file is saved in the raw folder inside res. The name of the audio file is determined by a randomly generated number which is then concatenated to "audio".

int res = getResources().getIdentifier ( "audio"+arrayIndex, "raw","com.din.askak" );
MediaPlayer mPlayer = MediaPlayer.create ( MainActivity.this, res );

在logcat中,似乎在创建mediaPlayer的行上引发了异常.我不知道我似乎在做错什么??

In the logcat it seems to throw the exception on the line creating the mediaPlayer. I don't know what I seem to be doing wrong???

推荐答案

不鼓励使用getIdentifier()函数.按标识符而不是按名称检索资源要高效得多.

Use of getIdentifier() function is discouraged. It is much more efficient to retrieve resources by identifier rather than by name.

这篇关于音频无法在android中播放. android.content.res.Resources $ NotFoundException:资源ID#0x0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆