Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

335
Views
SoundPool "AudioFlinger could not create track, status: -12"

I have an Android app with single button. When the button is clicked, the app starts playing (looping) sound loaded with SoundPool. When the button is clicked again, the sound is stopped, and then started again.

But the problem is that the sound is played only every other time.

  • Click 1st time -> sound starts to play
  • Click 2nd time -> sound stops but doesn't start again
  • Click 3rd time -> sound starts to play
  • Click 4th time -> sound stops but doesn't start to play
  • and so on...

When the sound doesn't play, this error appears in the logcat:

E/AudioTrack: AudioFlinger could not create track, status: -12
E/SoundPool: Error creating AudioTrack

When I remove looping (change -1 to 0), everything works completely right!

The sound I'm playing is an MP3-file, size 71.6 KiB.

I have tested this on Sony Xperia U, running Android 4.1.2 (not working). But in my Huawei Honor 6 (Android 6.0) everything works, including looping!

What am I doing wrong?


Here is my code:

import android.media.AudioManager;
import android.media.SoundPool;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {

    private int lastStreamId = 0;
    private int soundID;
    private SoundPool soundPool;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        soundPool = new SoundPool(1, AudioManager.STREAM_MUSIC, 0);

        soundID  = soundPool.load(this, R.raw.sound01, 1);


        Button button = (Button) findViewById(R.id.button);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                soundPool.stop(lastStreamId);
                lastStreamId = soundPool.play(soundID, 1, 1, 1, -1, 1);
            }
        });
    }
}

EDIT:

I'm not allowed to upload the original sound here, but here is another sound that does the same thing. Except that now the sound plays only in the first click; all the following clicks just make it silent and spit out the above error.

The sound is here: sound01.mp3

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

As you can see here, error code 12 stands for Out of memory in Linux environment. Apparently they are some issues concerning memory allocation on Jelly Bean (I suppose for pre-lollipop) devices.

I've downsampled your original file from 177808kbps to 32000kbps, and it started to work as expected on pre-lollipop devices.

So, you have to downsample your audio file for pre-lollipop devices. Better have a raw-v21 for original audio files, and put downsampled into raw. Thus devices starting from API 21 will use the original version.

enter image description here

Here's the downsampled file.

over 4 years ago · Santiago Trujillo Report

0

I had the same issue. Do the following:

(1) make sure your files are below 1 MB

(2) more importantly release your SoundPool instances after using them to free memory space

soundPool.release();
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!