Code example for SparseIntArray

0
 
 
    public SoundManager(Context context) {
        this.context = context;
        soundPool = new SoundPool(4, AudioManager.STREAM_MUSIC, 0);  
        soundMap = new SparseIntArray();
        mgr = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE);  
    } 
 
    public void loadSound(int id, int res) {  
        synchronized(this) {
            soundMap.put(id, soundPool.load(context, res, 1));  
        } 
    } 
 
    public void playSound(int id) {
        synchronized(this) {
            // The next 4 lines calculate the current volume 
            // in a scale of 0.0 to 1.0 
            float curVol = mgr.getStreamVolume(AudioManager.STREAM_MUSIC);  
            float maxVol = mgr.getStreamMaxVolume(AudioManager.STREAM_MUSIC);