Table of Contents

Class VideoControl

Namespace
SharpConsoleUI.Controls
Assembly
SharpConsoleUI.dll

Plays video files in the terminal using half-block, ASCII, or braille rendering. Decodes frames via FFmpeg subprocess and renders at up to 30 fps. Requires FFmpeg to be installed and on the system PATH.

public class VideoControl : BaseControl, IDOMPaintable, INotifyPropertyChanged, IInteractiveControl, IFocusableControl, IMouseAwareControl, IWindowControl, IDisposable
Inheritance
VideoControl
Implements
Inherited Members
Extension Methods

Properties

CanFocusWithMouse

Whether this control can receive focus via mouse clicks

public bool CanFocusWithMouse { get; }

Property Value

bool

CanReceiveFocus

Whether this control can receive focus

public bool CanReceiveFocus { get; }

Property Value

bool

ContentWidth

Gets the minimum width needed to display the control's content, including margins. Returns null if width cannot be determined. This is calculated based on content (text length, child controls, etc.) and represents the natural/intrinsic size.

public override int? ContentWidth { get; }

Property Value

int?

CurrentTime

Approximate current playback position in seconds.

public double CurrentTime { get; }

Property Value

double

DurationSeconds

Total video duration in seconds (0 if unknown).

public double DurationSeconds { get; }

Property Value

double

ErrorMessage

Error message to display inside the control (e.g., "FFmpeg not found"). Null when no error.

public string? ErrorMessage { get; }

Property Value

string

FilePath

Path to the video file. Alias for Source for backward compatibility.

public string? FilePath { get; set; }

Property Value

string

FrameCount

Total frames rendered since play started.

public long FrameCount { get; }

Property Value

long

HasFocus

Gets whether this control currently has focus.

public bool HasFocus { get; }

Property Value

bool

IsEnabled

Gets or sets whether this control is enabled and can receive input.

public bool IsEnabled { get; set; }

Property Value

bool

Looping

Whether playback loops when reaching the end.

public bool Looping { get; set; }

Property Value

bool

OverlayEnabled

Whether the bottom overlay status bar is enabled. Enable via builder: Controls.Video().WithOverlay(). When enabled, the overlay appears on any key press or focus gain, then auto-hides after OverlayAutoHideMs.

public bool OverlayEnabled { get; set; }

Property Value

bool

PlaybackState

Current playback state.

public VideoPlaybackState PlaybackState { get; }

Property Value

VideoPlaybackState

RenderMode

Rendering mode: HalfBlock, Ascii, or Braille.

public VideoRenderMode RenderMode { get; set; }

Property Value

VideoRenderMode

Source

Video source — file path or URL. Accepts anything FFmpeg understands: local files, HTTP/HTTPS, RTSP, HLS (m3u8), RTMP, FTP, etc.

public string? Source { get; set; }

Property Value

string

TargetFps

Target playback FPS. Clamped to MinFps-MaxFps.

public int TargetFps { get; set; }

Property Value

int

WantsMouseEvents

Whether this control wants to receive mouse events

public bool WantsMouseEvents { get; }

Property Value

bool

WantsTabKey

When true, Tab and Shift+Tab are passed to ProcessKey(ConsoleKeyInfo) instead of being intercepted for focus traversal. If ProcessKey(ConsoleKeyInfo) returns false, the key bubbles back to focus traversal as normal. Default: false.

public bool WantsTabKey { get; }

Property Value

bool

Methods

CycleRenderMode()

Cycles to the next render mode (HalfBlock -> Ascii -> Braille -> ...).

public void CycleRenderMode()

GetLogicalContentSize()

Gets the logical size of the control's content without rendering.

public override Size GetLogicalContentSize()

Returns

Size

The size representing the content's natural dimensions.

MeasureDOM(LayoutConstraints)

Measures the control's desired size given the available constraints.

public override LayoutSize MeasureDOM(LayoutConstraints constraints)

Parameters

constraints LayoutConstraints

The layout constraints (min/max width/height).

Returns

LayoutSize

The desired size of the control.

OnDisposing()

Called by BaseControl.Dispose(). Stops playback and kills FFmpeg process.

protected override void OnDisposing()

PaintDOM(CharacterBuffer, LayoutRect, LayoutRect, Color, Color)

Paints the control's content directly to a CharacterBuffer.

public override void PaintDOM(CharacterBuffer buffer, LayoutRect bounds, LayoutRect clipRect, Color defaultForeground, Color defaultBackground)

Parameters

buffer CharacterBuffer

The buffer to paint to.

bounds LayoutRect

The absolute bounds where the control should paint.

clipRect LayoutRect

The clipping rectangle (visible area).

defaultForeground Color

The default foreground color from the container.

defaultBackground Color

The default background color from the container.

Pause()

Pauses playback. Call Play() to resume.

public void Pause()

Play()

Starts or resumes video playback.

public void Play()

PlayFile(string)

Loads and immediately starts playing a video file.

public void PlayFile(string filePath)

Parameters

filePath string

ProcessKey(ConsoleKeyInfo)

Processes a keyboard input event.

public bool ProcessKey(ConsoleKeyInfo keyInfo)

Parameters

keyInfo ConsoleKeyInfo

Returns

bool

True if the key was handled by this control; otherwise, false.

ProcessMouseEvent(MouseEventArgs)

Processes a mouse event for this control

public bool ProcessMouseEvent(MouseEventArgs args)

Parameters

args MouseEventArgs

Mouse event arguments with control-relative coordinates

Returns

bool

True if the event was handled and should not propagate further

Stop()

Stops playback and releases FFmpeg resources.

public void Stop()

Stream(string)

Starts streaming from any source FFmpeg supports: HTTP/HTTPS URLs, RTSP streams, HLS playlists (m3u8), RTMP, FTP, local files, etc.

public void Stream(string url)

Parameters

url string

Source URL or path. Anything FFmpeg's -i accepts.

TogglePlayPause()

Toggles between Play and Pause.

public void TogglePlayPause()

Events

MouseClick

Event fired when the control is clicked

public event EventHandler<MouseEventArgs>? MouseClick

Event Type

EventHandler<MouseEventArgs>

MouseDoubleClick

Event fired when the control is double-clicked

public event EventHandler<MouseEventArgs>? MouseDoubleClick

Event Type

EventHandler<MouseEventArgs>

MouseEnter

Event fired when the mouse enters the control area

public event EventHandler<MouseEventArgs>? MouseEnter

Event Type

EventHandler<MouseEventArgs>

MouseLeave

Event fired when the mouse leaves the control area

public event EventHandler<MouseEventArgs>? MouseLeave

Event Type

EventHandler<MouseEventArgs>

MouseMove

Event fired when the mouse moves over the control

public event EventHandler<MouseEventArgs>? MouseMove

Event Type

EventHandler<MouseEventArgs>

MouseRightClick

Event fired when the control is right-clicked (Button3)

public event EventHandler<MouseEventArgs>? MouseRightClick

Event Type

EventHandler<MouseEventArgs>

PlaybackEnded

Fired when playback reaches end of file.

public event EventHandler? PlaybackEnded

Event Type

EventHandler

PlaybackStateChanged

Fired when playback state changes.

public event EventHandler<VideoPlaybackState>? PlaybackStateChanged

Event Type

EventHandler<VideoPlaybackState>