AudioCache堆大小溢出问题REQ大小:1053184,最大尺寸:1048576 [英] AudioCache Heap size overflow issue req size: 1053184, max size: 1048576

查看:1589
本文介绍了AudioCache堆大小溢出问题REQ大小:1053184,最大尺寸:1048576的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发一个应用程序,在这里我想同时玩两款MP3文件中的一个作为背景音乐,并希望单独控制每个玩家的声音。文件大小为每个5 MB

I am developing an app where i want to play two mp3 files simultaneously one as background music and want to control the sound of each player separately. The file size is 5 mb each

我已经做了与主音频文件,但是当我试图发挥它的第二个文件,它抛出错误

i have done with main audio file but when i try to play second file with it it throws error

  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);
      }
     }    

是否可以在同一时间播放两个文件,​​并控制各卷分别?

IS it possible to play both the files at same time and control the volume of each separately?

推荐答案

我所看过的意见建议的Soundpool并不适用于打很长的声音。 你必须得到一个有点可疑的操作系统质量,当每个人都得到一个错误信息具有完全相同的参数,否则这是一个惊人的巧合。

All the comments I have read suggest that SoundPool is not applicable to playing long sounds. You have to get a bit suspicious of OS quality when every one gets an error message with the exact same parameters, else it is an amazing coincidence.

这篇关于AudioCache堆大小溢出问题REQ大小:1053184,最大尺寸:1048576的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