ToneGenerator崩溃Android

前端之家收集整理的这篇文章主要介绍了ToneGenerator崩溃Android前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
几天前,我收到了我发布的应用程序的崩溃日志.

错误来自ToneGenerator,我找不到问题.

在这里,我有一个倒数计时器,当计时器达到0时,应用程序启动一个ToneGenerator.

private void lanceMinuteur(int temps,int color){
    if(color == 0)
        minuteur.setTextColor(getResources().getColor(R.color.color_important));
    else
        minuteur.setTextColor(getResources().getColor(R.color.color_informative));

    if(chronoLance){
        chrono.cancel();
    }
    chronoLance = true;

    chrono = new CountDownTimer((temps + 1) * 1000,1000) {
        public void onTick(long millisUntilFinished) {
            minuteur.setText(String.valueOf(millisUntilFinished / 1000) + "\"");
        }
        public void onFinish() {
            minuteur.setText("0\"");
            minuteur.setTextColor(getResources().getColor(R.color.textcolor1design));
            chronoLance = false;
            final ToneGenerator tg = new ToneGenerator(AudioManager.STREAM_NOTIFICATION,100);  //The error is coming from here
            tg.startTone(ToneGenerator.TONE_PROP_ACK);
        }
    }.start();

}

我收到的崩溃日志:

java.lang.RuntimeException: Init Failed
at android.media.ToneGenerator.native_setup(Native Method)
at android.media.ToneGenerator.<init>(ToneGenerator.java:798)
at ma.myperf.musculation.activ.GoPerformanceActivity$2.onFinish(GoPerformanceActivity.java:350)
at android.os.CountDownTimer$1.handleMessage(CountDownTimer.java:118)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:150)
at android.app.ActivityThread.main(ActivityThread.java:4385)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:849)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:607)
at dalvik.system.NativeStart.main(Native Method)

那可能是什么问题呢?如果ToneGenerator有一个尝试Catch块,我会打瞌睡但是没有.

我想也许发生崩溃的设备没有AudioManager.Stream_Notification?

解决方法

我发现这个 here

听起来你的应用程序没有发布它的媒体播放器资源.当你完成播放声音时,你需要拨打电话MediaPlayer.release()方法.如果你正在播放很多声音很快,垃圾收集器将无法跟上.

原文链接:https://www.f2er.com/android/309506.html

猜你在找的Android相关文章