Reduce Music Volume - Android Media

Android examples for Media:Media Volume

Description

Reduce Music Volume

Demo Code


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

public class VolumeUtil {
    private static VolumeUtil staticInstance;
    private AudioManager audioManager;

    private VolumeUtil(Context context) {
        audioManager = (AudioManager) context
                .getSystemService(Context.AUDIO_SERVICE);
    }//w  ww  . j  a v a2 s  . c  o m

    public static VolumeUtil getStaticInstance(Context context) {
        if (staticInstance == null)
            staticInstance = new VolumeUtil(context);
        return staticInstance;
    }

    public void raiseVolume() {
        audioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC,
                AudioManager.ADJUST_RAISE, 0);
    }

    public void reduceVolume() {
        audioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC,
                AudioManager.ADJUST_LOWER, 0);
    }
}

Related Tutorials