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



我正在开发一个应用程序,我想同时播放两个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不适用于播放长音。当每个人都收到一条参数完全相同的错误消息时,你必须对操作系统的质量有点怀疑,否则这是一个惊人的巧合。

相关内容

最新更新