我已经尝试通过多种方式更改声音方案。我查看了 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:文件 r es/raw/ouch.ogg 来自可绘制资源 ID #0x7f040000 ",这确实是我一直在寻找的错误。我愿意接受有关快速修复的建议。在那之前,我将继续调试。
最佳答案
提供错误的 LogCat 记录会有很大帮助。另外,尝试查看那里生成的错误日志,看看您是否可以发现“由...引起”标签并阅读相关的错误消息,这些消息应该指向文件中标记错误的行号。
(编辑:你能看看你是否在日志中发现任何用户创建的文件,因为日志不在焦点上,我看不到整个东西)
关于android - 声音不适用于 Android 设备。在模拟器上运行良好,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11354798/