diff --git a/src/CommunityToolkit.Maui.Analyzers.UnitTests/CommunityToolkit.Maui.Analyzers.UnitTests.csproj b/src/CommunityToolkit.Maui.Analyzers.UnitTests/CommunityToolkit.Maui.Analyzers.UnitTests.csproj
index 0a24dcfce..20c5766db 100644
--- a/src/CommunityToolkit.Maui.Analyzers.UnitTests/CommunityToolkit.Maui.Analyzers.UnitTests.csproj
+++ b/src/CommunityToolkit.Maui.Analyzers.UnitTests/CommunityToolkit.Maui.Analyzers.UnitTests.csproj
@@ -10,7 +10,7 @@
-
+
diff --git a/src/CommunityToolkit.Maui.MediaElement/CommunityToolkit.Maui.MediaElement.csproj b/src/CommunityToolkit.Maui.MediaElement/CommunityToolkit.Maui.MediaElement.csproj
index c3c93f832..d770a5273 100644
--- a/src/CommunityToolkit.Maui.MediaElement/CommunityToolkit.Maui.MediaElement.csproj
+++ b/src/CommunityToolkit.Maui.MediaElement/CommunityToolkit.Maui.MediaElement.csproj
@@ -81,4 +81,9 @@
+
+
+ ResourceDictionary.windows.xaml
+
+
\ No newline at end of file
diff --git a/src/CommunityToolkit.Maui.MediaElement/Primitives/CustomTransportControls.windows.cs b/src/CommunityToolkit.Maui.MediaElement/Primitives/CustomTransportControls.windows.cs
new file mode 100644
index 000000000..fe9c130c8
--- /dev/null
+++ b/src/CommunityToolkit.Maui.MediaElement/Primitives/CustomTransportControls.windows.cs
@@ -0,0 +1,43 @@
+using Microsoft.UI.Xaml;
+using Microsoft.UI.Xaml.Controls;
+namespace CommunityToolkit.Maui.Primitives;
+
+sealed partial class CustomTransportControls : MediaTransportControls
+{
+ public event EventHandler? OnTemplateLoaded;
+ public AppBarButton FullScreenButton = new();
+ bool isFullScreen = false;
+
+ public CustomTransportControls()
+ {
+ this.DefaultStyleKey = typeof(CustomTransportControls);
+ }
+
+ protected override void OnApplyTemplate()
+ {
+ base.OnApplyTemplate();
+
+ var temp = GetTemplateChild("FullWindowButton") as AppBarButton;
+ if(temp is not null)
+ {
+ FullScreenButton = temp;
+ FullScreenButton.Visibility = Microsoft.UI.Xaml.Visibility.Visible;
+ OnTemplateLoaded?.Invoke(this, EventArgs.Empty);
+ FullScreenButton.Click += FullScreenButton_Click;
+ }
+ }
+
+ void FullScreenButton_Click(object sender, RoutedEventArgs e)
+ {
+ if (isFullScreen)
+ {
+ FullScreenButton.Icon = new FontIcon { Glyph = "\uE740" };
+ isFullScreen = false;
+ }
+ else
+ {
+ FullScreenButton.Icon = new SymbolIcon(Symbol.BackToWindow);
+ isFullScreen = true;
+ }
+ }
+}
diff --git a/src/CommunityToolkit.Maui.MediaElement/ResourceDictionary.windows.xaml b/src/CommunityToolkit.Maui.MediaElement/ResourceDictionary.windows.xaml
new file mode 100644
index 000000000..4d1cc2e70
--- /dev/null
+++ b/src/CommunityToolkit.Maui.MediaElement/ResourceDictionary.windows.xaml
@@ -0,0 +1,799 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/CommunityToolkit.Maui.MediaElement/Views/MauiMediaElement.windows.cs b/src/CommunityToolkit.Maui.MediaElement/Views/MauiMediaElement.windows.cs
index bfc472903..6485aaf02 100644
--- a/src/CommunityToolkit.Maui.MediaElement/Views/MauiMediaElement.windows.cs
+++ b/src/CommunityToolkit.Maui.MediaElement/Views/MauiMediaElement.windows.cs
@@ -1,3 +1,4 @@
+using System.Reflection;
using CommunityToolkit.Maui.Extensions;
using CommunityToolkit.Maui.Primitives;
using CommunityToolkit.Maui.Views;
@@ -6,16 +7,11 @@
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
-using Microsoft.UI.Xaml.Input;
-using Microsoft.UI.Xaml.Media;
+using Microsoft.UI.Xaml.Markup;
using WinRT.Interop;
using Application = Microsoft.Maui.Controls.Application;
-using Button = Microsoft.UI.Xaml.Controls.Button;
-using Colors = Microsoft.UI.Colors;
using Grid = Microsoft.UI.Xaml.Controls.Grid;
using Page = Microsoft.Maui.Controls.Page;
-using SolidColorBrush = Microsoft.UI.Xaml.Media.SolidColorBrush;
-using Thickness = Microsoft.UI.Xaml.Thickness;
namespace CommunityToolkit.Maui.Core.Views;
@@ -27,12 +23,8 @@ public partial class MauiMediaElement : Grid, IDisposable
static readonly AppWindow appWindow = GetAppWindowForCurrentWindow();
readonly Popup popup = new();
readonly Grid fullScreenGrid = new();
- readonly Grid buttonContainer;
- readonly Button fullScreenButton;
readonly MediaPlayerElement mediaPlayerElement;
- // Cannot be static readonly because we need to be able to add icon to multiple instances of the button
- readonly FontIcon fullScreenIcon = new() { Glyph = "\uE740", FontFamily = new FontFamily("Segoe Fluent Icons") };
- readonly FontIcon exitFullScreenIcon = new() { Glyph = "\uE73F", FontFamily = new FontFamily("Segoe Fluent Icons") };
+ readonly CustomTransportControls? customTransportControls;
bool doesNavigationBarExistBeforeFullScreen;
bool isDisposed;
@@ -42,33 +34,73 @@ public partial class MauiMediaElement : Grid, IDisposable
///
public MauiMediaElement(MediaPlayerElement mediaPlayerElement)
{
+ LoadResourceDictionary();
this.mediaPlayerElement = mediaPlayerElement;
+ customTransportControls = SetTransportControls();
+ Children.Add(this.mediaPlayerElement);
+ }
- fullScreenButton = new Button
+ void LoadResourceDictionary()
+ {
+ var assembly = Assembly.GetExecutingAssembly();
+ using Stream? stream = assembly.GetManifestResourceStream("ResourceDictionary.windows.xaml");
+ if (stream is null)
{
- Content = fullScreenIcon,
- Background = new SolidColorBrush(Colors.Transparent),
- Width = 45,
- Height = 45
- };
+ return;
+ }
+ using StreamReader reader = new(stream);
+ var xaml = reader.ReadToEnd();
+ var resourceDictionary = (Microsoft.UI.Xaml.ResourceDictionary)XamlReader.Load(xaml);
+ if (resourceDictionary is null)
+ {
+ return;
+ }
+ this.Resources.MergedDictionaries.Add(resourceDictionary);
+ }
+ void ApplyCustomStyle()
+ {
+ if (this.Resources.TryGetValue("customTransportcontrols", out object styleObj) &&
+ styleObj is Microsoft.UI.Xaml.Style customStyle && mediaPlayerElement is not null && mediaPlayerElement.TransportControls is not null)
+ {
+ mediaPlayerElement.TransportControls.Style = customStyle;
+ }
+ }
- buttonContainer = new Grid
+ CustomTransportControls SetTransportControls()
+ {
+ mediaPlayerElement.TransportControls.IsEnabled = false;
+ var temp = new CustomTransportControls()
{
- HorizontalAlignment = Microsoft.UI.Xaml.HorizontalAlignment.Right,
- VerticalAlignment = Microsoft.UI.Xaml.VerticalAlignment.Top,
- Visibility = mediaPlayerElement.TransportControls.Visibility,
- Width = 45,
- Height = 45,
- Margin = new Thickness(0, 20, 30, 0)
+ IsZoomButtonVisible = true,
+ IsZoomEnabled = true,
+ IsVolumeButtonVisible = true,
+ IsVolumeEnabled = true,
+ IsSeekBarVisible = true,
+ IsSeekEnabled = true,
+ IsEnabled = true,
+ IsRepeatButtonVisible = true,
+ IsRepeatEnabled = true,
+ IsNextTrackButtonVisible = true,
+ IsPreviousTrackButtonVisible = true,
+ IsFastForwardButtonVisible = true,
+ IsFastForwardEnabled = true,
+ IsFastRewindButtonVisible = true,
+ IsFastRewindEnabled = true,
+ IsPlaybackRateButtonVisible = true,
+ IsPlaybackRateEnabled = true,
+ IsCompact = false,
};
-
- fullScreenButton.Click += OnFullScreenButtonClick;
- buttonContainer.Children.Add(fullScreenButton);
-
- Children.Add(this.mediaPlayerElement);
- Children.Add(buttonContainer);
-
- mediaPlayerElement.PointerMoved += OnMediaPlayerElementPointerMoved;
+ temp.OnTemplateLoaded += (s, e) =>
+ {
+ if (temp.FullScreenButton is null)
+ {
+ return;
+ }
+ temp.FullScreenButton.Click += OnFullScreenButtonClick;
+ };
+ mediaPlayerElement.TransportControls = temp;
+ ApplyCustomStyle();
+ return temp;
}
///
@@ -100,9 +132,10 @@ protected virtual void Dispose(bool disposing)
{
return;
}
-
- fullScreenButton.Click -= OnFullScreenButtonClick;
- mediaPlayerElement.PointerMoved -= OnMediaPlayerElementPointerMoved;
+ if (customTransportControls?.FullScreenButton is not null)
+ {
+ customTransportControls.FullScreenButton.Click -= OnFullScreenButtonClick;
+ }
if (disposing)
{
@@ -129,29 +162,9 @@ static AppWindow GetAppWindowForCurrentWindow()
return AppWindow.GetFromWindowId(id);
}
- async void OnMediaPlayerElementPointerMoved(object sender, PointerRoutedEventArgs e)
- {
- e.Handled = true;
- buttonContainer.Visibility = mediaPlayerElement.TransportControls.Visibility;
-
- if (mediaPlayerElement.TransportControls.Visibility == Microsoft.UI.Xaml.Visibility.Collapsed)
- {
- buttonContainer.Visibility = mediaPlayerElement.TransportControls.Visibility;
- return;
- }
-
- mediaPlayerElement.PointerMoved -= OnMediaPlayerElementPointerMoved;
- buttonContainer.Visibility = Microsoft.UI.Xaml.Visibility.Visible;
- await Task.Delay(TimeSpan.FromSeconds(5));
-
- buttonContainer.Visibility = Microsoft.UI.Xaml.Visibility.Collapsed;
- mediaPlayerElement.PointerMoved += OnMediaPlayerElementPointerMoved;
- }
-
void OnFullScreenButtonClick(object sender, RoutedEventArgs e)
{
var currentPage = CurrentPage;
-
if (appWindow.Presenter.Kind is AppWindowPresenterKind.FullScreen)
{
appWindow.SetPresenter(AppWindowPresenterKind.Default);
@@ -163,9 +176,7 @@ void OnFullScreenButtonClick(object sender, RoutedEventArgs e)
popup.Child = null;
fullScreenGrid.Children.Clear();
}
- fullScreenButton.Content = fullScreenIcon;
Children.Add(mediaPlayerElement);
- Children.Add(buttonContainer);
var parent = mediaPlayerElement.Parent as FrameworkElement;
mediaPlayerElement.Width = parent?.Width ?? mediaPlayerElement.Width;
@@ -183,9 +194,7 @@ void OnFullScreenButtonClick(object sender, RoutedEventArgs e)
mediaPlayerElement.Height = displayInfo.Height / displayInfo.Density;
Children.Clear();
- fullScreenButton.Content = exitFullScreenIcon;
fullScreenGrid.Children.Add(mediaPlayerElement);
- fullScreenGrid.Children.Add(buttonContainer);
popup.XamlRoot = mediaPlayerElement.XamlRoot;
popup.HorizontalOffset = 0;
diff --git a/src/CommunityToolkit.Maui.MediaElement/Views/MediaManager.windows.cs b/src/CommunityToolkit.Maui.MediaElement/Views/MediaManager.windows.cs
index 485314cec..a62a32b9a 100644
--- a/src/CommunityToolkit.Maui.MediaElement/Views/MediaManager.windows.cs
+++ b/src/CommunityToolkit.Maui.MediaElement/Views/MediaManager.windows.cs
@@ -60,7 +60,9 @@ public PlatformMediaElement CreatePlatformView()
Player.MediaPlayer.VolumeChanged += OnMediaElementVolumeChanged;
Player.MediaPlayer.IsMutedChanged += OnMediaElementIsMutedChanged;
+ Player.MediaPlayer.SystemMediaTransportControls.IsEnabled = false;
systemMediaControls = Player.MediaPlayer.SystemMediaTransportControls;
+
return Player;
}
@@ -250,12 +252,11 @@ protected virtual partial void PlatformUpdateShouldKeepScreenOn()
protected virtual partial void PlatformUpdateShouldMute()
{
- if (Player?.MediaPlayer is null)
+ if (Player is null)
{
return;
}
-
- Player.MediaPlayer.IsMuted = MediaElement.ShouldMute;
+ Dispatcher.Dispatch(() => Player.MediaPlayer.IsMuted = MediaElement.ShouldMute);
}
protected virtual async partial ValueTask PlatformUpdateSource()
diff --git a/src/CommunityToolkit.Maui.UnitTests/CommunityToolkit.Maui.UnitTests.csproj b/src/CommunityToolkit.Maui.UnitTests/CommunityToolkit.Maui.UnitTests.csproj
index 158e359f9..10fa0064f 100644
--- a/src/CommunityToolkit.Maui.UnitTests/CommunityToolkit.Maui.UnitTests.csproj
+++ b/src/CommunityToolkit.Maui.UnitTests/CommunityToolkit.Maui.UnitTests.csproj
@@ -9,7 +9,7 @@
-
+