问题的Soundpool和三星Galaxy S [英] Issue with Soundpool and Samsung Galaxy S

查看:104
本文介绍了问题的Soundpool和三星Galaxy S的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近收购了三星Galaxy S的Andr​​oid 2.1更新和运行我的应用程序后,我发现了一些声音效果播放两次兼任。这是奇怪,因为声音效果表现出这种行为看似随机的 - 在某些情况下,有些人会在别人的期望,他们将发挥玩一次两次。此错误还没有报道任何其它硬件平台我的应用程序。我只看到了这一报道的事件在本网站和人交换使用的MediaPlayer,但是我真的想要得到补救这一点。

I recently acquired a Samsung Galaxy S, Android 2.1 update and after running my app I found that some of the sound effects play twice concurrently. This is odd because the sound effects which exhibit this behaviour seem random - on some instances some will play twice on others they will play once as expected. This bug has not been reported on any other hardware platform for my app. I have only seen one reported incident of this on this site and the person switched to use MediaPlayer however I really want to get a remedy for this.

当应用程序被运行它启动的Soundpool如下,

When the app is run it initiates the Soundpool as follows,

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, soundPool.load(getContext(), R.raw.pop, 1));
     soundPoolMap.put(SOUND_CLICK, soundPool.load(getContext(), R.raw.click, 1));
     soundPoolMap.put(SOUND_MAGIC, soundPool.load(getContext(), R.raw.swoosh, 1));
     soundPoolMap.put(SOUND_ROCKET, soundPool.load(getContext(), R.raw.rocket, 1));
     soundPoolMap.put(SOUND_MELT, soundPool.load(getContext(), R.raw.melt3, 1));
     mgr = (AudioManager)getContext().getSystemService(Context.AUDIO_SERVICE); 
}

FX音效,然后通过调用下面的子打了,(PlaySound是一个全球性的用户选择切换)

Sound fx are then played by calling the following sub, (PlaySound is a global toggled by the user options)

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, volume, 1, 0, 1f);
 }

} 

正如你可以看到有我用来看看有多少次次被称为虽然这显示,当错误发生时的程序时,声音是从该设备听到两次只调用一次记录呼叫。

As you can see there is a log call which I used to see how many times the sub had been called although this revealed that when the bug occurs the routine is only called once when the sound is heard twice from the device.

我也有最后一分,当表面观被破坏收拾这就是所谓。

I have also one last sub which is called when the surface view is destroyed to tidy up.

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

   soundPool.release();
   soundPool = null;

  }
}

任何人都有这个问题,如果是的话你是怎么解决的呢?任何帮助将是很大的AP preciated,

Has anyone else had this issue, if so how did you resolve it? Any help on this would be greatly appreciated,

在预先感谢

推荐答案

在原始文件夹转换音频文件到OGG似乎已经解决了这个错误 - 因为我还没有看到它的重复

Converting sound files to OGG in the raw folder seems to have resolved this bug - I have not seen a repeat of it since.

这篇关于问题的Soundpool和三星Galaxy S的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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