Reputation: 969
I am trying to play audio file in android. Here is my code:
MediaPlayer mp = new MediaPlayer();
mp.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?
Upvotes: 0
Views: 1082
Reputation: 76
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.
Upvotes: 0
Reputation: 1336
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.
Upvotes: 2
Reputation: 2131
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();
Upvotes: -1