Skip to content
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

Update MediaElement Transport Controls for Windows #2329

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

ne0rrmatrix
Copy link
Contributor

@ne0rrmatrix ne0rrmatrix commented Nov 9, 2024

  • Feature/Proposal

Description of Change

Update MediaElement Transport Controls for Windows. Adds Support for Full Screen button in the controls. Controls are updated to have play, pause, Fast Forward, Next, Previous, Inline Volume Controls, Repeat button, Cast Button and an Aspect button.

Linked Issues

PR Checklist

  • Has a linked Issue, and the Issue has been approved(bug) or Championed (feature/proposal)
  • Has tests (if omitted, state reason in description)
  • Has samples (if omitted, state reason in description)
  • Rebased on top of main at time of PR
  • Changes adhere to coding standard
  • Documentation created or updated: https://github.com/MicrosoftDocs/CommunityToolkit/pulls

Additional information

This updates the windows controls to support all the Media Buttons you could want.

image

image

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.
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-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.
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.
- 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.
@ne0rrmatrix ne0rrmatrix added the 📽️ MediaElement Issue/PR that has to do with MediaElement label Nov 9, 2024
@ne0rrmatrix ne0rrmatrix marked this pull request as ready for review November 11, 2024 23:20
@ne0rrmatrix ne0rrmatrix added the needs discussion Discuss it on the next Monthly standup label Dec 5, 2024
@brminnick brminnick requested a review from Copilot December 11, 2024 20:46

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 4 out of 5 changed files in this pull request and generated no suggestions.

Files not reviewed (1)
  • src/CommunityToolkit.Maui.MediaElement/CommunityToolkit.Maui.MediaElement.csproj: Language not supported
Comments skipped due to low confidence (3)

src/CommunityToolkit.Maui.MediaElement/Primitives/CustomTransportControls.windows.cs:8

  • The variable name FullScreenButton should be renamed to fullScreenButton to follow the naming conventions.
public AppBarButton FullScreenButton = new();

src/CommunityToolkit.Maui.MediaElement/Views/MauiMediaElement.windows.cs:53

  • The LoadResourceDictionary method does not handle the case where the resource dictionary might not load correctly, which could lead to a runtime error. Add a null check for resourceDictionary.
var resourceDictionary = (Microsoft.UI.Xaml.ResourceDictionary)XamlReader.Load(xaml);

src/CommunityToolkit.Maui.MediaElement/Views/MauiMediaElement.windows.cs:167

  • The OnFullScreenButtonClick method does not check if CurrentPage is null before using it, which could lead to a NullReferenceException. Add a null check for CurrentPage.
var currentPage = CurrentPage;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📽️ MediaElement Issue/PR that has to do with MediaElement needs discussion Discuss it on the next Monthly standup
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants