本文介绍了SoundPool“AudioFlinger无法创建曲目,状态:-12”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我有一个带有单键的Android应用程序。单击该按钮时,应用程序开始播放(循环)SoundPool加载的声音。再次单击该按钮时,声音将停止,然后再次启动。 但问题是声音仅在每隔一段时间播放。 点击第一次 - >声音开始播放 点击第二次 - >声音停止但无法启动再次 点击第3次 - >声音开始播放 点击第4次 - >声音停止但无法开始播放 依此类推...... 当声音无法播放时,logcat中会出现此错误: E / AudioTrack:AudioFlinger无法创建曲目,状态:-12 E / SoundPool:创建AudioTrack时出错 当我删除循环(将-1更改为0)时,一切正常! 我正在播放的声音是一个MP3文件,大小为71.6 KiB。 我在索尼Xperia U上测试了这个,运行Android 4.1.2(不工作)。但在我的华为Honor 6(Android 6.0)中,一切正常,包括循环! 我做错了什么? 这是我的代码: 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; 公共类MainActivity扩展AppCompatActivity { private int lastStreamId = 0; private int soundID; 私人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); 按钮按钮=(按钮)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); } }); } } 编辑: 我不允许在这里上传原始声音,但这是另一种声音做同样的事情。 除了现在声音仅在第一次点击时播放;所有以下点击只是让它静音并吐出上述错误。 声音在这里: 这是下采样文件。 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 playClick 2nd time -> sound stops but doesn't start againClick 3rd time -> sound starts to playClick 4th time -> sound stops but doesn't start to playand so on...When the sound doesn't play, this error appears in the logcat:E/AudioTrack: AudioFlinger could not create track, status: -12E/SoundPool: Error creating AudioTrackWhen 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 解决方案 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.Here's the downsampled file. 这篇关于SoundPool“AudioFlinger无法创建曲目,状态:-12”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-18 13:48