Table of Contents

VAST.UI for WinUI

The VAST.UI for WinUI library provides media player controls for Windows App SDK (WinUI 3) applications. It supports hardware-accelerated Direct3D 11 rendering via Win2D with CPU fallback, and implements the IMediaPlayer interface for unified playback control.

Overview

Feature Description
Direct3D 11 Rendering Hardware-accelerated video rendering via Win2D and Windows Composition
CPU Fallback WriteableBitmap-based rendering when GPU unavailable
Pointer Controls Pan/tilt via pointer drag, zoom via mouse wheel
Overlays Title and statistics display overlays
Snapshots Capture current video frame as JPEG

Requirements

Setup

Add the MediaPlayerControl or VideoPreviewControl to your page in XAML or programmatically:

<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:vast="using:VAST.Controls">
    <vast:MediaPlayerControl x:Name="player" />
</Page>
var player = new VAST.Controls.MediaPlayerControl();
this.Content = player;

MediaPlayerControl

The MediaPlayerControl is the primary control for video playback in WinUI applications.

XAML Usage

<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:vast="using:VAST.Controls">
    <vast:MediaPlayerControl x:Name="player" />
</Page>

Code Usage

// Set media source
player.Source = new Uri("rtsp://camera.example.com/stream");

// Control playback
player.Play();
player.Pause();
player.Stop();

// Adjust volume
player.Volume = 0.8f;
player.IsMuted = false;

// Enable interactive pan/tilt/zoom
player.PlaybackParameters = new PlaybackParameters
{
    AllowDigitalPTZ = true,
};

Playback Properties

Property Type Description
AbsolutePlaybackTime DateTime? Absolute playback time for live streams with embedded timestamps
AutoPlay bool Auto-start on media load
Balance float Audio balance (-1.0 to 1.0)
CanPause bool Media supports pausing
CanSeek bool Media supports seeking
CurrentState PlayerState Current playback state
CurrentStatistics NetworkStat Real-time network performance statistics
Duration TimeSpan Total media duration
EchoCanceller IEchoCanceller Echo canceller for two-way audio communication
IsFullScreen bool Full-screen mode state
IsLooping bool Loop playback at end
IsMuted bool Audio mute state
PlaybackParameters PlaybackParameters Rendering and other low level configuration
PlaybackRate double Playback speed (1.0 = normal)
Position TimeSpan Current playback position
Source Uri Media source URI
SourceMedia IMediaSource Custom media source object
Stretch StretchType Video stretch mode
Volume float Audio volume (0.0 to 1.0)

Stream Selection

Property Type Description
AudioStreamCount int Number of audio streams
AudioStreamIndex int Selected audio stream
VideoStreamCount int Number of video streams
VideoStreamIndex int Selected video stream
SubtitleStreamCount int Number of subtitle streams
SubtitleStreamIndex int Selected subtitle stream

Display Properties

Property Type Default Description
PlayerBackgroundColor string Background color in #ARGB format

Events

Event Description
CurrentStateChanged Playback state changed
MediaEnded Playback reached end
MediaFailed Error occurred
MediaOpened Media loaded successfully
SeekCompleted Seek operation finished
VideoRenderingStarted First frame rendered

Methods

Method Description
GetAudioMediaType Get audio stream format
GetSubtitleMediaType Get subtitle stream format
GetVideoMediaType Get video stream format
Pause Pause playback
Play Start or resume playback
Stop Stop playback and release resources
TakeSnapshot Capture current frame as JPEG (returns Task<Stream>)

Playback Parameters

Configure low-level playback behavior using PlaybackParameters:

player.PlaybackParameters = new PlaybackParameters
{
    RenderingStrategy = RenderingStrategy.LowLatency,
    VideoRendererType = VideoRendererType.Auto,
    AllowDigitalPTZ = true,
};
Parameter Type Default Description
AllowDigitalPTZ bool false Enable pan, tilt, and zoom via pointer gestures
AllowIncompleteMediaType bool? null Start playback before all stream types are detected
AudioDecoderParameters DecoderParameters Audio decoder configuration
AudioOutputDeviceId string null WASAPI audio output device identifier
CleanupOnStop bool true Clear video surface when playback stops
ForceKeyframeOnlyDecoding bool false Decode keyframes only; reduces CPU/GPU load but video updates only at GOP intervals
MirrorX bool false Flip video horizontally
MirrorY bool false Flip video vertically
RenderingStrategy RenderingStrategy LowLatency LowLatency renders frames immediately; Smooth uses timestamp-based timing
StopAfterFirstFrame bool false Stop playback after rendering the first frame
StopAfterLastFrame bool true Stop playback after rendering the last frame
VideoDecoderParameters DecoderParameters Video decoder configuration
VideoRendererType VideoRendererType Auto Auto selects best available; Best forces Direct3D; Compatible uses WriteableBitmap
VideoRenderingFramerate Rational null Maximum rendering framerate; null renders all frames

