Loading android/app/src/com/android/bluetooth/a2dpsink/A2dpSinkStreamHandler.java +24 −23 Original line number Diff line number Diff line Loading @@ -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() { Loading @@ -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. Loading @@ -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(); Loading @@ -306,6 +305,7 @@ public class A2dpSinkStreamHandler extends Handler { releaseMediaKeyFocus(); return false; }); } mMediaPlayer.start(); BluetoothMediaBrowserService.setActive(true); Loading @@ -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; } Loading @@ -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); } Loading Loading
android/app/src/com/android/bluetooth/a2dpsink/A2dpSinkStreamHandler.java +24 −23 Original line number Diff line number Diff line Loading @@ -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() { Loading @@ -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. Loading @@ -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(); Loading @@ -306,6 +305,7 @@ public class A2dpSinkStreamHandler extends Handler { releaseMediaKeyFocus(); return false; }); } mMediaPlayer.start(); BluetoothMediaBrowserService.setActive(true); Loading @@ -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; } Loading @@ -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); } Loading