Example usage for android.media AudioManager ADJUST_LOWER

List of usage examples for android.media AudioManager ADJUST_LOWER

Introduction

In this page you can find the example usage for android.media AudioManager ADJUST_LOWER.

Prototype

int ADJUST_LOWER

To view the source code for android.media AudioManager ADJUST_LOWER.

Click Source Link

Document

Decrease the ringer volume.

Usage

From source file:Main.java

public static void adjustMusicVolume(Context context, boolean up, boolean showInterface) {
    int direction = up ? AudioManager.ADJUST_RAISE : AudioManager.ADJUST_LOWER;
    int flag = AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE | (showInterface ? AudioManager.FLAG_SHOW_UI : 0);
    getInstance(context).adjustStreamVolume(AudioManager.STREAM_MUSIC, direction, flag);
}

From source file:com.glanznig.beepme.view.MainActivity.java

@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    int action = event.getAction();
    int keyCode = event.getKeyCode();
    switch (keyCode) {
    case KeyEvent.KEYCODE_VOLUME_UP:
        if (action == KeyEvent.ACTION_UP) {
            audioManager.adjustStreamVolume(AudioManager.STREAM_ALARM, AudioManager.ADJUST_RAISE,
                    AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_PLAY_SOUND);
        }//w ww . j  a  v a2 s . c  om
        return true;
    case KeyEvent.KEYCODE_VOLUME_DOWN:
        if (action == KeyEvent.ACTION_DOWN) {
            audioManager.adjustStreamVolume(AudioManager.STREAM_ALARM, AudioManager.ADJUST_LOWER,
                    AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_PLAY_SOUND);
        }
        return true;
    default:
        return super.dispatchKeyEvent(event);
    }
}

From source file:uk.ac.ucl.excites.sapelli.shared.util.android.DeviceControl.java

/**
 * Decreases the Media Volume//from w  w  w .  j a  v  a2 s . co  m
 * 
 * @param context
 */
public static void decreaseMediaVolume(Context context) {
    // Get the AudioManager
    final AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    // Set the volume
    audioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_LOWER, 0);
}

From source file:com.google.android.marvin.mytalkback.ProcessorVolumeStream.java

private void adjustVolumeFromKeyEvent(int keyCode) {
    final int direction = ((keyCode == KeyEvent.KEYCODE_VOLUME_UP) ? AudioManager.ADJUST_RAISE
            : AudioManager.ADJUST_LOWER);

    if (mTouchingScreen) {
        mAudioManager.adjustStreamVolume(STREAM_TOUCHING_SCREEN, direction, DEFAULT_FLAGS);
    } else {/*from   w w w  .ja v  a  2s .co m*/
        // Attempt to adjust the suggested stream, but let the system
        // override in special situations like during voice calls, when an
        // application has locked the volume control stream, or when music
        // is playing.
        mAudioManager.adjustSuggestedStreamVolume(direction, STREAM_DEFAULT, DEFAULT_FLAGS);
    }
}

From source file:com.dena.app.usage.watcher.MainActivity.java

public boolean onKeyDown(int keyCode, KeyEvent evt) {
    switch (keyCode) {
    case KeyEvent.KEYCODE_VOLUME_UP:
        mAudioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_RAISE,
                AudioManager.FLAG_SHOW_UI);
        return true;
    case KeyEvent.KEYCODE_VOLUME_DOWN:
        mAudioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_LOWER,
                AudioManager.FLAG_SHOW_UI);
        return true;
    default://w w  w.j a v a  2s  .  c  om
        break;
    }
    return super.onKeyDown(keyCode, evt);
}

From source file:com.example.android.miwok.activity.ColorsActivity.java

private AudioManager.OnAudioFocusChangeListener getAudioFocusChangeCallback() {

    return new AudioManager.OnAudioFocusChangeListener() {
        Handler mHandler = new Handler();

        public void onAudioFocusChange(int focusChange) {

            // The AUDIOFOCUS_LOSS case means we've lost audio focus permanently
            if (focusChange == AudioManager.AUDIOFOCUS_LOSS) {
                // Stop playback and clean up resources
                releaseMediaPlayer();//  www .  ja  va  2 s. c  o  m
            }
            // The AUDIOFOCUS_LOSS_TRANSIENT case means that we've lost audio focus for a
            // short amount of time.
            else if (focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT) {
                // Pause playback immediately
                mMediaPlayer.pause();
                // play the word from the beginning when we resume playback.
                mMediaPlayer.seekTo(0);
            }
            //The AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK case means that
            // our app is allowed to continue playing sound but at a lower volume.
            else if (focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK) {
                // Lower the volume, keep playing
                mAudioManager.adjustVolume(AudioManager.ADJUST_LOWER, 0);
            }
            // The AUDIOFOCUS_GAIN case means we have regained focus and can resume playback.
            else if (focusChange == AudioManager.AUDIOFOCUS_GAIN) {
                // Raise volume to normal, restart playback if necessary
                mMediaPlayer.start();
                mAudioManager.adjustVolume(AudioManager.ADJUST_RAISE, 0);

            }
        }
    };
}

From source file:com.google.android.marvin.talkback.ProcessorVolumeStream.java

