Skip to content

Commit dec248e

Browse files
ne0rrmatrixTheCodeTravelervhugogarciajfversluis
authored
Update MediaElement Transport Controls for Windows (#2329)
* Add custom transport controls and resource dictionary Introduced a new embedded resource, `ResourceDictionary.windows.xaml`, in the `CommunityToolkit.Maui.MediaElement.csproj` project file. Updated `MauiMediaElement.windows.cs`: - Imported new namespaces. - Added `CustomTransportControls` field and methods for loading resource dictionary and applying custom styles. - Updated constructor to load resource dictionary and set custom transport controls. - Added `LoadResourceDictionary`, `ApplyCustomStyle`, and `SetTransportControls` methods. - Updated `Dispose` method to handle custom transport controls. - Removed `OnMediaPlayerElementPointerMoved` method and related code. - Updated `OnFullScreenButtonClick` method to remove fullscreen button references. Updated `MediaManager.windows.cs`: - Disabled `SystemMediaTransportControls` in `CreatePlatformView`. Added `CustomTransportControls` class in `CommunityToolkit.Maui.Primitives`: - Imported necessary namespaces. - Defined `FullScreenButton` property. - Implemented `OnTemplateLoaded` event. - Overrode `OnApplyTemplate` method to add full-screen button. - Added `FullScreenButton_Click` event handler. - Introduced `isFullScreen` field to track full-screen state. * Reorder AppBarSeparator in ResourceDictionary.xaml Moved RightSeparator before PlaybackRateButton in ResourceDictionary.windows.xaml. Added RightSeparator with Height='0', Width='0', and Margin='0,0'. Reordered properties of PlaybackRateButton without changing values. Removed original RightSeparator after PlaybackRateButton. * Re-add and enhance media control styles and templates Re-added various properties and elements to styles and templates in `ResourceDictionary.windows.xaml` to ensure consistent UI appearance and behavior. Added new buttons like `ZoomButton` and `CastButton` to the media controls command bar. Enhanced `customTransportcontrols` and `CommandBarStyle` with additional properties. * Update layout properties and add corner radius to Grid Removed the `UseLayoutRounding` property and adjusted the `Margin` property from `0,0,0,20` to `0,0,0,10`. Added `VerticalContentAlignment` set to `Center` and `VerticalAlignment` set to `Bottom`. Introduced `CornerRadius` of `8,8,8,8` to the `Grid` element in the `ResourceDictionary.windows.xaml` file. * Refactor CustomTransportControls class and clean up code - Cleaned up `using` directives by removing redundant `using CommunityToolkit.Maui.Core;` and reordering the remaining directives. - Changed `CustomTransportControls` class from public sealed to sealed partial. - Removed XML documentation comments for `CustomTransportControls` class and its members. - Changed `FullScreenButton` property from nullable `AppBarButton` with a private setter to non-nullable `AppBarButton` initialized with a new instance. - Removed null check for `FullScreenButton` in `FullScreenButton_Click` method as `FullScreenButton` is no longer nullable. * Fix volume slider bug with Should Mute --------- Co-authored-by: Brandon Minnick <13558917+brminnick@users.noreply.github.com> Co-authored-by: Víctor Hugo García Hernández <vhugogarcia@users.noreply.github.com> Co-authored-by: Gerald Versluis <gerald.versluis@microsoft.com>
1 parent 5979390 commit dec248e

File tree

5 files changed

+920
-62
lines changed

5 files changed

+920
-62
lines changed

src/CommunityToolkit.Maui.MediaElement/CommunityToolkit.Maui.MediaElement.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,9 @@
8181
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" Condition=" '$(Configuration)'=='Release' " PrivateAssets="All" />
8282
</ItemGroup>
8383

84+
<ItemGroup>
85+
<EmbeddedResource Include="ResourceDictionary.windows.xaml">
86+
<LogicalName>ResourceDictionary.windows.xaml</LogicalName>
87+
</EmbeddedResource>
88+
</ItemGroup>
8489
</Project>
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using Microsoft.UI.Xaml;
2+
using Microsoft.UI.Xaml.Controls;
3+
namespace CommunityToolkit.Maui.Primitives;
4+
5+
sealed partial class CustomTransportControls : MediaTransportControls
6+
{
7+
public event EventHandler<EventArgs>? OnTemplateLoaded;
8+
public AppBarButton FullScreenButton = new();
9+
bool isFullScreen = false;
10+
11+
public CustomTransportControls()
12+
{
13+
this.DefaultStyleKey = typeof(CustomTransportControls);
14+
}
15+
16+
protected override void OnApplyTemplate()
17+
{
18+
base.OnApplyTemplate();
19+
20+
var temp = GetTemplateChild("FullWindowButton") as AppBarButton;
21+
if(temp is not null)
22+
{
23+
FullScreenButton = temp;
24+
FullScreenButton.Visibility = Microsoft.UI.Xaml.Visibility.Visible;
25+
OnTemplateLoaded?.Invoke(this, EventArgs.Empty);
26+
FullScreenButton.Click += FullScreenButton_Click;
27+
}
28+
}
29+
30+
void FullScreenButton_Click(object sender, RoutedEventArgs e)
31+
{
32+
if (isFullScreen)
33+
{
34+
FullScreenButton.Icon = new FontIcon { Glyph = "\uE740" };
35+
isFullScreen = false;
36+
}
37+
else
38+
{
39+
FullScreenButton.Icon = new SymbolIcon(Symbol.BackToWindow);
40+
isFullScreen = true;
41+
}
42+
}
43+
}

0 commit comments

Comments
 (0)