🕓 5 MINTL;DR: We’re thrilled …
If you’ve ever built an app that needed to play video or audio across different devices, you know the struggle. The promise of rich media experiences is great, but the reality often involves wrestling with platform-specific APIs, struggling to maintain a consistent UI, and burning countless hours on asset management.
For developers using Uno Platform, the key to this is mastering the MediaPlayerElement
. This control offers a flexible way to embed video and audio into your apps for all targets. While it works well out of the box, you’ll often need to tailor its appearance and functionality to match your app’s unique design.
This article provides a look at how to style the MediaPlayerElement
and its companion, the MediaTransportControls
, specifically for Uno Platform applications. We’ll explore everything from simple tweaks to a complete visual overhaul.
Before you can use the MediaPlayerElement
, you need to enable the feature in your project. This adds the required platform-specific dependencies.
.csproj
file:
MediaElement
For a complete list of supported media formats, and platform-specific features, please refer to our official documentation.
Out of the box, the MediaPlayerElement
provides a standard set of controls for media playback, which are part of the MediaTransportControls
. Here’s the basic XAML to get one running:
This code block creates a media player with default controls like a play/pause button, volume control, and a progress slider. For an even faster workflow, you can also use Hot Design to simply drag the MediaPlayerElement
from the toolbox onto your UI, which generates this same code for you. This default setup is functional, but often you’ll need to adjust it to align with specific design requirements.
You’ll often need to modify the default transport controls to fit your app’s design. You can achieve this by accessing the MediaTransportControls within the MediaPlayerElement. This approach allows for targeted changes without redefining the entire template.
A common customization is to hide some of the default buttons. You can do this by setting their corresponding Is…ButtonVisible properties to False. This is useful for simplifying the interface and removing functionality that isn’t relevant to your app’s context.
In this example, using Hot Design, the fast forward, fast rewind, playback rate, and zoom buttons are hidden from the user, resulting in a cleaner player interface.
For a complete redesign, such as changing colors, layout, or adding new buttons—you need to provide a custom ControlTemplate for the MediaTransportControls.
You’ll start by copying the default style and then modifying it. The connection between the visual XAML and the player’s logic is made through specific x:Name
attributes (e.g., x:Name="PlayPauseButton"
). You must keep these names intact for the controls to function.
You can find the generic.xaml file included with the Windows App SDK or copy the code below.
Place the following <ResourceDictionary>
in your App.xaml
or in a separate dictionary file. From here, you can modify colors, sizes, and the arrangement of elements to match your brand.
XamlAutoFontFamily
Segoe Fluent Icons,Segoe MDL2 Assets
12
14
40
40
16
16
4
7,2,7,1
12,-1,8,1
Ultimately, the cross-platform MediaPlayerElement
is more than just a single control, it’s allows you to build ambitious, media-rich applications with a single codebase and integrates into the vast library of UI components already available through the Uno Toolkit, Windows Community Toolkit, and 3rd paty libraries.
Get hands-on experience with the MediaPlayerElement
using our Uno Chefs Recipe Book, where you’ll implement the video player, configure its source, and enable the transport controls. It’s the perfect way to see just how simple and powerful it is to create a rich media experience that runs everywhere.
Tags: XAML, WPF, Xamarin, UWP, Silverlight, .NET, Windows, C#, XAML
Uno Platform
360 rue Saint-Jacques, suite G101,
Montréal, Québec, Canada
H2Y 1P5
USA/CANADA toll free: +1-877-237-0471
International: +1-514-312-6958
Uno Platform 5.2 LIVE Webinar – Today at 3 PM EST – Watch