Android Audio issue
I am trying to play audio file in android. Here is my code:
MediaPlayer mp = new MediaPlayer();
m开发者_运维问答p.reset();
mp.create(this, R.raw.beep);
mp.start();
But I keep on getting following error: android.content.res.Resources$NotFoundException: File res/raw/sound.ogg from drawable resource ID #0x7f030002
I have a beep.ogg file in res/raw/ . I also tried it with mp3 and wav files. Still the same error.
Whats the issue?
MediaPlayer.create()
is a static factory method.
try:
MediaPlayer mp = MediaPlayer.create(this, R.raw.beep);
mp.start();
Don't forget to call mp.release()
after you're done with this instance.
The error You described is related to the asset packaging process during project building. The resources are probably compressed with ZIP. If You're using NetBeans as Your IDE the problem lies in nbproject/build-impl.xml file located in Your application project. You could change the line:
<zip destfile="${dist.apk}_" update="true">
to
<zip destfile="${dist.apk}_" update="true" keepcompression="true">
in <target name="-package-dex">
section of the script and ofcourse rebuild the project.
call the reset() method after creation of resource. try this it may works
MediaPlayer mp = new MediaPlayer();
mp.create(this, R.raw.beep);
mp.reset();
mp.start();
精彩评论