-
-
Notifications
You must be signed in to change notification settings - Fork 60
Add audio output device/port selection for Android and iOS/macOS #191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Copilot
wants to merge
10
commits into
main
Choose a base branch
from
copilot/add-audio-output-selection
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
1a68888
Initial plan
Copilot 0fc6eb0
Add audio output device selection for Android
Copilot b5a14f3
Fix documentation references and API level comments
Copilot e3b0ba9
Extract audio attributes configuration into shared method
Copilot 9842109
Standardize initialization order across all constructors
Copilot f4c1475
Add iOS/macOS audio output port override support
Copilot 1de9db7
Fix AudioOutputPort enum type to ulong for iOS/macOS
Copilot df9c0be
Address code review feedback - fix whitespace, remove unnecessary pra…
Copilot dc3f307
Update docs/audio-player.md
jfversluis b9a37b9
Merge branch 'main' into copilot/add-audio-output-selection
jfversluis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
75 changes: 75 additions & 0 deletions
75
src/Plugin.Maui.Audio/AudioPlayer/AudioOutputDevice.android.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| using System.Runtime.Versioning; | ||
| using Android.Media; | ||
|
|
||
| namespace Plugin.Maui.Audio; | ||
|
|
||
| /// <summary> | ||
| /// Specifies the preferred audio output device type for Android. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// This enum is used to specify which audio output device should be preferred for playback. | ||
| /// Requires Android API 28 (Android 9.0 Pie) or higher for setting the preferred device. | ||
| /// On older versions, this setting will be ignored and the system default routing will be used. | ||
| /// </remarks> | ||
| [SupportedOSPlatform("android23.0")] | ||
| public enum AudioOutputDevice | ||
| { | ||
| /// <summary> | ||
| /// Use the system default audio output device. No preferred device will be set. | ||
| /// </summary> | ||
| Default = 0, | ||
|
|
||
| /// <summary> | ||
| /// Route audio to the built-in device speaker (typically the loudspeaker). | ||
| /// Corresponds to <see cref="AudioDeviceType.BuiltinSpeaker"/>. | ||
| /// </summary> | ||
| Speaker = AudioDeviceType.BuiltinSpeaker, | ||
|
|
||
| /// <summary> | ||
| /// Route audio to the built-in earpiece (typically used for phone calls). | ||
| /// Corresponds to <see cref="AudioDeviceType.BuiltinEarpiece"/>. | ||
| /// </summary> | ||
| Earpiece = AudioDeviceType.BuiltinEarpiece, | ||
|
|
||
| /// <summary> | ||
| /// Route audio to a wired headset or headphones. | ||
| /// Corresponds to <see cref="AudioDeviceType.WiredHeadset"/>. | ||
| /// </summary> | ||
| WiredHeadset = AudioDeviceType.WiredHeadset, | ||
|
|
||
| /// <summary> | ||
| /// Route audio to a wired headphone device. | ||
| /// Corresponds to <see cref="AudioDeviceType.WiredHeadphones"/>. | ||
| /// </summary> | ||
| WiredHeadphones = AudioDeviceType.WiredHeadphones, | ||
|
|
||
| /// <summary> | ||
| /// Route audio to a Bluetooth device with A2DP profile (e.g., Bluetooth headphones, car audio). | ||
| /// Corresponds to <see cref="AudioDeviceType.BluetoothA2dp"/>. | ||
| /// </summary> | ||
| BluetoothA2dp = AudioDeviceType.BluetoothA2dp, | ||
|
|
||
| /// <summary> | ||
| /// Route audio to a Bluetooth SCO (Synchronous Connection Oriented) device (typically used for phone calls). | ||
| /// Corresponds to <see cref="AudioDeviceType.BluetoothSco"/>. | ||
| /// </summary> | ||
| BluetoothSco = AudioDeviceType.BluetoothSco, | ||
|
|
||
| /// <summary> | ||
| /// Route audio to an auxiliary line connection (e.g., 3.5mm aux cable). | ||
| /// Corresponds to <see cref="AudioDeviceType.AuxLine"/>. | ||
| /// </summary> | ||
| AuxLine = AudioDeviceType.AuxLine, | ||
|
|
||
| /// <summary> | ||
| /// Route audio to a USB audio device. | ||
| /// Corresponds to <see cref="AudioDeviceType.UsbDevice"/>. | ||
| /// </summary> | ||
| UsbDevice = AudioDeviceType.UsbDevice, | ||
|
|
||
| /// <summary> | ||
| /// Route audio to a USB accessory. | ||
| /// Corresponds to <see cref="AudioDeviceType.UsbAccessory"/>. | ||
| /// </summary> | ||
| UsbAccessory = AudioDeviceType.UsbAccessory, | ||
| } |
26 changes: 26 additions & 0 deletions
26
src/Plugin.Maui.Audio/AudioPlayer/AudioOutputPort.macios.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| using AVFoundation; | ||
|
|
||
| namespace Plugin.Maui.Audio; | ||
|
|
||
| /// <summary> | ||
| /// Specifies the preferred audio output port override for iOS/macOS. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// This enum controls audio routing on iOS/macOS platforms using AVAudioSession. | ||
| /// Unlike Android's device-specific routing, iOS uses a session-wide port override that affects all audio. | ||
| /// </remarks> | ||
| public enum AudioOutputPort : ulong | ||
| { | ||
| /// <summary> | ||
| /// Use the default audio routing behavior. The system will route audio based on connected devices. | ||
| /// Corresponds to <see cref="AVAudioSessionPortOverride.None"/>. | ||
| /// </summary> | ||
| Default = AVAudioSessionPortOverride.None, | ||
|
|
||
| /// <summary> | ||
| /// Force audio output to the built-in speaker, overriding the default routing. | ||
| /// Use this to ensure audio plays through the device speaker even when headphones or Bluetooth devices are connected. | ||
| /// Corresponds to <see cref="AVAudioSessionPortOverride.Speaker"/>. | ||
| /// </summary> | ||
| Speaker = AVAudioSessionPortOverride.Speaker, | ||
| } |
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
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.