TimeoutException Error by SoundPoolImpl.finalize() timed out after 10 seconds

1.6k views Asked by At

I have a method like this that check the API for notifications. at this method I'm trying to play a sound ( small size sound), by showing notification:

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();
                }

            }
        });
    }

}

But sometimes app crashed and I got this Error in some devices:

    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)

How should I resolve it?

1

There are 1 answers

0
Francisco Corrales Morales On

You need to add the release and stop methods for your sound pool.

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