-
Notifications
You must be signed in to change notification settings - Fork 465
Add support to make AndroidForegroundService optional to MediaElement #2658
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
base: main
Are you sure you want to change the base?
Changes from all commits
14eab7b
44a9928
c683d61
0feee28
f6407f6
63ad21b
1e60956
5a3c0fe
904ae95
ea35514
cecaf32
178e8ae
25b22c6
1168302
838d9a5
7aba464
a83de86
ed62a22
84b337c
58e07a8
cb63525
54830f8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -228,6 +228,8 @@ internal event EventHandler StopRequested | |||||
| /// </summary> | ||||||
| public AndroidViewType AndroidViewType { get; init; } = MediaElementOptions.DefaultAndroidViewType; | ||||||
|
|
||||||
| internal bool IsAndroidForegroundServiceEnabled { get; init; } = MediaElementOptions.IsAndroidForegroundServiceEnabled; | ||||||
|
||||||
| internal bool IsAndroidForegroundServiceEnabled { get; init; } = MediaElementOptions.IsAndroidForegroundServiceEnabled; | |
| public bool IsAndroidForegroundServiceEnabled { get; init; } = MediaElementOptions.IsAndroidForegroundServiceEnabled; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,8 +26,19 @@ internal MediaElementOptions(in MauiAppBuilder builder) : this() | |
| /// </summary> | ||
| internal static AndroidViewType DefaultAndroidViewType { get; private set; } = AndroidViewType.SurfaceView; | ||
|
|
||
| /// <summary> | ||
| /// Set Android Foreground Service for MediaElement on construction | ||
| /// </summary> | ||
|
Comment on lines
+29
to
+31
|
||
| internal static bool IsAndroidForegroundServiceEnabled { get; private set; } = true; | ||
|
|
||
| /// <summary> | ||
| /// Set Android View type for MediaElement as SurfaceView or TextureView on construction | ||
| /// </summary> | ||
| public void SetDefaultAndroidViewType(AndroidViewType androidViewType) => DefaultAndroidViewType = androidViewType; | ||
|
|
||
| /// <summary> | ||
| /// Set Android Foreground Service for MediaElement on construction | ||
| /// </summary> | ||
| /// <param name="androidForegroundServiceEnabled">Specifies whether the Android Foreground Service should be enabled for the MediaElement. Set to <c>true</c> to enable, or <c>false</c> to disable.</param> | ||
| public void SetDefaultAndroidForegroundService(bool androidForegroundServiceEnabled) => IsAndroidForegroundServiceEnabled = androidForegroundServiceEnabled; | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -21,6 +21,7 @@ namespace CommunityToolkit.Maui.Core.Views; | |||||
|
|
||||||
| public partial class MediaManager : Java.Lang.Object, IPlayerListener | ||||||
| { | ||||||
| bool androidForegroundServiceEnabled; | ||||||
|
||||||
| bool androidForegroundServiceEnabled; | |
| readonly bool androidForegroundServiceEnabled; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -166,5 +166,24 @@ public void UseMauiCommunityToolkitMediaElement_ShouldSetDefaultAndroidViewType( | |
|
|
||
| MediaElementOptions.DefaultAndroidViewType.Should().Be(AndroidViewType.TextureView); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void UseMauiCommunityToolkitMediaElement_ShouldSetAndroidServiceByDefault() | ||
| { | ||
| var builder = MauiApp.CreateBuilder(); | ||
| builder.UseMauiCommunityToolkitMediaElement(); | ||
| MediaElementOptions.IsAndroidForegroundServiceEnabled.Should().Be(true); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void UseMauiCommunityToolkitMediaElement_ServiceCanBeDisabled() | ||
| { | ||
| var builder = MauiApp.CreateBuilder(); | ||
| builder.UseMauiCommunityToolkitMediaElement(static options => | ||
| { | ||
| options.SetDefaultAndroidForegroundService(false); | ||
| }); | ||
| MediaElementOptions.IsAndroidForegroundServiceEnabled.Should().Be(false); | ||
| } | ||
|
Comment on lines
+179
to
+187
|
||
| } | ||
| #pragma warning restore CA1416 | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing XML documentation for the
IsAndroidForegroundServiceEnabledproperty. Following the pattern used forAndroidViewTypeon line 226-228, this property should have documentation explaining its purpose and that it's set during construction.Add documentation like: