在我的应用中,当用户点击按钮时,会播放声音。由于用户可以多次按下该按钮并且比声音的长度快得多,因此我缩短了声音。现在它像0.2秒或sg。奇怪的是,现在Android无法播放声音,我的app力量关闭。那么声音的长度还是什么?它与之前的类似.mp3。 这是我正在使用的代码:
mp = MediaPlayer.create(Start.this, R.raw.clicksound2);
mp.start();
NameButton.setEnabled(false);
mp.setOnCompletionListener(new OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
mp.release();
NameButton.setEnabled(true);
}
});
logcat的:
06-09 05:38:23.774: ERROR/AndroidRuntime(551): java.lang.NullPointerException
06-09 05:38:23.774: ERROR/AndroidRuntime(551): at com.bfarago.clickme.Start$1.onClick(Start.java:113)
06-09 05:38:23.774: ERROR/AndroidRuntime(551): at android.view.View.performClick(View.java:2408)
06-09 05:38:23.774: ERROR/AndroidRuntime(551): at android.view.View$PerformClick.run(View.java:8816)
06-09 05:38:23.774: ERROR/AndroidRuntime(551): at android.os.Handler.handleCallback(Handler.java:587)
06-09 05:38:23.774: ERROR/AndroidRuntime(551): at android.os.Handler.dispatchMessage(Handler.java:92)
06-09 05:38:23.774: ERROR/AndroidRuntime(551): at android.os.Looper.loop(Looper.java:123)
06-09 05:38:23.774: ERROR/AndroidRuntime(551): at android.app.ActivityThread.main(ActivityThread.java:4627)
06-09 05:38:23.774: ERROR/AndroidRuntime(551): at java.lang.reflect.Method.invokeNative(Native Method)
06-09 05:38:23.774: ERROR/AndroidRuntime(551): at java.lang.reflect.Method.invoke(Method.java:521)
06-09 05:38:23.774: ERROR/AndroidRuntime(551): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
06-09 05:38:23.774: ERROR/AndroidRuntime(551): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
06-09 05:38:23.774: ERROR/AndroidRuntime(551): at dalvik.system.NativeStart.main(Native Method)
06-09 05:38:23.794: WARN/ActivityManager(70): Force finishing activity com.bfarago.clickme/.Start
06-09 05:38:24.357: WARN/ActivityManager(70): Activity pause timeout for HistoryRecord{43efc7b0 com.bfarago.clickme/.Start}
第113行是mp.start();
答案 0 :(得分:0)
我看不到你的其余代码,但在你的代码中你有mp.release()调用时 MediaPlayer mp完成播放,之后对象mp不再可用,因此您需要再次创建它。