Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d1f66c6d authored by Sal Savage's avatar Sal Savage Committed by android-build-merger
Browse files

Merge "Allow subsequent requests for media keys to replay the silent audio sample"

am: 5dd3eb8d

Change-Id: Ie1f6de9a4935850445ba49be0274fee0cac7da15
parents ca447812 5dd3eb8d
Loading
Loading
Loading
Loading
+24 −23
Original line number Diff line number Diff line
@@ -249,9 +249,6 @@ public class A2dpSinkStreamHandler extends Handler {
        if (mAudioFocus != AudioManager.AUDIOFOCUS_GAIN) {
            requestAudioFocus();
        }
        // On the off change mMediaPlayer errors out and dies, we want to make sure we retry this.
        // This function immediately exits if we have a MediaPlayer object.
        requestMediaKeyFocus();
    }

    private synchronized int requestAudioFocus() {
@@ -278,8 +275,11 @@ public class A2dpSinkStreamHandler extends Handler {
    }

    /**
     * Creates a MediaPlayer that plays a silent audio sample so that MediaSessionService will be
     * aware of the fact that Bluetooth is playing audio.
     * Plays a silent audio sample so that MediaSessionService will be aware of the fact that
     * Bluetooth is playing audio.
     *
     * Creates a new MediaPlayer if one does not already exist. Repeat calls to this function are
     * safe and will result in the silent audio sample again.
     *
     * This allows the MediaSession in AVRCP Controller to be routed media key events, if we've
     * chosen to use it.
@@ -287,8 +287,7 @@ public class A2dpSinkStreamHandler extends Handler {
    private synchronized void requestMediaKeyFocus() {
        if (DBG) Log.d(TAG, "requestMediaKeyFocus()");

        if (mMediaPlayer != null) return;

        if (mMediaPlayer == null) {
            AudioAttributes attrs = new AudioAttributes.Builder()
                    .setUsage(AudioAttributes.USAGE_MEDIA)
                    .build();
@@ -306,6 +305,7 @@ public class A2dpSinkStreamHandler extends Handler {
                releaseMediaKeyFocus();
                return false;
            });
        }

        mMediaPlayer.start();
        BluetoothMediaBrowserService.setActive(true);
@@ -314,7 +314,6 @@ public class A2dpSinkStreamHandler extends Handler {
    private synchronized void abandonAudioFocus() {
        if (DBG) Log.d(TAG, "abandonAudioFocus()");
        stopFluorideStreaming();
        releaseMediaKeyFocus();
        mAudioManager.abandonAudioFocus(mAudioFocusListener);
        mAudioFocus = AudioManager.AUDIOFOCUS_NONE;
    }
@@ -337,9 +336,11 @@ public class A2dpSinkStreamHandler extends Handler {
    private void startFluorideStreaming() {
        mA2dpSinkService.informAudioFocusStateNative(STATE_FOCUS_GRANTED);
        mA2dpSinkService.informAudioTrackGainNative(1.0f);
        requestMediaKeyFocus();
    }

    private void stopFluorideStreaming() {
        releaseMediaKeyFocus();
        mA2dpSinkService.informAudioFocusStateNative(STATE_FOCUS_LOST);
    }