Skip to content

Commit 178e8ae

Browse files
committed
Enable Android Foreground Service for MediaElement
Updated the `CreateMauiApp` method to enable the Android foreground service for `MediaElement`. Removed the `IsAndroidForegroundServiceEnabled` property from the XAML definition and set it to `false` in the `DisplayPopup` method. Changed the access level of the `IsAndroidForegroundServiceEnabled` property in `MediaElement.shared.cs` from `public` to `internal` to restrict its visibility.
1 parent 904ae95 commit 178e8ae

File tree

4 files changed

+2
-6
lines changed

4 files changed

+2
-6
lines changed

samples/CommunityToolkit.Maui.Sample/MauiProgram.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public static MauiApp CreateMauiApp()
7070
.UseMauiCommunityToolkitMediaElement(static options =>
7171
{
7272
options.SetDefaultAndroidViewType(AndroidViewType.TextureView);
73+
options.SetDefaultAndroidForegroundService(true);
7374
})
7475
.ConfigureMauiHandlers(static handlers =>
7576
{

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

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

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,6 @@ async void DisplayPopup(object sender, EventArgs e)
275275
var popupMediaElement = new MediaElement
276276
{
277277
AndroidViewType = AndroidViewType.SurfaceView,
278-
IsAndroidForegroundServiceEnabled = false,
279278
Source = source,
280279
MetadataArtworkUrl = "dotnet_bot.png",
281280
ShouldAutoPlay = true,

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,7 @@ internal event EventHandler StopRequested
225225
/// </summary>
226226
public AndroidViewType AndroidViewType { get; init; } = MediaElementOptions.DefaultAndroidViewType;
227227

228-
/// <summary>
229-
/// Gets or sets whether the Android Foreground Service is enabled.
230-
/// </summary>
231-
public bool IsAndroidForegroundServiceEnabled { get; init; } = MediaElementOptions.IsAndroidForegroundServiceEnabled;
228+
internal bool IsAndroidForegroundServiceEnabled { get; init; } = MediaElementOptions.IsAndroidForegroundServiceEnabled;
232229

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

0 commit comments

Comments
 (0)