我正在尝试使用 SoundPool 类播放 mp3 文件:
但是,我遇到了上述错误。mp3 在我的机器上播放良好 - Win7 64bit。逐字显示错误消息:
09-11 20:27:55.256:E/AudioTrack(671):AudioFlinger 无法创建轨道,状态:-22
编辑
执行所述功能的所有代码:
private SoundPool soundPool = new SoundPool(4, AudioManager.STREAM_MUSIC, 100);;
private HashMap<Integer, Integer> soundsMap = new HashMap<Integer, Integer>();
private int CLICK_SOUND = 1;
int sp = soundPool.load(this, R.raw.click, 1);
soundsMap.clear();
soundsMap.put(CLICK_SOUND, sp);
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;
soundPool.play(soundsMap.get(sound), volume, volume, 1, 0, fSpeed);