Previously I wrote about playing video with .NET MAUI on Android, iOS, and Mac Catalyst. The problem platform was Windows because WinUI 3 lacked any media playback controls. This has been rectified with the preview release of the WinAppSDK v1.2, which contains the MediaPlayerElement
and MediaTransportControls
types. If you want to know how to use these types, see Media players.
I’ve updated my VideoPlayer code with Windows support, so it’s now a truly cross-platform Video
control. This includes the ability to play remote videos, videos embedded in the app, and video's from the file system. As with the other platforms, the MauiVideoPlayer
class provides video playback capabilities on Windows. This class derives from Microsoft.UI.Xaml.Controls.Grid
and adds a MediaPlayerElement
to it (all WinUI controls must be in a layout, and so this mechanism ensures this will always be the case).
I also updated the code to remove the IVideo
and IVideoHandler
interfaces. After chatting to Shane I realised the interfaces weren’t necessary and weren’t adding anything. While .NET MAUI decouples its handlers from its cross-platform controls via interfaces, this is to enable experimental frameworks such as Comet and Fabulous to provide their own cross-platform controls, that implement the interfaces, while still using .NET MAUI’s handlers. Therefore, creating an interface for your cross-platform control is only necessary if you need to decouple your handler from its cross-platform control for a similar purpose, or for testing purposes.
My understanding is that v1.2 of the WinAppSDK will move out of preview by the end of the year, so there may be issues with MediaPlayerElement
until then.
No comments:
Post a Comment