SoundManager.java :  » Map » mapdroid » org » mapdroid » utils » Android Open Source

Android Open Source » Map » mapdroid 
mapdroid » org » mapdroid » utils » SoundManager.java
package org.mapdroid.utils;

import java.util.HashMap;

import android.content.Context;
import android.media.AudioManager;
import android.media.SoundPool;

public class SoundManager {
  private SoundPool soundPool;
  private HashMap<Integer, Integer> soundPoolMap;
  //private AudioManager audioManager;
  private Context context;
  
  public SoundManager(Context context){
    this.context = context;
    soundPoolMap = new HashMap<Integer, Integer>();
    //audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
  }
  
  public void initSound(int key, int resourceId) {  
       soundPool = new SoundPool(4, AudioManager.STREAM_MUSIC, 0);    
       soundPoolMap.put(key, soundPool.load(context, resourceId, 1));  
  }  
              
  public void playSound(int key){  
      /* Updated: The next 4 lines calculate the current volume in a scale of 0.0 to 1.0 */    
      //float streamVolumeCurrent = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);  
      //float streamVolumeMax = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);      
      //float volume = streamVolumeCurrent / streamVolumeMax;  
        
      /* Play the sound with the correct volume */  
      soundPool.play(soundPoolMap.get(key), 1, 1, 1, 0, 1f);       
  }  
  
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.