3

我尝试过几种方式更改声音方案。我研究了 Uri 和 SoundPool,但我不确定我是否正确使用它们。这是 MediaPlayer 的工作代码:

 final Context context;
 MediaPlayer media;

 void play()
{

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

正如我所说,它在模拟器上运行良好。这是一个 ogg 声音文件,但我尝试过 mp3 和 wav。

这是崩溃的日志文件:

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

直到现在我还没有注意到“E/AndroidRuntime(981): FATAL EXCEPTION: main E/AndroidRuntime(981): android.content.res.Resources$NotFoundException: File res/raw/ouch.ogg from drawable resource ID #0x7f040000 ",这确实是我正在寻找的错误。我愿意接受有关快速修复的建议。在那之前我会继续调试。

4

1 回答 1

0

提供错误的 LogCat 记录将有很大帮助。另外,尝试查看那里生成的错误日志,看看您是否可以发现“由”标签并阅读相关的错误消息,该消息应该指向文件中标记错误的行号。

(编辑:你能看到你是否在日志中发现任何用户创建的文件,因为日志没有焦点,我看不到整个内容)

于 2012-07-13T20:09:00.723 回答