MediaPlayerElement control for Windows Forms and WPF

The MediaPlayerElement control embeds a view that streams and renders media content such as video in your Windows Forms or WPF desktop application. This is one of several wrapped Universal Windows Platform controls that are available for Windows Forms and WPF applications as part of a feature called XAML Islands. For more information, see UWP controls in desktop applications (XAML Islands).

MediaPlayterElement example

Note

If you have feedback about this control, create a new issue in the microsoft-ui-xaml repo and leave your comments there.

About MediaPlayerElement control

This control wraps an instance of the UWP Windows.UI.Xaml.Controls.MediaPlayerElement control. The WPF version of this control is located in the Microsoft.Toolkit.Wpf.UI.Controls namespace. The Windows Forms version is located in the Microsoft.Toolkit.Forms.UI.Controls namespace. You can find additional related types (such as enums and event args classes) in the Microsoft.Toolkit.Win32.UI.Controls.Interop.WinRT namespace.

Prerequisites

Before you can use this control, you must follow these instructions to configure your project to support XAML Islands.

Known issues and limitations

  • This controls does not currently support full screen video.
  • The Source property is exposed as a string, which is interpreted as a URL and bound to the Source property of the wrapped UWP control as a UWP-implemented IMediaPlaybackSource.
  • See also our list of known issues for WPF and Windows Forms controls in the Windows Community Toolkit repo.

Syntax

<Window x:Class="TestSample.MainWindow" ...
  xmlns:controls="clr-namespace:Microsoft.Toolkit.Wpf.UI.Controls;assembly=Microsoft.Toolkit.Wpf.UI.Controls"
...>

<controls:MediaPlayerElement x:Name="mediaPlayerElement"
    Source="https://mediaplatstorage1.blob.core.windows.net/windows-universal-samples-media/elephantsdream-clip-h264_sd-aac_eng-aac_spa-aac_eng_commentary-srt_eng-srt_por-srt_swe.mkv"
    AutoPlay="True" Margin="5" HorizontalAlignment="Stretch"  VerticalAlignment="Stretch" AreTransportControlsEnabled="True" />

Properties

The following properties wrap corresponding properties of the wrapped UWP Windows.UI.Xaml.Controls.MediaPlayerElement object. See the links in this table for more information about each property.

Property Type Description
AreTransportControlsEnabled bool Wraps the AreTransportControlsEnabled property.
AreTransportControlsEnabledProperty DependencyProperty Dependency property for the AreTransportControlsEnabled property.
AutoPlay bool Wraps the AutoPlay property.
AutoPlayProperty DependencyProperty Dependency property for the ActiAutoPlayveTool property.
IsFullWindow bool Wraps the IsFullWindow property.
IsFullWindowProperty DependencyProperty Dependency property for the IsFullWindow property.
MediaPlayer MediaPlayer Wraps the MediaPlayer property.
MediaPlayerProperty DependencyProperty Dependency property for the MediaPlayer property.
PosterSource ImageSource Wraps the PosterSource property.
PosterSourceProperty DependencyProperty Dependency property for the PosterSource property.
Source string Wraps the Source property. The Source property of this wrapped control is exposed as a string, which is interpreted as a URL and bound to the Source property of the wrapped UWP control as a UWP-implemented IMediaPlaybackSource.
SourceProperty DependencyProperty Dependency property for the Source property.
Stretch Stretch Wraps the Stretch property.
StretchProperty DependencyProperty Dependency property for the Stretch property.
TransportControls MediaTransportControls Wraps the TransportControls property.

Methods

Methods Return Type Description
SetMediaPlayer(MediaPlayer) void Wraps the SetMediaPlayer method of the wrapped UWP MediaPlayerElement control.

Requirements

Device family .NET 4.6.2, Windows 10 (introduced v10.0.17709.0)
Namespace Windows Forms: Microsoft.Toolkit.Forms.UI.Controls
WPF: Microsoft.Toolkit.Wpf.UI.Controls
NuGet package Windows Forms: Microsoft.Toolkit.Forms.UI.Controls
WPF: Microsoft.Toolkit.Wpf.UI.Controls

API