-
Notifications
You must be signed in to change notification settings - Fork 113
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
Update PlaySoundAction to MediaPlayerElement for UWP and WinUI 3 #287
Conversation
Not sure why build is failing, this seems like the error message, which seems unrelated:
This is built off the |
src/BehaviorsSDKManaged/Microsoft.Xaml.Interactions.Shared/Media/PlaySoundAction.cs
Outdated
Show resolved
Hide resolved
src/BehaviorsSDKManaged/Microsoft.Xaml.Interactions.Shared/Media/PlaySoundAction.cs
Outdated
Show resolved
Hide resolved
Comparing to main, it looks like the Windows VM image was updated between the integration to Main used: windows-2022 20241021.1.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
2630eed
to
492d01c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Fixes #252
As per the docs for MediaElement:
MediaElement no longer exists in WinUI 3, so this PR moves both UWP and WinUI 3 to be able to use
MediaPlayerElement
with thePlaySoundAction
.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.)