[英]Audio not playing in android. android.content.res.Resources$NotFoundException: Resource ID #0x0
I am trying to play an audio file in Android but it seems to crash and give a the ResourcesNotFoundException
. 我正在尝试在Android中播放音频文件,但似乎崩溃了,并给出了ResourcesNotFoundException
。 The audio file is saved in the raw folder inside res. 音频文件保存在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 );
In the logcat it seems to throw the exception on the line creating the mediaPlayer. 在logcat中,似乎在创建mediaPlayer的行上抛出了异常。 I don't know what I seem to be doing wrong??? 我不知道我在做什么错???
Use of getIdentifier()
function is discouraged. 不鼓励使用getIdentifier()
函数。 It is much more efficient to retrieve resources by identifier rather than by name. 通过标识符而不是通过名称检索资源要高效得多。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.