Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issue with Soundpool and Samsung Galaxy S

Tags:

android

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.

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

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;

  }
}

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

Many thanks in advance

like image 773
Steven Avatar asked Dec 28 '10 16:12

Steven


People also ask

How do you fix the low volume on a call on a Samsung Galaxy?

During a call, press the Volume up button on the side of your phone or you can test the sound from the Settings menu on your device. 1 Go to "Settings", then tap "Sounds and vibration". 2 Tap "Volume". 3 Slide the bar to adjust the volume to your preferred level for each type of sound.

How do I fix the sound on my Samsung a12?

Does your device not produce any sound? You might have turned the volume down completely. You can check and adjust this via the menu by swiping up/down > Settings > Sounds and vibration > Volume.

Why is my Samsung not playing media sound?

You might have the sound muted or turned down low in the app. Check the media volume. If you still don't hear anything, verify that the media volume isn't turned down or off: Navigate to Settings.


1 Answers

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

like image 113
Steven Avatar answered Nov 05 '22 00:11

Steven