Example usage for android.media AudioManager AUDIOFOCUS_REQUEST_DELAYED

List of usage examples for android.media AudioManager AUDIOFOCUS_REQUEST_DELAYED

Introduction

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

Prototype

int AUDIOFOCUS_REQUEST_DELAYED

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

Click Source Link

Document

A focus change request whose granting is delayed: the request was successful, but the requester will only be granted audio focus once the condition that prevented immediate granting has ended.

Usage

From source file:androidx.media.widget.VideoView2.java

@SuppressWarnings("deprecation")
private void requestAudioFocus(int focusType) {
    int result;/*from  w  w  w .j  a  va2  s . c  om*/
    if (android.os.Build.VERSION.SDK_INT >= 26) {
        AudioFocusRequest focusRequest;
        focusRequest = new AudioFocusRequest.Builder(focusType).setAudioAttributes(mAudioAttributes)
                .setOnAudioFocusChangeListener(mAudioFocusListener).build();
        result = mAudioManager.requestAudioFocus(focusRequest);
    } else {
        result = mAudioManager.requestAudioFocus(mAudioFocusListener, AudioManager.STREAM_MUSIC, focusType);
    }
    if (result == AudioManager.AUDIOFOCUS_REQUEST_FAILED) {
        mAudioFocused = false;
    } else if (result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
        mAudioFocused = true;
    } else if (result == AudioManager.AUDIOFOCUS_REQUEST_DELAYED) {
        mAudioFocused = false;
    }
}