android – Soundpool和三星Galaxy S的问题

我最近购买了三星Galaxy S,Android 2.1更新,在运行我的应用程序后,我发现一些声音效果同时播放两次.这很奇怪,因为表现出这种行为的声音效果似乎是随机的 – 在某些情况下,有些人会在其他情况下播放两次,他们将按预期播放一次.我的应用程序的任何其他硬件平台上都没有报告此错误.我在这个网站上只看到一个报道此事件的事件,并且该人转而使用MediaPlayer,但是我真的想得到一个补救措施.

当应用程序运行时,它启动Soundpool,如下所示,

public static final int SOUND_EXPLOSION = 1;
public static final int SOUND_CLEAR = 2;
public static final int SOUND_CLICK = 3;
public static final int SOUND_MAGIC = 4;
public static final int SOUND_ROCKET = 5;
public static final int SOUND_MELT = 6;

private SoundPool soundPool;
private AudioManager mgr;
private HashMap<Integer,Integer> soundPoolMap;

private void initSounds()
{   
     soundPool = new SoundPool(4,AudioManager.STREAM_MUSIC,100);

     soundPoolMap = new HashMap<Integer,Integer>();

     soundPoolMap.put(SOUND_EXPLOSION,soundPool.load(getContext(),R.raw.explosion3,1));
     soundPoolMap.put(SOUND_CLEAR,R.raw.pop,1));
     soundPoolMap.put(SOUND_CLICK,R.raw.click,1));
     soundPoolMap.put(SOUND_MAGIC,R.raw.swoosh,1));
     soundPoolMap.put(SOUND_ROCKET,R.raw.rocket,1));
     soundPoolMap.put(SOUND_MELT,R.raw.melt3,1));
     mgr = (AudioManager)getContext().getSystemService(Context.AUDIO_SERVICE); 
}

然后通过调用以下子播放声音fx(PlaySound是由用户选项切换的全局)

public void playSound(int sound)
{


 if (PlaySound == true)
 {
     Log.w("playSound","Playing Sound" + sound);          
     float streamVolumeCurrent = mgr.getStreamVolume(AudioManager.STREAM_MUSIC);   
     float streamVolumeMax = mgr.getStreamMaxVolume(AudioManager.STREAM_MUSIC);       
     float volume = streamVolumeCurrent / streamVolumeMax; 
     soundPool.play(soundPoolMap.get(sound),volume,1,1f);
 }

}

你可以看到有一个日志调用,我曾经看过调用了多少次虽然这表明当发生错误时,例程只在设备听到两次声音时被调用一次.

我还有一个最后一个sub,当表面视图被破坏以便整理时调用它.

public void ReleaseSounds()
{
  if (soundPool != null)
  {

   soundPool.release();
   soundPool = null;

  }
}

有没有其他人有这个问题,如果是这样你是如何解决它的?任何有关这方面的帮助将不胜感激,

提前谢谢了

解决方法

将声音文件转换为原始文件夹中的OGG似乎已经解决了这个问题 – 我从未见过重复它.

以上是来客网为你收集整理的android – Soundpool和三星Galaxy S的问题全部内容,希望文章能够帮你解决android – Soundpool和三星Galaxy S的问题所遇到的程序开发问题。

如果觉得来客网网站内容还不错,欢迎将来客网网站推荐给程序员好友。