From fe1af7b001bc645e214adcf4062851020c19d279 Mon Sep 17 00:00:00 2001 From: Shaun Lawrence <17139988+bijington@users.noreply.github.com> Date: Tue, 28 May 2024 19:26:31 +0100 Subject: [PATCH] Add initial media options class and extension --- .../AppBuilderExtensions.shared.cs | 23 +++++++++++++++- .../Options/MediaOptions.macios.cs | 26 +++++++++++++++++++ .../Options/MediaOptions.shared.cs | 9 +++++++ .../Views/MediaManager.shared.cs | 2 ++ 4 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 src/CommunityToolkit.Maui.MediaElement/Options/MediaOptions.macios.cs create mode 100644 src/CommunityToolkit.Maui.MediaElement/Options/MediaOptions.shared.cs diff --git a/src/CommunityToolkit.Maui.MediaElement/AppBuilderExtensions.shared.cs b/src/CommunityToolkit.Maui.MediaElement/AppBuilderExtensions.shared.cs index 44915efb8a..fa318443c8 100644 --- a/src/CommunityToolkit.Maui.MediaElement/AppBuilderExtensions.shared.cs +++ b/src/CommunityToolkit.Maui.MediaElement/AppBuilderExtensions.shared.cs @@ -1,4 +1,5 @@ using CommunityToolkit.Maui.Core.Handlers; +using CommunityToolkit.Maui.Core.Views; using CommunityToolkit.Maui.Views; namespace CommunityToolkit.Maui; @@ -12,13 +13,33 @@ public static class AppBuilderExtensions /// Initializes the .NET MAUI Community Toolkit MediaElement Library /// /// generated by . + /// + /// The mechanism to define the shared options for use with the implementations. Note this is optional. + /// An example of configuring the media options for iOS and macOS, is as follows: + /// + /// builder + /// .AddAudio( + /// configureMediaOptions: mediaOptions => + /// { + ///#if IOS || MACCATALYST + /// mediaOptions.Category = AVFoundation.AVAudioSessionCategory.Playback; + /// mediaOptions.Mode = AVFoundation.AVAudioSessionMode.Default; + /// mediaOptions.CategoryOptions = AVFoundation.AVAudioSessionCategoryOptions.DefaultToSpeaker; + ///#endif + /// }); + /// + /// /// initialized for . - public static MauiAppBuilder UseMauiCommunityToolkitMediaElement(this MauiAppBuilder builder) + public static MauiAppBuilder UseMauiCommunityToolkitMediaElement(this MauiAppBuilder builder, Action? configureMediaOptions = null) { builder.ConfigureMauiHandlers(h => { h.AddHandler(); }); + + var mediaOptions = new MediaOptions(); + configureMediaOptions?.Invoke(mediaOptions); + MediaManager.DefaultMediaOptions = mediaOptions; return builder; } diff --git a/src/CommunityToolkit.Maui.MediaElement/Options/MediaOptions.macios.cs b/src/CommunityToolkit.Maui.MediaElement/Options/MediaOptions.macios.cs new file mode 100644 index 0000000000..5bdc9e8a72 --- /dev/null +++ b/src/CommunityToolkit.Maui.MediaElement/Options/MediaOptions.macios.cs @@ -0,0 +1,26 @@ +using AVFoundation; + +namespace CommunityToolkit.Maui; + +partial class MediaOptions +{ + /// + /// Gets or sets the category for the audio session. + /// + public AVAudioSessionCategory Category { get; set; } = AVAudioSessionCategory.Record; + + /// + /// Gets or sets the mode for the audio session. + /// + public AVAudioSessionMode Mode { get; set; } = default; + + /// + /// Gets or sets the options for the audio session category. + /// + public AVAudioSessionCategoryOptions CategoryOptions { get; set; } = default; + + // /// + // /// Gets or sets the lifetime of the underlying audio session - basically whether the AVAudioSession will stay active or be deactivated. + // /// + // public SessionLifetime SessionLifetime { get; set; } = default; +} \ No newline at end of file diff --git a/src/CommunityToolkit.Maui.MediaElement/Options/MediaOptions.shared.cs b/src/CommunityToolkit.Maui.MediaElement/Options/MediaOptions.shared.cs new file mode 100644 index 0000000000..9a9e24f3e8 --- /dev/null +++ b/src/CommunityToolkit.Maui.MediaElement/Options/MediaOptions.shared.cs @@ -0,0 +1,9 @@ +namespace CommunityToolkit.Maui; + +/// +/// Options that can be configured for media playback sessions. +/// +public partial class MediaOptions +{ + +} \ No newline at end of file diff --git a/src/CommunityToolkit.Maui.MediaElement/Views/MediaManager.shared.cs b/src/CommunityToolkit.Maui.MediaElement/Views/MediaManager.shared.cs index 253f5beaa8..fe3977ea32 100644 --- a/src/CommunityToolkit.Maui.MediaElement/Views/MediaManager.shared.cs +++ b/src/CommunityToolkit.Maui.MediaElement/Views/MediaManager.shared.cs @@ -19,6 +19,8 @@ namespace CommunityToolkit.Maui.Core.Views; /// public partial class MediaManager { + internal static MediaOptions DefaultMediaOptions { get; set; } = new(); + /// /// Initializes a new instance of the class. ///