Skip to content

Commit 44a9928

Browse files
committed
Rename foreground service property for clarity
Renamed `AndroidForegroundServiceEnabled` to `IsAndroidForegroundServiceEnabled` across multiple files, including XAML, C#, and shared code. Updated the default value for the foreground service option to true in `MediaElementOptions`. Added unit tests to verify the default behavior and the ability to disable the foreground service setting. These changes improve clarity and maintainability by standardizing the naming convention.
1 parent 14eab7b commit 44a9928

File tree

7 files changed

+26
-7
lines changed

7 files changed

+26
-7
lines changed

samples/CommunityToolkit.Maui.Sample/Pages/Views/MediaElement/MediaElementPage.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
<toolkit:MediaElement
3131
x:Name="MediaElement"
3232
ShouldAutoPlay="True"
33-
AndroidForegroundServiceEnabled="True"
33+
IsAndroidForegroundServiceEnabled="True"
3434
Source="{x:Static constants:StreamingVideoUrls.BuckBunny}"
3535
MetadataArtworkUrl="https://lh3.googleusercontent.com/pw/AP1GczNRrebWCJvfdIau1EbsyyYiwAfwHS0JXjbioXvHqEwYIIdCzuLodQCZmA57GADIo5iB3yMMx3t_vsefbfoHwSg0jfUjIXaI83xpiih6d-oT7qD_slR0VgNtfAwJhDBU09kS5V2T5ZML-WWZn8IrjD4J-g=w1792-h1024-s-no-gm"
3636
MetadataTitle="Big Buck Bunny"

samples/CommunityToolkit.Maui.Sample/Pages/Views/MediaElement/MediaElementPage.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ void DisplayPopup(object sender, EventArgs e)
250250
{
251251
AndroidViewType = AndroidViewType.SurfaceView,
252252
Source = MediaSource.FromResource("AppleVideo.mp4"),
253-
AndroidForegroundServiceEnabled = false,
253+
IsAndroidForegroundServiceEnabled = false,
254254
HeightRequest = 600,
255255
WidthRequest = 600,
256256
ShouldAutoPlay = true,

src/CommunityToolkit.Maui.MediaElement/AppBuilderExtensions.shared.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public static MauiAppBuilder UseMauiCommunityToolkitMediaElement(this MauiAppBui
2525
{
2626
// Update the default MediaElementOptions for MediaElement if Action is not null
2727
options?.Invoke(new MediaElementOptions(builder));
28-
28+
2929
// Perform Handler configuration
3030
builder.ConfigureMauiHandlers(h =>
3131
{

src/CommunityToolkit.Maui.MediaElement/Handlers/MediaElementHandler.android.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ protected override MauiMediaElement CreatePlatformView()
2424
VirtualView,
2525
Dispatcher.GetForCurrentThread() ?? throw new InvalidOperationException($"{nameof(IDispatcher)} cannot be null"));
2626

27-
var (_, playerView) = MediaManager.CreatePlatformView(VirtualView.AndroidViewType, VirtualView.AndroidForegroundServiceEnabled);
27+
var (_, playerView) = MediaManager.CreatePlatformView(VirtualView.AndroidViewType, VirtualView.IsAndroidForegroundServiceEnabled);
2828
return new(Context, playerView);
2929
}
3030

src/CommunityToolkit.Maui.MediaElement/MediaElement.shared.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ internal event EventHandler StopRequested
228228
/// <summary>
229229
/// Gets or sets whether the Android Foreground Service is enabled.
230230
/// </summary>
231-
public bool AndroidForegroundServiceEnabled { get; init; } = MediaElementOptions.AndroidForeServiceEnabled;
231+
public bool IsAndroidForegroundServiceEnabled { get; init; } = MediaElementOptions.AndroidForegroundServiceEnabled;
232232

233233
/// <summary>
234234
/// Gets or sets whether the media should start playing as soon as it's loaded.

src/CommunityToolkit.Maui.MediaElement/MediaElementOptions.shared.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ internal MediaElementOptions(in MauiAppBuilder builder) : this()
2020
/// <summary>
2121
/// Set Android Foreground Service for MediaElement on construction
2222
/// </summary>
23-
internal static bool AndroidForeServiceEnabled { get; private set; } = true;
23+
internal static bool AndroidForegroundServiceEnabled { get; private set; } = true;
2424

2525
/// <summary>
2626
/// Set Android View type for MediaElement as SurfaceView or TextureView on construction
@@ -31,5 +31,5 @@ internal MediaElementOptions(in MauiAppBuilder builder) : this()
3131
/// Set Android Foreground Service for MediaElement on construction
3232
/// </summary>
3333
/// <param name="androidForegroundServiceEnabled"></param>
34-
public void SetDefaultAndroidForegroundService(bool androidForegroundServiceEnabled) => AndroidForeServiceEnabled = androidForegroundServiceEnabled;
34+
public void SetDefaultAndroidForegroundService(bool androidForegroundServiceEnabled) => AndroidForegroundServiceEnabled = androidForegroundServiceEnabled;
3535
}

src/CommunityToolkit.Maui.UnitTests/Extensions/AppBuilderExtensionsTests.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,5 +139,24 @@ public void UseMauiCommunityToolkitMediaElement_ShouldSetDefaultAndroidViewType(
139139

140140
MediaElementOptions.DefaultAndroidViewType.Should().Be(AndroidViewType.TextureView);
141141
}
142+
143+
[Fact]
144+
public void UseMauiCommunityToolkitMediaElement_ShouldSetAndroidServiceByDefault()
145+
{
146+
var builder = MauiApp.CreateBuilder();
147+
builder.UseMauiCommunityToolkitMediaElement();
148+
MediaElementOptions.AndroidForegroundServiceEnabled.Should().Be(true);
149+
}
150+
151+
[Fact]
152+
public void UseMauiCommunityToolkitMediaElement_ServiceCanBeDisabled()
153+
{
154+
var builder = MauiApp.CreateBuilder();
155+
builder.UseMauiCommunityToolkitMediaElement(static options =>
156+
{
157+
options.SetDefaultAndroidForegroundService(false);
158+
});
159+
MediaElementOptions.AndroidForegroundServiceEnabled.Should().Be(false);
160+
}
142161
}
143162
#pragma warning restore CA1416

0 commit comments

Comments
 (0)