当我在Android中播放声音文件时,我收到此错误:
11-17 15:58:14.482 158-20904 /? E / OMXNodeInstance: setConfig(f3f:google.mp3.decoder,ConfigPriority(0x6f800002))错误: 未定义(0x80001001)11-17 15:58:14.482 158-20904 /? I / ACodec:编解码器 不支持配置优先级(错误-2147483648)11-17 15:58:14.483 158-20904 /? I / MediaCodec:MediaCodec将以异步模式11-17运行 15:58:14.488 158-20902 /? E / AudioFlinger:没有足够的内存 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 |一个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 |一个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 |一个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 |一个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:分配的大小:918400(896 KB)11-17 15:58:14.488 158-20902 /? E / AudioFlinger:createTrack_l()initCheck失败-12;没有 控制块? 11-17 15:58:14.488 158-20902 /? E / AudioTrack: AudioFlinger无法创建曲目,状态:-12 11-17 15:58:14.488 158-20902 /? E / AudioSink:无法创建音轨11-17 15:58:14.488 158-20902 /? W / NuPlayerRenderer:openAudioSink:非 卸载打开失败状态:-19 11-17 15:58:14.488 158-20902 /? W / NuPlayerRenderer:onDrainAudioQueue():音频接收器未就绪11-17 15:58:14.489 158-20902 /? W / NuPlayerRenderer:onDrainAudioQueue(): 音频接收器尚未就绪11-17 15:58:14.489 158-20902 /? W / NuPlayerRenderer:onDrainAudioQueue():音频接收器未就绪11-17 15:58:14.490 158-20902 /? W / NuPlayerRenderer:onDrainAudioQueue(): 音频接收器尚未就绪
这是我的代码:
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"); } }
答案 0 :(得分:3)
我已经看到由于没有充分释放媒体播放器而引起的问题。它似乎能够在没有适当释放的情况下继续播放6次,但是在7次时它必须开始释放线程。
在启动媒体播放器或使用create命令之前,请检查它是否为空,如果它不为空,请将其清除。如果它正在播放或循环播放,请先停止播放。一旦它停止,然后释放它,然后使其为空。完成后,您应该能够安全地使用create命令,然后开始播放。
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();