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 PlaySoundAction to MediaPlayerElement for UWP and WinUI 3 #287

Merged
merged 2 commits into from
Nov 19, 2024

Conversation

michael-hawker
Copy link
Contributor

@michael-hawker michael-hawker commented Nov 18, 2024

Fixes #252

As per the docs for MediaElement:

In Windows 10, build 1607 and on we recommend that you use MediaPlayerElement in place of MediaElement. MediaPlayerElement has the same functionality as MediaElement, while also enabling more advanced media playback scenarios. Additionally, all future improvements in media playback will happen in MediaPlayerElement.

MediaElement no longer exists in WinUI 3, so this PR moves both UWP and WinUI 3 to be able to use MediaPlayerElement with the PlaySoundAction.

This also resolves #252 as PlaySoundAction wasn't working with WinUI 3, but support was added back as of WinAppSDK 1.2.

I built a NuGet locally and tested with both UWP and WinUI 3 are able to play a sound fine.

This doesn't change the external API surface of this action at all, only the internal implementation. However, since we are changing to a different handler underneath for UWP, it be best to consider this a breaking change to note in the release notes, just in case and get in for 3.0. (We could bifercate and only use MPE on WinUI 3, I did that first, but that makes the code much more complex and will be harder to maintain, this seems like a good thing to update for UWP as well.)

@michael-hawker
Copy link
Contributor Author

michael-hawker commented Nov 18, 2024

Not sure why build is failing, this seems like the error message, which seems unrelated:

2024-11-18T18:43:06.9667610Z ##[error]C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Microsoft\VisualStudio\v17.0\AppxPackage\Microsoft.AppXPackage.Targets(1181,5): error APPX3217: SDK folder containing 'UAP.props' for 'UAP 10.0.18362.0' cannot be located. See http://go.microsoft.com/fwlink/?LinkID=798187 for more information. [D:\a\XamlBehaviors\XamlBehaviors\src\BehaviorsSDKManaged\Microsoft.Xaml.Interactivity.Uwp\Microsoft.Xaml.Interactivity.Uwp.csproj]
2024-11-18T18:43:06.9674859Z Done executing task "GetSdkFileFullPath" -- FAILED. (TaskId:1378)

This is built off the main branch which just built: https://github.com/microsoft/XamlBehaviors/actions/runs/11898644760/job/33155569513

@michael-hawker
Copy link
Contributor Author

Comparing to main, it looks like the Windows VM image was updated between the integration to main this morning and now.

Main used: windows-2022 20241021.1.0
Now using: windows-2022 20241113.3.0

WinUI 1.2 re-added Media support, but the PlaySoundAction was never updated
- Ensures we have the XamlRoot set on the Popup
- Creates a MediaPlayerElement in WinUI as no MediaElement exists (we should maybe just move the UWP code to this too anyway based on remarks in docs)
- Sets AutoPlay to true for MediaPlayerElement
- Adjusts to the new method event callback parameters for each platform
- Centralizes the Popup closing code, we also need to dispatch to the UI thread for WinUI 3 as the media events are called on a background thread
- Tested locally in a nuget package release build - works great!
…mmendations

The MediaElement docs say that no further improvements were made to it and that MediaPlayerElement should be used, as of 1607:

> In Windows 10, build 1607 and on we recommend that you use MediaPlayerElement in place of MediaElement. MediaPlayerElement has the same functionality as MediaElement, while also enabling more advanced media playback scenarios. Additionally, all future improvements in media playback will happen in MediaPlayerElement.

This also aligns the code to the WinUI 3 code needed as it only has MediaPlayerElement
Copy link
Member

@Sergio0694 Sergio0694 left a comment

Choose a reason for hiding this comment

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

LGTM!

@Sergio0694 Sergio0694 merged commit 912c928 into microsoft:main Nov 19, 2024
2 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.

What happened to PlaySoundAction?
2 participants