VAST.UI for WPF
The VAST.UI for WPF library provides media player controls for Windows Presentation Foundation applications. It supports hardware-accelerated DirectX 11 rendering with WriteableBitmap fallback, and implements the IMediaPlayer interface for unified playback control.
Overview
| Feature |
Description |
| DirectX 11 Rendering |
Hardware-accelerated video rendering via DirectX 11 |
| WriteableBitmap Fallback |
CPU-based rendering when DirectX is unavailable |
| Mouse Controls |
Pan/tilt via drag, zoom via mouse wheel |
| Subtitles |
Configurable subtitle rendering with font and color options |
| Overlays |
BitmapSource overlay support for custom graphics on video |
| Snapshots |
Capture current video frame as JPEG |
| XAML Support |
Declarative UI with data binding support |
Requirements
Setup
Add the MediaPlayerControl or VideoPreviewControl to your window using XAML or programmatically:
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vast="clr-namespace:VAST.Controls;assembly=VAST.UI">
<vast:MediaPlayerControl x:Name="player" />
</Window>
var player = new VAST.Controls.MediaPlayerControl();
this.Content = player;
The MediaPlayerControl is the primary control for video playback in WPF applications.
XAML Usage
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vast="clr-namespace:VAST.Controls;assembly=VAST.UI">
<vast:MediaPlayerControl x:Name="player" />
</Window>
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 |
| SubtitleDecoration |
SubtitleDecoration |
Subtitle font, size, and color configuration |
| Volume |
float |
Audio volume (0.0 to 1.0) |
Stream Selection
Display Properties
Events
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>) |
| SetOverlay |
Set overlay bitmap on video (Pbgra32 or Bgra32) |
| RemoveOverlay |
Remove overlay from video |
Playback Parameters
Configure low-level playback behavior using PlaybackParameters:
player.PlaybackParameters = new PlaybackParameters
{
RenderingStrategy = RenderingStrategy.LowLatency,
VideoRendererType = VideoRendererType.Auto,
AllowDigitalPTZ = true,
};
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 |
Mouse Gestures
When PlaybackParameters.AllowDigitalPTZ is enabled, the control supports interactive pan, tilt, and zoom.
| Input |
Action |
| Mouse drag |
Pan/tilt (cursor changes to ScrollAll) |
| Mouse wheel |
Zoom in/out centered on cursor position |
player.PlaybackParameters = new PlaybackParameters
{
AllowDigitalPTZ = true,
};
Overlays
Display custom graphics over the video using BitmapSource overlays:
// Create overlay bitmap (must be Pbgra32 or Bgra32)
var bitmap = new WriteableBitmap(width, height, 96, 96, PixelFormats.Pbgra32, null);
// Draw on the bitmap
bitmap.Lock();
// ... drawing operations ...
bitmap.Unlock();
// Set overlay
player.SetOverlay(bitmap);
// Remove overlay
player.RemoveOverlay();
Subtitles
Configure subtitle appearance using SubtitleDecoration:
player.SubtitleDecoration = new SubtitleDecoration
{
FontFamily = "Segoe UI",
FontSize = 24,
Bold = true,
BackgroundColor = "#80000000", // Semi-transparent black
};
| Property |
Type |
Description |
| FontFamily |
string |
Font family name |
| FontSize |
double |
Font size in pixels |
| Bold |
bool |
Bold text |
| BackgroundColor |
string |
Background color in #ARGB format |
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.
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:vast="clr-namespace:VAST.Controls;assembly=VAST.UI">
<vast:VideoPreviewControl x:Name="preview"
RenderingStrategy="LowLatency"
RendererType="Best" />
</Window>
| 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 (DirectX 11 preferred) |
| Best |
Use hardware-accelerated DirectX 11 rendering |
| Compatible |
Use CPU-based WriteableBitmap rendering (fallback when DirectX 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. |
DirectX Renderer
The DirectX renderer uses HwndHost to embed a native DirectX 11 swap chain within the WPF visual tree:
- Creates a child window for DirectX rendering
- Integrates with WPF layout and transforms
- Hardware-accelerated video decoding and rendering
Compatible Renderer
The WriteableBitmap compatible renderer provides fallback rendering when DirectX is unavailable:
- Automatic color space conversion to BGRA
- Device offline image support (displays placeholder when capture device disconnects)
- Thread-safe bitmap updates via WPF Dispatcher
Troubleshooting
Common Issues
| Issue |
Cause |
Solution |
| Black screen |
Renderer not initialized |
Ensure control is visible and has non-zero size |
| No DirectX rendering |
DirectX 11 unavailable |
Set VideoRendererType = Compatible to use WriteableBitmap fallback |
| Mouse gestures not working |
PTZ disabled |
Set PlaybackParameters.AllowDigitalPTZ = true |
| Poor performance |
Software rendering active |
Ensure DirectX 11 is available; update graphics drivers |
| Overlay not displaying |
Wrong pixel format |
Use PixelFormats.Pbgra32 or PixelFormats.Bgra32 for overlay bitmaps |
- DirectX 11 requires Windows 7 SP1 or later with Platform Update
- WriteableBitmap fallback works on all Windows versions
- Hardware acceleration depends on graphics driver support
- WASAPI audio output requires Windows Vista or later
See Also