Java Code Examples for android.media.AudioManager#FLAG_SHOW_UI

The following examples show how to use android.media.AudioManager#FLAG_SHOW_UI . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HdmiControlService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
void setAudioStatus(boolean mute, int volume) {
    if (!isTvDeviceEnabled() || !tv().isSystemAudioActivated()) {
        return;
    }
    AudioManager audioManager = getAudioManager();
    boolean muted = audioManager.isStreamMute(AudioManager.STREAM_MUSIC);
    if (mute) {
        if (!muted) {
            audioManager.setStreamMute(AudioManager.STREAM_MUSIC, true);
        }
    } else {
        if (muted) {
            audioManager.setStreamMute(AudioManager.STREAM_MUSIC, false);
        }
        // FLAG_HDMI_SYSTEM_AUDIO_VOLUME prevents audio manager from announcing
        // volume change notification back to hdmi control service.
        int flag = AudioManager.FLAG_HDMI_SYSTEM_AUDIO_VOLUME;
        if (0 <= volume && volume <= 100) {
            Slog.i(TAG, "volume: " + volume);
            flag |= AudioManager.FLAG_SHOW_UI;
            audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, volume, flag);
        }
    }
}
 
Example 2
Source File: MediaSessionService.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
private void dispatchVolumeKeyEventLocked(String packageName, int pid, int uid,
        boolean asSystemService, KeyEvent keyEvent, int stream, boolean musicOnly) {
    boolean down = keyEvent.getAction() == KeyEvent.ACTION_DOWN;
    boolean up = keyEvent.getAction() == KeyEvent.ACTION_UP;
    int direction = 0;
    boolean isMute = false;
    switch (keyEvent.getKeyCode()) {
        case KeyEvent.KEYCODE_VOLUME_UP:
            direction = AudioManager.ADJUST_RAISE;
            break;
        case KeyEvent.KEYCODE_VOLUME_DOWN:
            direction = AudioManager.ADJUST_LOWER;
            break;
        case KeyEvent.KEYCODE_VOLUME_MUTE:
            isMute = true;
            break;
    }
    if (down || up) {
        int flags = AudioManager.FLAG_FROM_KEY;
        if (musicOnly) {
            // This flag is used when the screen is off to only affect active media.
            flags |= AudioManager.FLAG_ACTIVE_MEDIA_ONLY;
        } else {
            // These flags are consistent with the home screen
            if (up) {
                flags |= AudioManager.FLAG_PLAY_SOUND | AudioManager.FLAG_VIBRATE;
            } else {
                flags |= AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_VIBRATE;
            }
        }
        if (direction != 0) {
            // If this is action up we want to send a beep for non-music events
            if (up) {
                direction = 0;
            }
            dispatchAdjustVolumeLocked(packageName, pid, uid, asSystemService, stream,
                    direction, flags);
        } else if (isMute) {
            if (down && keyEvent.getRepeatCount() == 0) {
                dispatchAdjustVolumeLocked(packageName, pid, uid, asSystemService, stream,
                        AudioManager.ADJUST_TOGGLE_MUTE, flags);
            }
        }
    }
}