Skip to content
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

Add initial media options class and extension #1905

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,33 @@ public static class AppBuilderExtensions
/// Initializes the .NET MAUI Community Toolkit MediaElement Library
/// </summary>
/// <param name="builder"><see cref="MauiAppBuilder"/> generated by <see cref="MauiApp"/>.</param>
/// <param name="configureMediaOptions">
/// The mechanism to define the shared options for use with the <see cref="MediaManager"/> implementations. Note this is optional.
/// An example of configuring the media options for iOS and macOS, is as follows:
/// <code>
/// builder
/// .AddAudio(
/// configureMediaOptions: mediaOptions =>
/// {
///#if IOS || MACCATALYST
/// mediaOptions.Category = AVFoundation.AVAudioSessionCategory.Playback;
/// mediaOptions.Mode = AVFoundation.AVAudioSessionMode.Default;
/// mediaOptions.CategoryOptions = AVFoundation.AVAudioSessionCategoryOptions.DefaultToSpeaker;
///#endif
/// });
/// </code>
/// </param>
/// <returns><see cref="MauiAppBuilder"/> initialized for <see cref="MediaElement"/>.</returns>
public static MauiAppBuilder UseMauiCommunityToolkitMediaElement(this MauiAppBuilder builder)
public static MauiAppBuilder UseMauiCommunityToolkitMediaElement(this MauiAppBuilder builder, Action<MediaOptions>? configureMediaOptions = null)
{
builder.ConfigureMauiHandlers(h =>
{
h.AddHandler<MediaElement, MediaElementHandler>();
});

var mediaOptions = new MediaOptions();
configureMediaOptions?.Invoke(mediaOptions);
MediaManager.DefaultMediaOptions = mediaOptions;

#if ANDROID
builder.Services.AddSingleton<Media.Services.MediaControlsService>();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using AVFoundation;

namespace CommunityToolkit.Maui;

partial class MediaOptions
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would say those Options should be immutable. So we can refactor it to be a record and remove the setters

{
/// <summary>
/// Gets or sets the category for the audio session.
/// </summary>
public AVAudioSessionCategory Category { get; set; } = AVAudioSessionCategory.Record;

/// <summary>
/// Gets or sets the mode for the audio session.
/// </summary>
public AVAudioSessionMode Mode { get; set; } = default;

/// <summary>
/// Gets or sets the options for the audio session category.
/// </summary>
public AVAudioSessionCategoryOptions CategoryOptions { get; set; } = default;

// /// <summary>
// /// Gets or sets the lifetime of the underlying audio session - basically whether the AVAudioSession will stay active or be deactivated.
// /// </summary>
// public SessionLifetime SessionLifetime { get; set; } = default;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace CommunityToolkit.Maui;

/// <summary>
/// Options that can be configured for media playback sessions.
/// </summary>
public partial class MediaOptions
{

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ namespace CommunityToolkit.Maui.Core.Views;
/// </summary>
public partial class MediaManager
{
internal static MediaOptions DefaultMediaOptions { get; set; } = new();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's is fine to be mutable, since users may want to change how options based on the MediaSource. But, it does make sense on the current implementation? The MediaOptions is only configurable on AppBuilder, so it shouldn't change after app startup, right?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Let's make these { get; private set;} for now to follow the same architecture in CommunityToolkit.Maui.Options:

internal static bool ShouldSuppressExceptionsInAnimations { get; private set; }
internal static bool ShouldSuppressExceptionsInConverters { get; private set; }
internal static bool ShouldSuppressExceptionsInBehaviors { get; private set; }
internal static bool ShouldEnableSnackbarOnWindows { get; private set; }

We can always make it a public set; in the future without breaking changes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to add bindable properties so we can use this at runtime for changes with MediaSource ?


/// <summary>
/// Initializes a new instance of the <see cref="MediaManager"/> class.
/// </summary>
Expand Down