gpt4 book ai didi

java - Android MediaPlayer 在 Android 6.0 Marshmallow 上崩溃

转载 作者:行者123 更新时间:2023-12-01 23:35:13 27 4
gpt4 key购买 nike

我的应用程序中有这段代码,我已经使用它很多年了,它适用于从 API 10 到 API 22 的所有 Android 版本。

我将手机升级到 API 23 (Android 6.0 Marshmallow),但现在它崩溃了。

public static void beep(Context context) {
MediaPlayer mp = MediaPlayer.create(context, R.raw.beep);
mp.start();
mp.setOnCompletionListener(new OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
mp.release();
}
});
}

错误是:

01-29 17:16:20.641 8354-8651/mobiliza30.fyb E/MediaPlayer: error (1, -2147483648) 01-29 17:16:20.643 8354-8354/mobiliza30.fyb E/AndroidRuntime: FATAL EXCEPTION: main Process: mobiliza30.fyb, PID: 8354 java.lang.RuntimeException: Unable to resume activity {mobiliza30.fyb/mobiliza30.fyb.activities.ItemCbte}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.media.MediaPlayer.start()' on a null object reference at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3121) at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3152) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1398) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:148) at android.app.ActivityThread.main(ActivityThread.java:5443) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618) Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.media.MediaPlayer.start()' on a null object reference at mobiliza30.fyb.utils.Utiles.beep(Utiles.java:573) at mobiliza30.fyb.activities.ItemCbte.buscarArticulo(ItemCbte.java:1544) at mobiliza30.fyb.activities.ItemCbte.agregarArticulo(ItemCbte.java:1009) at mobiliza30.fyb.activities.ItemCbte.access$200(ItemCbte.java:64) at mobiliza30.fyb.activities.ItemCbte$2.onEditorAction(ItemCbte.java:193) at android.widget.TextView.doKeyDown(TextView.java:6038) at android.widget.TextView.onKeyDown(TextView.java:5919) at android.view.KeyEvent.dispatch(KeyEvent.java:2654) at android.view.View.dispatchKeyEvent(View.java:9237) at mobiliza30.fyb.activities.ItemCbte.onResume(ItemCbte.java:600) at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1281) at android.app.Activity.performResume(Activity.java:6320) at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3110) at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3152)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1398)  at android.os.Handler.dispatchMessage(Handler.java:102)  at android.os.Looper.loop(Looper.java:148)  at android.app.ActivityThread.main(ActivityThread.java:5443)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)

最佳答案

已解决:更改声音文件,效果完美,肯定是 Android 版本 6 不支持该文件的格式。

关于java - Android MediaPlayer 在 Android 6.0 Marshmallow 上崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35093906/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com