When i play sound files in android i am getting this error:
11-17 15:58:14.482 158-20904/? E/OMXNodeInstance: setConfig(f3f:google.mp3.decoder, ConfigPriority(0x6f800002)) ERROR: Undefined(0x80001001) 11-17 15:58:14.482 158-20904/? I/ACodec: codec does not support config priority (err -2147483648) 11-17 15:58:14.483 158-20904/? I/MediaCodec: MediaCodec will operate in async mode 11-17 15:58:14.488 158-20902/? E/AudioFlinger: not enough memory for AudioTrack size=131176 11-17 15:58:14.488 158-20902/? D/MemoryDealer: AudioTrack (0xb731c9f0, size=1048576) 11-17 15:58:14.488 158-20902/? D/MemoryDealer: 0: 0xb94bbdf8 | 0x00000000 | 0x00020080 | A 11-17 15:58:14.488 158-20902/? D/MemoryDealer: 1: 0xb94bbe28 | 0x00020080 | 0x00020080 | A 11-17 15:58:14.488 158-20902/? D/MemoryDealer: 2: 0xb7bb4438 | 0x00040100 | 0x00020080 | A 11-17 15:58:14.488 158-20902/? D/MemoryDealer: 3: 0xb7be71f8 | 0x00060180 | 0x00020080 | A 11-17 15:58:14.488 158-20902/? D/MemoryDealer: 4: 0xb94bbca8 | 0x00080200 | 0x00020080 | A 11-17 15:58:14.488 158-20902/? D/MemoryDealer: 5: 0xb7321998 | 0x000A0280 | 0x00020080 | A 11-17 15:58:14.488 158-20902/? D/MemoryDealer: 6: 0xb73883d0 | 0x000C0300 | 0x00020080 | A 11-17 15:58:14.488 158-20902/? D/MemoryDealer: 7: 0xb9e4f420 | 0x000E0380 | 0x0001FC80 | F 11-17 15:58:14.488 158-20902/? D/MemoryDealer: size allocated: 918400 (896 KB) 11-17 15:58:14.488 158-20902/? E/AudioFlinger: createTrack_l() initCheck failed -12; no control block? 11-17 15:58:14.488 158-20902/? E/AudioTrack: AudioFlinger could not create track, status: -12 11-17 15:58:14.488 158-20902/? E/AudioSink: Unable to create audio track 11-17 15:58:14.488 158-20902/? W/NuPlayerRenderer: openAudioSink: non offloaded open failed status: -19 11-17 15:58:14.488 158-20902/? W/NuPlayerRenderer: onDrainAudioQueue(): audio sink is not ready 11-17 15:58:14.489 158-20902/? W/NuPlayerRenderer: onDrainAudioQueue(): audio sink is not ready 11-17 15:58:14.489 158-20902/? W/NuPlayerRenderer: onDrainAudioQueue(): audio sink is not ready 11-17 15:58:14.490 158-20902/? W/NuPlayerRenderer: onDrainAudioQueue(): audio sink is not ready
here is my code:
public void playSound(int n) { try { Log.e("n value is", "" + n); boolean mStartPlaying = true; if (mStartPlaying == true) { mPlayer = new MediaPlayer(); Uri uri = Uri.parse("android.resource://packagename/" + beeb.mp3); mPlayer.setOnCompletionListener(soundListener); mPlayer.setDataSource(getContext(), uri); mPlayer.prepare(); mPlayer.setLooping(false); mPlayer.start(); } else { // stopPlaying(); //rePlay.setText("Replay"); mPlayer.stop(); mPlayer.release(); mPlayer = null; } mStartPlaying = !mStartPlaying; } catch (IOException e) { Log.e("ERR", "prepare() failed"); } }
I've seen that issue caused by not adequately releasing the mediaplayer. It seems to be able to keep playing 6 more times without the proper release, but at 7 times it has to start releasing threads.
Before starting your media player, or using the create command, check if it's null, and if it's not null, clean it up. First stop it if it's playing, or looping. Once it's stopped, then release it, and then make it null. Once that's been done you should be able to safely use the create command, and start playing.
if (mp != null){
if (mp.isPlaying()||mp.isLooping()) {
mp.stop();
}
mp.release();
mp = null;
}
mp = MediaPlayer.create(this,R.raw.sound); // note that R = res folder, raw = raw subfolder holding my audio files, and sound is the name of one of the audio files
mp.start();
User contributions licensed under CC BY-SA 3.0