声音在Android设备上无效。在模拟器上正常工作

时间:2012-07-06 01:39:18

标签: android audio media-player emulation

我尝试过多种方式改变声音方案。我看过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):致命异常:主要 E / AndroidRuntime(981):android.content.res.Resources $ NotFoundException:File r 来自可绘制资源ID#0x7f040000的es / raw / ouch.ogg “,这确实是我正在寻找的错误。我对快速修复的建议持开放态度。在那之前我将继续调试。

1 个答案:

答案 0 :(得分:0)

提供错误的LogCat记录会有很大帮助。另外,尝试查看在那里生成的错误日志,看看你是否可以发现'由...引起'标记并阅读相关的错误消息,该消息应该指向文件中的行号,该错误被标记为。

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