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

Fix Media Element Windows CTD #1921

Merged

Conversation

ne0rrmatrix
Copy link
Contributor

  • Bug fix

Description of Change

-Update font icon behavior to prevent CTD.

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

Fixes crash where if you have multiple media elements on a page in windows the app will immediately crash to desktop. This was an issues with font icons and has been resolved with this PR.

…esktop.

Updated the `Content` property of the `fullScreenButton` object from `fullScreenIcon` to a new `FontIcon` object. The `Glyph` property is now set to "\uE740" and the `FontFamily` property is set to "Segoe Fluent Icons". This change modifies the visual representation of the `fullScreenButton` in the UI.
@vhugogarcia
Copy link
Contributor

Thanks @ne0rrmatrix for the PR. I believe changing the icon to a font icon makes sense.

However, is Segoe Fluent Icons a system windows font? if yes, what will happen if that font does not exist in the OS? 🤔

@ne0rrmatrix
Copy link
Contributor Author

ne0rrmatrix commented Jun 7, 2024

Thanks @ne0rrmatrix for the PR. I believe changing the icon to a font icon makes sense.

However, is Segoe Fluent Icons a system windows font? if yes, what will happen if that font does not exist in the OS? 🤔

This is a windows specific fix and the font icon is standard across current windows versions that we support.
Edit: The changes here only create a new icon on demand and do not change the previous icon at all. It simply stops using a static readonly and dynamically generates a new one.

Removed the `fullScreenIcon` static readonly object from the `MauiMediaElement` class in the `MauiMediaElement.windows.cs` file. Now, a new `FontIcon` object is directly created in the `OnFullScreenButtonClick` method. This change simplifies the code and makes the `OnFullScreenButtonClick` method more self-contained.

This removes reduntant static readonly object that was causing issues. The fontIcon is now generated dynamically to prevent CTD.
@ne0rrmatrix
Copy link
Contributor Author

ne0rrmatrix commented Jun 7, 2024

Since we were having issues with a static readonly object I have removed it and it is now generated dynamically. Not sure if the second call would be impacted but I can't guess every use case. The only question now is do we want to that in case somehow we end up with two fullscreen media elements on the same page which would also generate the same bug? Not sure how that would happen but if it does it will crash.

If we do I can remove static readonly FontIcon exitFullScreenIcon = new() { Glyph = "\uE73F", FontFamily = new FontFamily("Segoe Fluent Icons") }; and replace with dynamic calls too.

Edit: Was able to verify when exiting app after enter and exiting full screen that the app can crash while exiting. Fix has been applied.

Refactored the `MauiMediaElement` class in `MauiMediaElement.windows.cs` file. Removed the `exitFullScreenIcon` static readonly variable and instead created a new `FontIcon` directly where needed. Updated the `OnFullScreenButtonClick` method to set the `fullScreenButton.Content` to new `FontIcon` instances with different glyphs (`"\uE740"` and `"\uE73F"`), representing different icons in the "Segoe Fluent Icons" font family. These changes affect the icons used for the full screen button in the media player.

This fixes a small UI issue where the incorrect icon was applied starting with full screen then reversion of Full screen status. So icons got reversed starting when selecting full screen. Fixed now. Removed the static readonly object as I was able to verify it does in fact have a bug with it.
@brminnick
Copy link
Collaborator

I too am a bit nervous hard coding a font here. The smells like a potential for a future bug.

@ne0rrmatrix - could you add the font as a resource to the Windows platform in CommunityToolkit.Maui.MediaElement (ie add the .ttf or .otf file as an embedded resource to ensure the font always ships with the NuGet package? This is probably overkill, but it'll prevent a future bug if Windows removes/changes Segoe Fluent Icons).

Updated the `UseMauiCommunityToolkitMediaElement` method in the `AppBuilderExtensions` class to include a configuration for the "Segoe Fluent Icons" font from the "SegMDL2.ttf" file specifically for the Windows platform. Also, added a new `ItemGroup` in the `CommunityToolkit.Maui.MediaElement.csproj` file to pack the "SegMDL2.ttf" font file into the application when the `TargetFramework` contains '-windows'.
@ne0rrmatrix
Copy link
Contributor Author

Segoe Fluent Icons

Updated as requested. Font added as resource for windows.

@bijington
Copy link
Contributor

I too am a bit nervous hard coding a font here. The smells like a potential for a future bug.

@ne0rrmatrix - could you add the font as a resource to the Windows platform in CommunityToolkit.Maui.MediaElement (ie add the .ttf or .otf file as an embedded resource to ensure the font always ships with the NuGet package? This is probably overkill, but it'll prevent a future bug if Windows removes/changes Segoe Fluent Icons).

I've tried to look but have failed to find the licensing rules around the specific font. Are we allowed to distribute the font?

@ne0rrmatrix
Copy link
Contributor Author

ne0rrmatrix commented Jun 8, 2024

License can be found by downloading Mac download link here. It is in zip file. Scroll down page and look for mac assets. https://learn.microsoft.com/en-us/windows/apps/design/style/segoe-ui-symbol-font

Edit: Copy of text of included license

"You may use the Segoe MDL2 Assets and Segoe UI fonts or glyphs included in this file (“Software”) solely to design, develop and test your programs that run on a Microsoft Platform, a Microsoft Platform includes but is not limited to any hardware or software product or service branded by trademark, trade dress, copyright or some other recognized means, as a product or service of Microsoft. This license does not grant you the right to distribute or sublicense all or part of the Software to any third party. By using the Software you agree to these terms. If you do not agree to these terms, do not use the Software."

Looks like we cannot distribute them. I will revert the changes. I will mention this font is built into windows and I believe is used directly by the OS in many built in applications like explorer, Settings, etc. Not 100 percent sure but it is a core OS font as far as I know.

@ne0rrmatrix
Copy link
Contributor Author

ne0rrmatrix commented Jun 8, 2024

I just double checked and google first result is that "Segoe UI" is a windows system font. The MDL2 icons I reference are system icons that are a core part of the OS. I'm not sure how we move forward if this is an issue. We can of course close this PR and go back and revert the previous one that added this use of fonts and look for an alternative method of fixing the previous issue? Can we not rely on system resources to just be available?

2. remove `static readonly` from `FontIcons`
3. Fix what font icon is applied while switching full screen status
Copy link
Collaborator

@brminnick brminnick left a comment

Choose a reason for hiding this comment

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

Thanks James! I owe you an apology - I see now that we were already using Segoe Fluent Icons in MediaElement and that this PR does not introduce that change. (A lazy PR review on my part - sorry!)

I'm cool moving forward with this. I have a couple comments (below). After that, I'm cool approving/merginfg this 💯

brminnick
brminnick previously approved these changes Jun 9, 2024
Copy link
Collaborator

@brminnick brminnick left a comment

Choose a reason for hiding this comment

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

Thanks @ne0rrmatrix!!

@brminnick brminnick enabled auto-merge (squash) June 9, 2024 08:51
auto-merge was automatically disabled June 9, 2024 08:52

Head branch was pushed to by a user without write access

@brminnick brminnick enabled auto-merge (squash) June 9, 2024 09:04
@brminnick brminnick merged commit f6e3368 into CommunityToolkit:main Jun 9, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Windows Media Element CTD When using Multiple MediaElements
4 participants