Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了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 Au@L_161_8@manager mgr;
private HashMap<Integer,Integer> soundPoolMap;

private void initSounds()
{   
     soundPool = new SoundPool(4,Au@L_161_8@manager.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 = (Au@L_161_8@manager)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(Au@L_161_8@manager.STREAM_MUSIC);   
     float streamVolumeMax = mgr.getStreAMMaxVolume(Au@L_161_8@manager.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的问题所遇到的程序开发问题。

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

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。