2

After about 10-15 photos, the shutter noise stops working and doesn't come back until you restart the app. This error is in android studio:

02-10 10:20:03.626 491-13501/? E/AudioFlinger: no more track names 
available 02-10 10:20:03.626 491-13501/? E/AudioFlinger: 
createTrack_l() initCheck failed -12; no control block? 02-10 
10:20:03.626 31837-31837/ E/AudioTrack: AudioFlinger could not create 
track, status: -12 02-10 10:20:03.627 31837-31837/ E/SoundPool: Error 
creating AudioTrack

Here is the code:

Thread myThread = new Thread(new Runnable() {
    @Override
    public void run() {
        MediaActionSound sound = new MediaActionSound();
        sound.play(MediaActionSound.SHUTTER_CLICK);
    }
} 
Jack A.
  • 4,245
  • 1
  • 20
  • 34
Sunny.A
  • 21
  • 2
  • can u please provide the full code snippet – bakriOnFire Feb 14 '17 at 10:03
  • Thread myThread = new Thread(new Runnable() { @Override public void run() { MediaActionSound sound = new MediaActionSound(); sound.play(MediaActionSound.SHUTTER_CLICK); } }); myThread.start(); – Sunny.A Feb 14 '17 at 10:13
  • you are opening multiple objects without calling release..see if this helps http://stackoverflow.com/questions/11964623/audioflinger-could-not-create-track-status-12 – bakriOnFire Feb 14 '17 at 10:14

1 Answers1

1

In my application I use this code. I also had a similar problem (the sound was not played to the end after several playing). But after reusing (instead of re-creating) MediaActionSound problem has gone.

PS: sound play asynchronously, so you don't need to create a thread.

static private MediaActionSound sound = null;

static public void playShutterSound(){
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) {
        if(sound == null) {
            sound = new MediaActionSound();
        }
        sound.play(MediaActionSound.SHUTTER_CLICK);
    }
}
Mikhail
  • 2,612
  • 3
  • 22
  • 37