private void adjustVolumeFromKeyEvent(int keyCode) {
    final int direction = ((keyCode == KeyEvent.KEYCODE_VOLUME_UP) ? AudioManager.ADJUST_RAISE
            : AudioManager.ADJUST_LOWER);

    if (mTouchingScreen) {
        mAudioManager.adjustStreamVolume(STREAM_TOUCHING_SCREEN, direction, DEFAULT_FLAGS_TOUCHING_SCREEN);
    } else {/*www  . ja v a  2  s .  c  o  m*/
        // Attempt to adjust the suggested stream, but let the system
        // override in special situations like during voice calls, when an
        // application has locked the volume control stream, or when music
        // is playing.
        mAudioManager.adjustSuggestedStreamVolume(direction, STREAM_DEFAULT, DEFAULT_FLAGS_NOT_TOUCHING_SCREEN);
    }
}

From source file:com.microsoft.mimickeralarm.appcore.AlarmMainActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
        mAudioManager.adjustStreamVolume(AudioManager.STREAM_ALARM, AudioManager.ADJUST_LOWER,
                AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_PLAY_SOUND);
    } else if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
        mAudioManager.adjustStreamVolume(AudioManager.STREAM_ALARM, AudioManager.ADJUST_RAISE,
                AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_PLAY_SOUND);
    } else {//from   w w w  .  j a v  a  2s . c o  m
        return super.onKeyDown(keyCode, event);
    }
    return true;
}

From source file:com.lybeat.lilyplayer.widget.media.IjkVideoView.java

private void initGestureScanner(final Context context) {
    slop = ViewConfiguration.get(context).getScaledTouchSlop();
    screenWidth = ScreenUtil.getScreenWidth(context);
    gestureDetector = new GestureDetectorCompat(context, new LilyGestureListener());
    setOnTouchListener(new OnTouchListener() {
        @Override// w w w. j  ava  2  s. c  o m
        public boolean onTouch(View view, MotionEvent motionEvent) {
            switch (motionEvent.getAction()) {
            case MotionEvent.ACTION_UP:
                if (adjustProgress) {
                    adjustProgress = false;
                    int newPosition = (int) (getCurrentPosition() + scrollX / screenWidth * 1000 * 90);
                    if (newPosition < 0) {
                        seekTo(0);
                    } else {
                        seekTo(newPosition);
                    }
                    start();
                    mAdjustProgressView.setVisibility(GONE);
                    if (mMediaController.isShowing()) {
                        showAllBoard();
                    }
                }
                scrollX = 0;
                scrollY = 0;
                level = 0;
                adjustVolume = false;
                adjustBrightness = false;
                break;
            case MotionEvent.ACTION_DOWN:
                lastX = motionEvent.getRawX();
                lastY = motionEvent.getRawY();
                if (motionEvent.getRawX() > screenWidth / 2 + 150) {
                    adjustVolume = true;
                    adjustBrightness = false;
                } else if (motionEvent.getRawX() < screenWidth / 2 - 150) {
                    adjustBrightness = true;
                    adjustVolume = false;
                }
                break;
            case MotionEvent.ACTION_MOVE:
                if (adjustProgress) {
                    break;
                }
                if (Math.abs(motionEvent.getRawY() - lastY) > Math.abs(motionEvent.getRawX() - lastX)) {

                    AudioManager audioManager = (AudioManager) mAppContext
                            .getSystemService(Context.AUDIO_SERVICE);
                    if (motionEvent.getRawY() > lastY) {
                        level += motionEvent.getRawY() - lastY;
                        if (level > slop) {
                            if (adjustVolume) {
                                audioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC,
                                        AudioManager.ADJUST_LOWER, AudioManager.FLAG_SHOW_UI);
                            } else if (adjustBrightness) {
                                float brightness = ScreenUtil.getScreenBrightness((Activity) context);
                                if (brightness <= 0.1f) {
                                    ScreenUtil.setScreenBrightness((Activity) context, 0.0f);
                                } else {
                                    ScreenUtil.setScreenBrightness((Activity) context,
                                            ScreenUtil.getScreenBrightness((Activity) context) - 0.1f);
                                }
                            }
                            level = 0;
                        }
                    } else {
                        level += lastY - motionEvent.getRawY();
                        if (level > slop) {
                            if (adjustVolume) {
                                audioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC,
                                        AudioManager.ADJUST_RAISE, AudioManager.FLAG_SHOW_UI);
                            } else if (adjustBrightness) {
                                float brightness = ScreenUtil.getScreenBrightness((Activity) context);
                                if (brightness >= 0.9f) {
                                    ScreenUtil.setScreenBrightness((Activity) context, 1.0f);
                                } else {
                                    ScreenUtil.setScreenBrightness((Activity) context,
                                            ScreenUtil.getScreenBrightness((Activity) context) + 0.1f);
                                }
                            }
                            level = 0;
                        }
                    }
                }
                lastX = motionEvent.getRawX();
                lastY = motionEvent.getRawY();
                break;
            }

            return gestureDetector.onTouchEvent(motionEvent);
        }
    });
}

From source file:com.android.screenspeak.eventprocessor.ProcessorVolumeStream.java

private void adjustVolumeFromKeyEvent(int button) {
    final int direction = ((button == VolumeButtonPatternDetector.VOLUME_UP) ? AudioManager.ADJUST_RAISE
            : AudioManager.ADJUST_LOWER);

    if (mTouchingScreen) {
        mAudioManager.adjustStreamVolume(STREAM_TOUCHING_SCREEN, direction, DEFAULT_FLAGS_TOUCHING_SCREEN);
    } else {/*from   w ww  . ja v a2s .c o  m*/
        // Attempt to adjust the suggested stream, but let the system
        // override in special situations like during voice calls, when an
        // application has locked the volume control stream, or when music
        // is playing.
        mAudioManager.adjustSuggestedStreamVolume(direction, STREAM_DEFAULT, DEFAULT_FLAGS_NOT_TOUCHING_SCREEN);
    }
}