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

Commit 14a3049f authored by Automerger Merge Worker's avatar Automerger Merge Worker
Browse files

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

Merge "Allow subsequent requests for media keys to replay the silent audio sample" am: 969c68c5 am: caf9d041

Change-Id: Id5685a6fa190e7b8dec694a341b6b5c052cc839e
parents f2e2ac1d caf9d041
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);
    }