Java 当使用soundPool时,我的第一个声音循环其余的抛出状态12
当使用soundPool时,我的第一个声音循环其余的抛出状态12 这是密码Java 当使用soundPool时,我的第一个声音循环其余的抛出状态12,java,android,soundpool,Java,Android,Soundpool,当使用soundPool时,我的第一个声音循环其余的抛出状态12 这是密码 public SoundPool soundPool = new SoundPool(5, AudioManager.STREAM_MUSIC, 100); public HashMap<Integer, Integer> soundsMap; public int playSound(int sound, int loop) { if (curs != sound) { curs = s
public SoundPool soundPool = new SoundPool(5, AudioManager.STREAM_MUSIC, 100);
public HashMap<Integer, Integer> soundsMap;
public int playSound(int sound, int loop) {
if (curs != sound)
{
curs = sound;
AudioManager mgr = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
float streamVolumeCurrent = mgr.getStreamVolume(AudioManager.STREAM_MUSIC);
float streamVolumeMax = mgr.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
float volume = streamVolumeCurrent / streamVolumeMax;
return soundPool.play(soundsMap.get(sound), volume, volume, 1, loop, 1);
}else
{
return 0;
}
}
public SoundPool SoundPool=new SoundPool(5,AudioManager.STREAM_MUSIC,100);
公共HashMap soundsMap;
公共int播放声音(int声音,int循环){
如果(光标!=声音)
{
curs=声音;
AudioManager管理器=(AudioManager)getSystemService(Context.AUDIO\u服务);
float streamVolumeCurrent=mgr.getStreamVolume(AudioManager.STREAM\u MUSIC);
float streamVolumeMax=mgr.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
浮动体积=流量体积当前值/流量体积最大值;
返回soundPool.play(soundsMap.get(声音),音量,音量,1,循环,1);
}否则
{
返回0;
}
}
只有当我将循环设置为-1时才会发生这种情况
它们是非常小的文件。尝试使用小文件,使用.ogg formate(推荐),我还添加了1秒的睡眠时间以使其成为缓冲区。outofmemory基本上是在未缓冲并尝试播放时出现的
new Thread() {
public void run() {
try {
sleep(900);
mSoundManager.playSound(1);
} catch (InterruptedException e) {
e.printStackTrace();
}
};
}.start();
01-24 13:11:45.383:E/AudioTrack(2073):AudioFlinger无法创建曲目,状态:-12-12内存不足这不是问题,文件很小。