File tree Expand file tree Collapse file tree 7 files changed +26
-7
lines changed Expand file tree Collapse file tree 7 files changed +26
-7
lines changed Original file line number Diff line number Diff line change 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"
Original file line number Diff line number Diff 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 ,
Original file line number Diff line number Diff 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 {
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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.
Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments