I'm trying to play an audio Stream using audioTrack, so i have created audioTrack like this:
public AudioTrack create() {
if (mTrack != null) {
if (mTrack.getState() == AudioTrack.STATE_INITIALIZED) {
return mTrack;
} else {
mTrack.release();
mTrack = null;
}
}
mBuffSize = AudioTrack.getMinBufferSize(Settings.SAMPLE_RATE, AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_16BIT);
mTrack = new AudioTrack(AudioManager.STREAM_MUSIC, Settings.SAMPLE_RATE,
AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_16BIT, mBuffSize, AudioTrack.MODE_STREAM);
if (mTrack.getState() == AudioTrack.STATE_INITIALIZED) {
mTrack.play();
return mTrack;
}
return null;
}
when i finis i call stop like this:
public void stop() {
if (mTrack != null) {
if (mTrack.getState() == AudioTrack.STATE_INITIALIZED) {
mTrack.release();
mTrack = null;
}
}
}
in some device, When i frequently create and stop, i get this:
AudioFlinger could not create track, status: -12.
I searched this issue in StackOverflow many times, but all the answers talk about soundpool , and i have not used a soundpool
Any help would be greatly appreciated!(i'm a Chinese and my English is not good)
Add
to play the audio stream.