Rendering Strategies

Strategy Description
LowLatency Frames rendered immediately when decoded. Best for live streams and real-time monitoring.
Smooth Frame timing based on timestamps. Best for VOD content and recorded media.
// Configure for live stream monitoring
player.PlaybackParameters.RenderingStrategy = RenderingStrategy.LowLatency;

// Configure for smooth playback
player.PlaybackParameters.RenderingStrategy = RenderingStrategy.Smooth;

Playback Rates

Playback rate control is only available for interactive sources (VOD, file-based media). Live streams do not support playback rate changes.

Rate Description
-32 to -1 Rewind (backward playback)
0 to 1 (exclusive) Slow motion
1 Normal speed
1 to 32 Fast forward

Pointer Gestures

When PlaybackParameters.AllowDigitalPTZ is enabled, the control supports interactive pan, tilt, and zoom.

Input Action
Pointer drag Pan/tilt (cursor changes to SizeAll)
Mouse wheel Zoom in/out centered on cursor position
player.PlaybackParameters = new PlaybackParameters
{
    AllowDigitalPTZ = true,
};

Stretch Modes

Mode Description
Original Display at original size without scaling
Preserve Scale to fit while preserving aspect ratio
Fill Scale to fill the entire area (may crop)
Zoom Scale to fill with aspect ratio preserved (crops edges)

Snapshots

Capture the current video frame as a JPEG image:

using var stream = await player.TakeSnapshot();
if (stream != null)
{
    // Save to file
    using var fileStream = File.Create("snapshot.jpg");
    await stream.CopyToAsync(fileStream);
}

VideoPreviewControl

The VideoPreviewControl provides a lightweight preview surface for video capture and mixing scenarios.

<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:vast="using:VAST.Controls">
    <vast:VideoPreviewControl x:Name="preview"
                              RenderingStrategy="LowLatency"
                              RendererType="Best" />
</Page>
Property Type Default Description
Renderer IVideoRenderer null Active renderer instance (read-only)
RendererType VideoRendererType Best Renderer selection
RenderingStrategy RenderingStrategy LowLatency Rendering optimization mode

Connecting to a Capture Source

To display video from a capture device, assign the Renderer to the capture source's Renderer property.

// Configure rendering
preview.RenderingStrategy = RenderingStrategy.LowLatency;
preview.RendererType = VideoRendererType.Best;

// Connect the renderer to the capture source
videoCaptureSource.Renderer = preview.Renderer;

// ...

// Disconnect renderer to stop preview
videoCaptureSource.Renderer = null;

Rendering

Renderer Types

Type Description
Auto Automatically select the best available renderer (Direct3D 11 preferred)
Best Use hardware-accelerated Direct3D 11 rendering via Win2D
Compatible Use CPU-based WriteableBitmap rendering (fallback when Direct3D unavailable)

Rendering Strategies

Strategy Description
LowLatency Frames rendered immediately when decoded. Best for live streams and real-time monitoring.
Smooth Frame timing based on timestamps. Best for VOD content and recorded media.

GPU Renderer

The GPU renderer (WindowsMauiRenderer) uses Direct3D 11 with Win2D and Windows Composition APIs:

  • SpriteVisual with composition surfaces for efficient rendering
  • CanvasDevice for GPU context management
  • Media Foundation integration via IMFDXGIDeviceManager
  • Configurable rendering queue duration for latency tuning

Compatible Renderer

The CPU-based compatible renderer provides fallback rendering when Direct3D is unavailable:

  • WriteableBitmap for software rendering
  • Automatic color space conversion to BGRA
  • Device offline image support (displays placeholder when capture device disconnects)
  • Thread-safe bitmap updates via DispatcherQueue

Troubleshooting

Common Issues

Issue Cause Solution
Black screen Renderer not initialized Ensure control is visible and has non-zero size
No Direct3D rendering Direct3D 11 unavailable Set VideoRendererType = Compatible to use WriteableBitmap fallback
Pointer gestures not working PTZ disabled Set PlaybackParameters.AllowDigitalPTZ = true
Poor performance Software rendering active Ensure Direct3D 11 is available; update graphics drivers

Platform Notes

  • Requires Windows 10 version 1809 (build 17763) or later
  • Windows App SDK 1.7 or later
  • Direct3D 11 requires compatible GPU and drivers
  • WASAPI audio output for low-latency audio playback

See Also