Table of Contents

Class VideoView

Namespace
VisioForge.Core.UI.Uno
Assembly
VisioForge.Core.UI.Uno.dll

Skia Desktop-specific implementation of VideoView. The pipeline pushes BGRA frames, which are copied into a Microsoft.UI.Xaml.Media.Imaging.WriteableBitmap shown by an Microsoft.UI.Xaml.Controls.Image child.

public sealed class VideoView : Grid, IWeakReferenceProvider, IAnimationObject, IVisualElement, IVisualElement2, IDataContextProvider, IVideoViewPushFrame, IVideoView, IDisposable, INotifyPropertyChanged

Inheritance

Implements

IVideoViewPushFrame
IVideoView

Inherited Members

Remarks

This control serves as a unified video rendering surface across all Uno Platform targets:

  • Windows: Native WinUI 3 rendering with DirectX
  • Android: TextureView-based rendering with hardware acceleration
  • iOS: Metal-based rendering via native UIView
  • Skia desktop (Linux, macOS): pushed BGRA frames drawn into a WriteableBitmap

The control integrates with VisioForge media engines through the VisioForge.Core.Types.IVideoView interface, providing consistent video playback APIs across all platforms. It handles platform-specific initialization through partial methods that are implemented in platform-specific files.

Key features:

  • Automatic DPI scaling on Windows
  • Mouse/pointer event handling (except on Android and iOS)
  • Minimum size enforcement for reliable rendering
  • Platform-specific optimizations via partial methods
  • Thread-safe UI updates via DispatcherQueue

Constructors

VideoView()

Initializes a new instance of the VisioForge.Core.UI.Uno.VideoView class.

public VideoView()

Remarks

The constructor performs the following initialization:

  • Sets black background for standard video display appearance
  • Subscribes to lifecycle events (Loaded, Unloaded, SizeChanged)
  • Subscribes to pointer events on supported platforms (not Android/iOS)
  • Ensures DispatcherQueue is available for thread-safe operations
  • Sets minimum size constraints to ensure proper rendering

Platform-specific initialization is performed when the control is added to the visual tree via the Loaded event, which calls the partial method OnLoadedPlatform().

Properties

Context

SDK logging context. Set by the engine via VisioForge.Core.Helpers.ContextPropagator when the view is attached. When null, lifecycle/render diagnostics fall back to Trace.

public BaseContext Context { get; set; }

Property Value

BaseContext

RendererSettings

Gets or sets the settings of the renderer that draws into this view.

public VideoRendererSettingsX RendererSettings { get; set; }

Property Value

VideoRendererSettingsX

Remarks

X engines: read when the renderer is built, so assign the object before the engine starts, starting from VisioForge.Core.Types.X.VideoRendererSettingsX.CreateDefault: a plain VisioForge.Core.Types.X.VideoRendererSettingsX selects the OpenGL renderer on Windows, and on macOS the picture can open in a separate window instead of the view. VisioForge.Core.Types.X.VideoRendererSettingsX.Letterbox alone can also be changed while the video is playing. On macOS, and on a view that draws the frames itself (WPF, WinUI, MAUI, Avalonia software mode, Android, iOS), the change applies with the next frame, so a paused picture changes when playback continues. VideoEditCoreX and SimplePlayerCoreX read only VisioForge.Core.Types.X.VideoRendererSettingsX.Letterbox: when they start, or on a view that draws the frames itself, with the next frame.

Classic engines (VideoCaptureCore, MediaPlayerCore, VideoEditCore) read only VisioForge.Core.Types.X.VideoRendererSettingsX.Letterbox, which stays in step with their Video_Renderer.StretchMode: whichever was written last wins, and when an engine is first attached to a view, a stretch on either side wins. To apply a change while the video is playing, call Video_Renderer_UpdateAsync, or Video_Renderer_Update after a synchronous start.

Methods

CallInvoke(Delegate, params object[])

Invokes the specified method on the UI thread.

public void CallInvoke(Delegate method, params object[] args)

