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
CanReceiveFocus
Whether this control can receive focus
public bool CanReceiveFocus { get; }
Property Value
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
DurationSeconds
Total video duration in seconds (0 if unknown).
public double DurationSeconds { get; }
Property Value
ErrorMessage
Error message to display inside the control (e.g., "FFmpeg not found"). Null when no error.
public string? ErrorMessage { get; }
Property Value
FilePath
Path to the video file. Alias for Source for backward compatibility.
public string? FilePath { get; set; }
Property Value
FrameCount
Total frames rendered since play started.
public long FrameCount { get; }
Property Value
HasFocus
Gets whether this control currently has focus.
public bool HasFocus { get; }
Property Value
IsEnabled
Gets or sets whether this control is enabled and can receive input.
public bool IsEnabled { get; set; }
Property Value
Looping
Whether playback loops when reaching the end.
public bool Looping { get; set; }
Property Value
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
PlaybackState
Current playback state.
public VideoPlaybackState PlaybackState { get; }
Property Value
RenderMode
Rendering mode: HalfBlock, Ascii, or Braille.
public VideoRenderMode RenderMode { get; set; }
Property Value
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
TargetFps
Target playback FPS. Clamped to MinFps-MaxFps.
public int TargetFps { get; set; }
Property Value
WantsMouseEvents
Whether this control wants to receive mouse events
public bool WantsMouseEvents { get; }
Property Value
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
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
constraintsLayoutConstraintsThe 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
bufferCharacterBufferThe buffer to paint to.
boundsLayoutRectThe absolute bounds where the control should paint.
clipRectLayoutRectThe clipping rectangle (visible area).
defaultForegroundColorThe default foreground color from the container.
defaultBackgroundColorThe 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
filePathstring
ProcessKey(ConsoleKeyInfo)
Processes a keyboard input event.
public bool ProcessKey(ConsoleKeyInfo keyInfo)
Parameters
keyInfoConsoleKeyInfo
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
argsMouseEventArgsMouse 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
urlstringSource 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
MouseDoubleClick
Event fired when the control is double-clicked
public event EventHandler<MouseEventArgs>? MouseDoubleClick
Event Type
MouseEnter
Event fired when the mouse enters the control area
public event EventHandler<MouseEventArgs>? MouseEnter
Event Type
MouseLeave
Event fired when the mouse leaves the control area
public event EventHandler<MouseEventArgs>? MouseLeave
Event Type
MouseMove
Event fired when the mouse moves over the control
public event EventHandler<MouseEventArgs>? MouseMove
Event Type
MouseRightClick
Event fired when the control is right-clicked (Button3)
public event EventHandler<MouseEventArgs>? MouseRightClick
Event Type
PlaybackEnded
Fired when playback reaches end of file.
public event EventHandler? PlaybackEnded
Event Type
PlaybackStateChanged
Fired when playback state changes.
public event EventHandler<VideoPlaybackState>? PlaybackStateChanged