Table of Contents

VAST.UI for MAUI

The VAST.UI for MAUI library provides cross-platform media player controls for .NET MAUI applications. It supports Android, iOS, macOS (Catalyst), and Windows with platform-optimized video rendering and unified API through the IMediaPlayer interface.

Overview

Feature Description
Cross-Platform Single codebase for Android, iOS, macOS, and Windows
Hardware Rendering Platform-native video rendering (Metal, OpenGL, DirectX, TextureView)
Touch Gestures Pinch to zoom, pan to move on touch devices
Pointer Controls Mouse-based pan/tilt/zoom on desktop platforms
Overlays Title and statistics display overlays
Snapshots Capture current video frame as JPEG

Requirements

Platform-Specific Dependencies

Platform Dependency
Android VAST.Common.Ext.Android
iOS VAST.Common.Ext.iOS
macOS (Catalyst) VAST.Common.Ext.Catalyst
Windows VAST.Common.Ext.Win32

Platform Minimum Versions

Platform Minimum Version
Android API 21 (Android 5.0)
iOS 11.0
macOS (Catalyst) 11.0
Windows 10.0.17763.0

Setup

Register the VAST.UI handlers in your MauiProgram.cs:

public static MauiApp CreateMauiApp()
{
    var builder = MauiApp.CreateBuilder();
    builder
        .UseMauiApp<App>()
        .ConfigureMauiHandlers(handlers =>
        {
            handlers.AddHandler(typeof(VAST.Controls.MediaPlayerControlBase), typeof(VAST.Controls.MediaPlayerHandler));
            handlers.AddHandler(typeof(VAST.Controls.VideoPreviewControl), typeof(VAST.Controls.VideoPreviewHandler));
        });

    return builder.Build();
}

MediaPlayerControl

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

XAML Usage

<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:vast="clr-namespace:VAST.Controls;assembly=VAST.UI">
    <vast:MediaPlayerControl x:Name="player" />
</ContentPage>

Code Usage

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

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

// Adjust volume
player.Volume = 0.8;
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 (0.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
BorderColor Color Control border color
BorderThickness double 0 Border width
PlayerBackgroundColor string Background color in #ARGB format
ShowPlaybackControls bool false Show controls on pointer hover (Windows)
Stat string null Statistics text
StatBackColor Color Statistics background color
StatColor Color Statistics text color
StatFont Font Statistics font
StatIsVisible bool false Show statistics overlay
StatMargin Thickness Statistics margin
Title string null Title text
TitleBackColor Color Title background color
TitleColor Color Title text color
TitleFont Font Title font
TitleIsVisible bool false Show title overlay
TitleMargin Thickness Title margin

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 touch/mouse 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 hardware; Compatible uses software
VideoRenderingFramerate Rational null Maximum rendering framerate; null renders all frames

Rendering Strategies

Strategy Description
LowLatency Optimized for minimum frame latency; frames are rendered as soon as they are decoded. Best for real-time monitoring.
Smooth Optimized for smooth playback with frame timing based on timestamps. Best for smooth preview.
// 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

Gestures

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

Touch Gestures

Gesture Action
Pinch Zoom in/out centered on pinch origin
Pan Move the visible area (pan/tilt)

Pointer Gestures (Windows)

Input Action
Mouse wheel Zoom in/out
Mouse drag Pan/tilt
player.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.

<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:vast="clr-namespace:VAST.Controls;assembly=VAST.UI">
    <vast:VideoPreviewControl x:Name="preview"
                          RenderingStrategy="LowLatency"
                          RendererType="Best"
                          PreviewType="Capture" />
</ContentPage>
Property Type Default Description
IsReady bool false Renderer ready state (read-only)
PreviewType VideoPreviewType Capture Preview source type
Renderer IVideoRenderer null Active renderer instance (read-only)
RendererType VideoRendererType Best Renderer selection
RenderingStrategy RenderingStrategy LowLatency Rendering optimization mode

Preview Types

Type Description
Capture Preview from video capture device
Mixing Preview from video mixing/compositing source

Connecting to a Capture Source

To display video from a capture device, assign the Renderer to the capture source's Renderer property. Wait for IsReady before connecting.

// Wait for video preview control to be ready
while (!videoPreview.IsReady)
{
    await Task.Delay(100);
}

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

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

// ...

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

Platform-Specific Rendering

Each platform uses optimized native rendering:

Platform Video Renderer MJPEG Renderer
Windows WindowsMauiRenderer (SoftwareBitmap) CompatibleRenderer
Android AndroidTextureRenderer (TextureView) AndroidImageRenderer (ImageView)
iOS AppleVideoRenderer (AVSampleBufferDisplayLayer) IosImageRenderer (UIImageView)
macOS AppleVideoRenderer (AVSampleBufferDisplayLayer) IosImageRenderer (UIImageView)

Video Preview Rendering

Platform Capture Mixing
Windows WindowsMauiRenderer WindowsMauiRenderer
Android AndroidSurfaceRenderer (SurfaceView) AndroidTextureRenderer (TextureView)
iOS VirtualVideoRenderer (Metal/OpenGL) VirtualVideoRenderer
macOS VirtualVideoRenderer VirtualVideoRenderer

Troubleshooting

Common Issues

Issue Cause Solution
Black screen Renderer not initialized Ensure control is visible and has non-zero size
No video on Android TextureView not ready Wait for control to be fully laid out
Gestures not working PTZ disabled Set PlaybackParameters.AllowDigitalPTZ = true
Handler not found Handlers not registered Add handler registration in MauiProgram.cs
Poor performance Software rendering Check platform supports hardware acceleration
No audio Platform audio session Ensure audio session is configured (iOS)

Platform-Specific Notes

Android:

  • TextureView requires hardware acceleration
  • MJPEG streams use ImageView for better performance
  • Minimum API 21 required for TextureView

iOS/macOS:

  • Uses AVSampleBufferDisplayLayer for hardware-decoded video
  • Metal rendering available
  • Audio session must be configured for background playback

Windows:

  • SoftwareBitmap-based rendering for WinUI compatibility
  • Full pointer event support for pan/tilt/zoom
  • Playback controls overlay available on hover

See Also