gpt4 book ai didi

android - AudioCache 堆大小溢出问题请求大小 : 1053184, 最大大小:1048576

转载 作者:太空宇宙 更新时间:2023-11-03 12:40:29 25 4
gpt4 key购买 nike

我正在开发一个应用程序,我想同时播放两个 mp3 文件,一个作为背景音乐,并想分别控制每个播放器的声音。每个文件大小为 5 mb

我已经完成了主音频文件,但是当我尝试用它播放第二个文件时它会抛出错误

  SoundManager mSoundManager = new SoundManager();
mSoundManager.initSounds(getBaseContext());

mSoundManager.addSound(1,R.raw.music);
mSoundManager.addSound(2,R.raw.mentalafslapning);
mSoundManager.playSound(1);
mSoundManager.playSound(2);


}
class SoundManager
{
private SoundPool mSoundPool;
private HashMap<Integer, Integer> mSoundPoolMap;
private AudioManager mAudioManager;
private Context mContext;
private Vector<Integer> mAvailibleSounds = new Vector<Integer>();
private Vector<Integer> mKillSoundQueue = new Vector<Integer>();
private Handler mHandler = new Handler();

public SoundManager(){}

public void initSounds(Context theContext) {
mContext = theContext;
mSoundPool = new SoundPool(20, AudioManager.STREAM_MUSIC, 0);
mSoundPoolMap = new HashMap<Integer, Integer>();
mAudioManager = (AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE);
}

public void addSound(int Index, int SoundID)
{
mAvailibleSounds.add(Index);
mSoundPoolMap.put(Index, mSoundPool.load(mContext, SoundID, 1));

}

public void playSound(int index) {
// dont have a sound for this obj, return.
if(mAvailibleSounds.contains(index)){

int streamVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
int soundId = mSoundPool.play(mSoundPoolMap.get(index), streamVolume, streamVolume, 1, 0, 1f);

mKillSoundQueue.add(soundId);

// schedule the current sound to stop after set milliseconds
mHandler.postDelayed(new Runnable() {
public void run() {
if(!mKillSoundQueue.isEmpty()){
mSoundPool.stop(mKillSoundQueue.firstElement());
}
}
}, 3000);
}
}

是否可以同时播放两个文件并分别控制每个文件的音量?

最佳答案

我看过的所有评论都表明 SoundPool 不适用于播放长音。当每个人都收到具有完全相同参数的错误消息时,您必须对操作系统质量产生怀疑,否则这是一个惊人的巧合。

关于android - AudioCache 堆大小溢出问题请求大小 : 1053184, 最大大小:1048576,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9124026/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com