Add Android initial audio session options#1117
Merged
Merged
Conversation
Pass initial audio session options into Android WebRTC initialization, use them as the default Android automatic session policy, rename the media preset to mediaPlayback, and avoid sticky speaker routing when updating route preference.
This comment has been minimized.
This comment has been minimized.
cloudwebrtc
approved these changes
Jun 19, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds Android startup-time audio session configuration so apps can set WebRTC’s initialization-time playout AudioAttributes (e.g., media vs voice) before the WebRTC audio device module is created, while also seeding LiveKit’s automatic Android session policy from the same initial intent.
Changes:
- Add
LiveKitClient.initialize(initialAudioSessionOptions: ...)and plumb it intortc.WebRTC.initialize(...)options via a new internal helper. - Seed
AudioManager’s automatic Android policy from initialization options and update Android policy resolution to use currentAudioSessionOptions. - Rename the media preset constructor to
AudioSessionOptions.mediaPlayback(), update docs/tests, and adjust Android speaker routing to avoid sticky device selection.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| test/audio/audio_session_test.dart | Updates preset naming and adds coverage for seeding initial options + WebRTC init options mapping. |
| lib/src/support/webrtc_initialize_options.dart | New internal builder for flutter_webrtc initialize options, including Android audio configuration. |
| lib/src/livekit.dart | Extends LiveKitClient.initialize with initialAudioSessionOptions and seeds AudioManager on Android. |
| lib/src/audio/audio_session.dart | Renames the media preset constructor to mediaPlayback(). |
| lib/src/audio/audio_session_policy.dart | Changes Android automatic policy resolution to use current options.android. |
| lib/src/audio/audio_manager.dart | Adds internal setInitialAudioSessionOptions to seed automatic-mode intent without switching to manual. |
| docs/audio.md | Documents Android timing differences and how to use initialization-time media playback intent. |
| android/src/main/kotlin/io/livekit/plugin/LKAudioSwitchManager.kt | Updates speaker routing to rely on preferred device list and avoid sticky selections. |
| .changes/android-media-routing | Changelog entries for Android initialization audio attributes, default policy seeding, and routing behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
robbysneller
pushed a commit
to robbysneller/client-sdk-flutter-no-pub
that referenced
this pull request
Jun 22, 2026
## Summary - Add `LiveKitClient.initialize(initialAudioSessionOptions: ...)` for Android WebRTC audio-device initialization. - Seed Android automatic audio-session policy from the same initial options so playback-first apps do not need to immediately call `AudioManager.setAudioSessionOptions(...)` with the same preset. - Rename the playback preset to `AudioSessionOptions.mediaPlayback()` for clearer intent. - Avoid sticky Android speaker routing when updating speaker preference. - Update audio session docs and change entry. ## Runtime behavior Android uses `AudioSessionOptions` in two places with different timing: | API | Timing | What changes | | --- | --- | --- | | `LiveKitClient.initialize(initialAudioSessionOptions: ...)` | Before WebRTC initializes. | Passes Android audio configuration into flutter_webrtc/WebRTC ADM creation. This is where WebRTC playout `AudioAttributes` such as `usageType` and `contentType` are set. It also seeds LiveKit's automatic Android session policy. | | `AudioManager.instance.setAudioSessionOptions(...)` | Runtime. | Replaces LiveKit's stored session policy, switches to manual management, and applies LiveKit's platform session behavior: Android audio mode, audio focus mode, stream type, focus ownership, routing handler policy, and iOS category/options/mode. | The important Android limitation is that WebRTC playout `AudioAttributes` are still initialization-time configuration. Calling `AudioManager.setAudioSessionOptions(...)` at runtime applies LiveKit's platform session policy, but it does not mutate the `AudioAttributes` on an already-created WebRTC audio device module. For playback-first Android apps that need media volume/routing from WebRTC playout, pass `AudioSessionOptions.mediaPlayback()` to `LiveKitClient.initialize(...)` before connecting. ## Validation - `flutter test --no-pub test/audio/audio_session_test.dart` - `flutter analyze --no-pub --------- Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
LiveKitClient.initialize(initialAudioSessionOptions: ...)for Android WebRTC audio-device initialization.AudioManager.setAudioSessionOptions(...)with the same preset.AudioSessionOptions.mediaPlayback()for clearer intent.Runtime behavior
Android uses
AudioSessionOptionsin two places with different timing:LiveKitClient.initialize(initialAudioSessionOptions: ...)AudioAttributessuch asusageTypeandcontentTypeare set. It also seeds LiveKit's automatic Android session policy.AudioManager.instance.setAudioSessionOptions(...)The important Android limitation is that WebRTC playout
AudioAttributesare still initialization-time configuration. CallingAudioManager.setAudioSessionOptions(...)at runtime applies LiveKit's platform session policy, but it does not mutate theAudioAttributeson an already-created WebRTC audio device module. For playback-first Android apps that need media volume/routing from WebRTC playout, passAudioSessionOptions.mediaPlayback()toLiveKitClient.initialize(...)before connecting.Validation
flutter test --no-pub test/audio/audio_session_test.dart