Parameters

method Delegate

The method to invoke.

args object[]

The arguments to pass to the method.

Remarks

If the invoked method throws, this method rethrows the underlying exception rather than the wrapping TargetInvocationException raised by DynamicInvoke(Object[]). (LOW #356)

Exceptions

MemberAccessException

Thrown by DynamicInvoke(Object[]) if the caller does not have access to the method.

TargetParameterCountException

Thrown when the number of arguments does not match the method signature.

CallRefresh()

Forces the view to redraw or refresh its content.

public void CallRefresh()

ClearUI()

Clears the user interface, removing any overlays or graphics.

public void ClearUI()

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

Remarks

This method performs comprehensive cleanup:

  • Unsubscribes from all lifecycle events (Loaded, Unloaded, SizeChanged)
  • Unsubscribes from pointer events on supported platforms
  • On Windows: Detaches from parent media engine and unsubscribes from its events
  • On non-Windows Uno targets (Skia / Android / iOS): calls base.Dispose() so Uno's generated Microsoft.UI.Xaml.FrameworkElement dispose can release the underlying native peer (Android View, iOS UIView, or the Skia visual). Uno does not generate a FrameworkElement.Dispose() on the WinUI / WindowsAppSDK target, so the chain is omitted there.

The method is safe to call multiple times. After disposal, the control should not be used.

~VideoView()

Finalizer.

protected ~VideoView()

GetBackgroundColor()

Gets the background color of the video view.

public SKColor GetBackgroundColor()

Returns

SKColor

The background color as an SkiaSharp.SKColor.

Remarks

This method safely accesses the Background property from any thread by marshalling to the UI thread if necessary. If the DispatcherQueue is available and the call is not from the UI thread, the method synchronously waits for the result.

GetHandle()

Gets the native window handle of the underlying UI control.

public nint GetHandle()

Returns

nint

An IntPtr representing the window handle.

GetInvokeRequired()

Gets a value indicating whether the caller must use an invoke method when making calls to the control.

public bool GetInvokeRequired()

Returns

bool

true if the call must be invoked; otherwise, false.

GetIsHandleCreated()

Gets a value indicating whether the underlying UI control's handle has been created.

public bool GetIsHandleCreated()

Returns

bool

true if the handle is created; otherwise, false.

GetSize()

Gets the current size of the video view.

public Size GetSize()

Returns

Size

The size as a VisioForge.Core.Types.Size structure.

Remarks

This method returns the control's size with platform-specific adjustments:

  • Uses ActualWidth/ActualHeight if available, falls back to Width/Height
  • On Windows: Applies DPI scaling to convert from logical pixels to device pixels
  • On other platforms: Returns logical pixels directly

The returned size is always at least 1x1 pixels and is rounded to integers. If DPI information cannot be retrieved on Windows, a scale of 1.0 (96 DPI) is assumed.

GetUIEngine()

Gets the underlying UI engine being used by the view.

public VideoViewUIEngine GetUIEngine()

Returns

VideoViewUIEngine

The VisioForge.Core.Types.VideoViewUIEngine used for rendering.

InvokeStart()

Signals the view that the engine has started.

public void InvokeStart()

Remarks

This method prepares the control for video rendering by calling the platform-specific start hook (OnInvokeStartPlatform) on the UI thread.

Microsoft.UI.Xaml.UIElement.Visibility is deliberately left alone. The engine calls this method on every pipeline start, and writing Visibility here sets a local value that wins over the value the application last pushed through its binding: a view the application had collapsed came back, and — because the source property had not changed — no further binding update ever corrected it, so the control could never be collapsed again. Showing and hiding the view belongs to the application.

InvokeStartComplete()

Signals the view that the engine has completed its start sequence.

public void InvokeStartComplete()

InvokeStop()

Signals the view that the engine has stopped.

public void InvokeStop()

Remarks

This method performs cleanup when video playback stops:

  • Keeps the control visible (unlike some platforms that hide it)
  • Forces a layout update to ensure proper display
  • Calls the platform-specific stop hook (OnInvokeStopPlatform)

The operation is performed on the UI thread to ensure thread safety. Any exceptions during layout update are caught and logged to debug output.

InvokeVideoRendererUpdate()

Triggers an update of the video renderer.

public void InvokeVideoRendererUpdate()

LogDialogClear()

Clears all messages from the log dialog.

public void LogDialogClear()

LogDialogClose()

Closes the log dialog if it is open.

public void LogDialogClose()

LogDialogError(string)

Logs a dialog error message.

public void LogDialogError(string msg)

Parameters

msg string

The message to log.

MeasureOverride(Size)

Keeps the video from sizing the view: in unconstrained space (an Auto row, a StackPanel) the image would grow the view to the frame's pixel size. There the view takes the size of its other children, or its minimum size.

protected override Size MeasureOverride(Size availableSize)

Parameters

availableSize Size

The size the parent offers.

Returns

Size

The desired size.

PushFrame(VideoFrame)

Pushes a video frame for rendering.

public void PushFrame(VideoFrame frame)

Parameters

frame VideoFrame

The video frame.

PushFrame(VideoFrameX)

Pushes a BGRA video frame for rendering. Called on a streaming thread: the pixels are copied here (the pipeline reuses its buffer) and the bitmap is updated on the UI thread.

public void PushFrame(VideoFrameX frame)

Parameters

frame VideoFrameX

The video frame.

PushMouseButtonDown(int, int, MouseButton)

Pushes a mouse button down event.

public void PushMouseButtonDown(int x, int y, MouseButton button)

Parameters

x int

The x-coordinate of the mouse cursor.

y int

The y-coordinate of the mouse cursor.

button MouseButton

The mouse button that was pressed.

PushMouseButtonUp(int, int, MouseButton)

Pushes a mouse button up event.

public void PushMouseButtonUp(int x, int y, MouseButton button)

Parameters

x int

The x-coordinate of the mouse cursor.

y int

The y-coordinate of the mouse cursor.

button MouseButton

The mouse button that was released.

PushMouseMove(int, int)

Pushes a mouse move event.

public void PushMouseMove(int x, int y)

Parameters

x int

The x-coordinate of the mouse cursor.

y int

The y-coordinate of the mouse cursor.

ResizeRoundTo(int)

Resizes the control, rounding the dimensions to the specified multiple.

public void ResizeRoundTo(int round)

Parameters

round int

The value to round the dimensions to.

SetHandle(nint)

Sets the window handle.

public void SetHandle(nint handle)

Parameters

handle nint

The handle.

ShowMessage(string)

Shows a message box.

public MessageBoxResult ShowMessage(string message)

Parameters

message string

The message to display.

Returns

MessageBoxResult

The result of the message box.

ShowMessageEx(string, string, MessageBoxDialogButtons)

Displays a message box with custom caption and buttons.

public MessageBoxResult ShowMessageEx(string message, string caption, MessageBoxDialogButtons buttons)

Parameters

message string

The message to display.

caption string

The caption of the message box.

buttons MessageBoxDialogButtons

The buttons to display in the message box.

Returns

MessageBoxResult

The result of the message box.

OnMouseButtonDown

Occurs when a mouse button is pressed down over the control.

public event EventHandler<MouseButtonEventArgs> OnMouseButtonDown

Event Type

EventHandler<MouseButtonEventArgs>

OnMouseButtonUp

Occurs when a mouse button is released over the control.

public event EventHandler<MouseButtonEventArgs> OnMouseButtonUp

Event Type

EventHandler<MouseButtonEventArgs>

OnMouseMoved

Occurs when the mouse pointer is moved over the control.

public event EventHandler<MouseMoveEventArgs> OnMouseMoved

Event Type

EventHandler<MouseMoveEventArgs>

PropertyChanged

Occurs when a property value changes.

public event PropertyChangedEventHandler PropertyChanged

Event Type

PropertyChangedEventHandler