简体   繁体   English

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

[英]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. 我看过Uri和SoundPool,但我不确定我是否正确使用它们。 Here is the working code with MediaPlayer: 以下是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. 这是一个ogg声音文件,但我尝试过mp3和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. 到目前为止我还没有注意到“E / AndroidRuntime(981):致命异常:主要E / AndroidRuntime(981):android.content.res.Resources $ NotFoundException:文件来自可绘制资源ID#0x7f040000的/ raw / ouch.ogg “,这确实是我一直在寻找的错误。 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. 提供错误的LogCat记录将有很大帮助。 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) (编辑:你能看到你是否在日志中发现任何用户创建的文件,因为日志失焦,我看不到整件事)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android应用在模拟器上工作正常,但在设备上无效。 使用Internet连接 - Android app works fine on Emulator, but not on Device. Uses Internet Connection 物理设备不会显示,模拟器运行正常 - Physical device won't show up, Emulator works just fine Android LinkedIn无法在设备上运行,并且在模拟器上运行正常 - Android LinkedIn does not work on device and works fine on emulator 我制作的Android App不会安装但在模拟器中工作正常吗? - Android App I made won't Install but works fine in emulator? 带有 Flutter 的 Rive(flare) 文件在 QEMU Android Emulator 上显示并正常工作,但不会在真实 Android 设备的内置 APK 上显示 - Rive(flare) files with Flutter show and works fine on QEMU Android Emulator but won't shows on a builted APK in real android device APK 文件在 android 模拟器中工作,但不会安装在我的设备上 - APK File works in android emulator but won't install on my device Android EditText字段可在模拟器上正常运行,但不能在设备上运行 - Android EditText field works fine on emulator, but not device Android应用程序可以在模拟器中正常运行,但不能在真实设备中运行? - Android application works fine in emulator but not in real device? Android应用程序可以在模拟器上正常运行,但不能在真实设备上运行 - Android Application works fine on emulator but not on a real device android http请求在设备上不起作用,在模拟器中有效 - android http request doesn't work on device, in emulator works
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM