简体   繁体   中英

Sound won't work on android device. Works fine on emulator

I have tried changing the sound scheme several ways. I have looked into Uri and SoundPool but I'm not sure I was using them right. Here is the working code with MediaPlayer:

 final Context context;
 MediaPlayer media;

 void play()
{

 media=MediaPlayer.create(context, R.raw.soundFile);
 media.start();
 }

As I said it runs fine on the emulator. It is an ogg sound file, but I have tried mp3 and wav.

Here is the log file for the crash:

D/AndroidRuntime(  981): Shutting down VM
W/dalvikvm(  981): threadid=1: thread exiting with uncaught exception (group=0x4
0a9c228)
E/AndroidRuntime(  981): FATAL EXCEPTION: main
E/AndroidRuntime(  981): android.content.res.Resources$NotFoundException: File r
es/raw/ouch.ogg from drawable resource ID #0x7f040000
E/AndroidRuntime(  981):        at android.content.res.Resources.openRawResource
Fd(Resources.java:1081)
E/AndroidRuntime(  981):        at android.media.MediaPlayer.create(MediaPlayer.
java:762)
E/AndroidRuntime(  981):        at Seven.Circle.GameView.onTouchEvent(GameView.j
ava:185)
E/AndroidRuntime(  981):        at android.view.View.dispatchTouchEvent(View.jav
a:5579)
E/AndroidRuntime(  981):        at android.view.ViewGroup.dispatchTransformedTou
chEvent(ViewGroup.java:1965)
E/AndroidRuntime(  981):        at android.view.ViewGroup.dispatchTouchEvent(Vie
wGroup.java:1692)
E/AndroidRuntime(  981):        at android.view.ViewGroup.dispatchTransformedTou
chEvent(ViewGroup.java:1965)
E/AndroidRuntime(  981):        at android.view.ViewGroup.dispatchTouchEvent(Vie
wGroup.java:1692)
E/AndroidRuntime(  981):        at android.view.ViewGroup.dispatchTransformedTou
chEvent(ViewGroup.java:1965)
E/AndroidRuntime(  981):        at android.view.ViewGroup.dispatchTouchEvent(Vie
wGroup.java:1692)
E/AndroidRuntime(  981):        at com.android.internal.policy.impl.PhoneWindow$
DecorView.superDispatchTouchEvent(PhoneWindow.java:1982)
E/AndroidRuntime(  981):        at com.android.internal.policy.impl.PhoneWindow.
superDispatchTouchEvent(PhoneWindow.java:1441)
E/AndroidRuntime(  981):        at android.app.Activity.dispatchTouchEvent(Activ
ity.java:2414)
E/AndroidRuntime(  981):        at com.android.internal.policy.impl.PhoneWindow$
DecorView.dispatchTouchEvent(PhoneWindow.java:1930)
E/AndroidRuntime(  981):        at android.view.View.dispatchPointerEvent(View.j
ava:5759)
E/AndroidRuntime(  981):        at android.view.ViewRootImpl.deliverPointerEvent
(ViewRootImpl.java:2963)
E/AndroidRuntime(  981):        at android.view.ViewRootImpl.handleMessage(ViewR
ootImpl.java:2522)
E/AndroidRuntime(  981):        at android.view.ViewRootImpl.processInputEvents(
ViewRootImpl.java:862)
E/AndroidRuntime(  981):        at android.view.ViewRootImpl.handleMessage(ViewR
ootImpl.java:2531)
E/AndroidRuntime(  981):        at android.os.Handler.dispatchMessage(Handler.ja
va:99)
E/AndroidRuntime(  981):        at android.os.Looper.loop(Looper.java:154)
E/AndroidRuntime(  981):        at android.app.ActivityThread.main(ActivityThrea
d.java:4894)
E/AndroidRuntime(  981):        at java.lang.reflect.Method.invokeNative(Native
Method)
E/AndroidRuntime(  981):        at java.lang.reflect.Method.invoke(Method.java:5
11)
E/AndroidRuntime(  981):        at com.android.internal.os.ZygoteInit$MethodAndA
rgsCaller.run(ZygoteInit.java:784)
E/AndroidRuntime(  981):        at com.android.internal.os.ZygoteInit.main(Zygot
eInit.java:551)
E/AndroidRuntime(  981):        at dalvik.system.NativeStart.main(Native Method)

E/AndroidRuntime(  981): Caused by: java.io.FileNotFoundException: This file can
 not be opened as a file descriptor; it is probably compressed
E/AndroidRuntime(  981):        at android.content.res.AssetManager.openNonAsset
FdNative(Native Method)
E/AndroidRuntime(  981):        at android.content.res.AssetManager.openNonAsset
Fd(AssetManager.java:503)
E/AndroidRuntime(  981):        at android.content.res.Resources.openRawResource
Fd(Resources.java:1078)
E/AndroidRuntime(  981):        ... 26 more

Until now I had not noticed "E/AndroidRuntime( 981): FATAL EXCEPTION: main E/AndroidRuntime( 981): android.content.res.Resources$NotFoundException: File r es/raw/ouch.ogg from drawable resource ID #0x7f040000 ", which is indeed the error I was looking for. I am open to suggestions on a quick fix. Until then I will continue debugging.

Providing the LogCat record of the error would help immensely. Also, try looking at the error log generated there and see if u can spot a 'Caused by' tag and read the relevant error message which should point you to the line number in a file that the error is being flagged at.

(Edit: can you see if u spot any user created files in the log since the log is out of focus and I can't see the whole thing)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM