adjust Audio Stream Volume - Android Media

Android examples for Media:Media Volume

Description

adjust Audio Stream Volume

Demo Code


//package com.java2s;

import android.content.Context;

import android.media.AudioManager;

import android.view.KeyEvent;

public class Main {
    public static void adjustStreamVolume(Context mContext, int action) {
        AudioManager mAudioManager = (AudioManager) mContext
                .getSystemService(Context.AUDIO_SERVICE);
        if (action == KeyEvent.KEYCODE_VOLUME_UP) {
            mAudioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC,
                    AudioManager.ADJUST_RAISE, AudioManager.FLAG_SHOW_UI);
        } else {//  ww  w  . j  a v a 2s. co  m
            mAudioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC,
                    AudioManager.ADJUST_LOWER, AudioManager.FLAG_SHOW_UI);
        }
    }
}

Related Tutorials