TimeoutException Error by SoundPoolImpl.finalize() 在 10 秒后超时



>我有这样的方法来检查 API 中的通知。在这种方法中,我正在尝试通过显示通知来播放声音(小尺寸声音):

public void initNotification(Context cntx, final Typeface typeface){
    if(User_Session.isLoggedIn() != true){
        mNotifHolder.setVisibility(View.INVISIBLE);
    }else{
        mNotifHolder.setVisibility(View.VISIBLE);
        mNotifHolder.setOnClickListener(openNotifActivity);
        HashMap<String, String> user = User_Session.GetUserDetails();
        String strToken     = user.get(SessionManagement.KEY_USERTOKEN);
        String URL          = Constants.NotifiCount_URL+strToken;
        if (NotificationCount != null && !NotificationCount.isDone() && !NotificationCount.isCancelled()){ return; }
        NotificationCount   = Ion.with(cntx).load(URL).asJsonObject().setCallback(new FutureCallback<JsonObject>() {
            @Override
            public void onCompleted(Exception e, JsonObject result) {
                System.out.println("RESULT OF NOTIFICATION COUNT: "+result);
                if(e == null){
                    if(result != null){
                        String count            = result.get("count").getAsString();
                        if(count.equals("0")){
                            mNotifHolder.setVisibility(View.VISIBLE);
                            notifBack.setBackgroundResource(R.drawable.ic_notif_off);
                            notifText.setVisibility(View.INVISIBLE);
                        }else{
                            AudioManager audioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
                            float actualVolume = (float) audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
                            float maxVolume = (float) audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
                            float volume = actualVolume / maxVolume;
                            if (loaded) {
                                soundPool.play(soundID, volume, volume, 1, 0, 1f);
                            }
                            int Count   = Integer.parseInt(count);
                            if(Count > 10){
                                count   = "+10";
                            }
                            notifBack.setBackgroundResource(R.drawable.ic_notif_on);
                            notifText.setVisibility(View.VISIBLE);
                            notifText.setTypeface(typeface);
                            notifText.setText(count);
                            mNotifHolder.setVisibility(View.VISIBLE);
                            ScaleAnimation scale = new ScaleAnimation(0, 1, 0, 1, ScaleAnimation.RELATIVE_TO_SELF, .5f, ScaleAnimation.RELATIVE_TO_SELF, .5f);
                            scale.setDuration(300);
                            scale.setInterpolator(new OvershootInterpolator());
                            mNotifHolder.startAnimation(scale);
                        }
                    }else{
                        Crouton.makeText(MainActivity.this, "ERROR", Style.ALERT).show();
                    }
                }else{
                    Crouton.makeText(MainActivity.this, "ERROR", Style.ALERT).show();
                }
            }
        });
    }
}

但有时应用程序崩溃,我在某些设备中收到此错误:

    java.util.concurrent.TimeoutException: android.media.SoundPool$SoundPoolImpl.finalize() timed out after 10 seconds
            at android.media.SoundPool$SoundPoolImpl.release(Native Method)
            at android.media.SoundPool$SoundPoolImpl.finalize(SoundPool.java:616)
            at java.lang.Daemons$FinalizerDaemon.doFinalize(Daemons.java:187)
            at java.lang.Daemons$FinalizerDaemon.run(Daemons.java:170)
            at java.lang.Thread.run(Thread.java:841)

我应该如何解决它?

您需要为声音池添加释放停止方法。

soundPool.stop(streamID);
soundPool.release();

相关内容

最新更新