Table of Contents

Class MediaPlayer

Namespace
VAST.Player
Assembly
VAST.UI.dll

Provides media playback functionality including video and audio rendering, stream selection, seeking, and playback control.

public class MediaPlayer : IMediaPlayer, IDisposable
Inheritance
MediaPlayer
Implements
Inherited Members

Constructors

MediaPlayer()

Creates a new instance of MediaPlayer.

public MediaPlayer()

Exceptions

UnauthorizedAccessException

Thrown when the license is invalid.

Fields

TRACK_AUTO

Indicates automatic track selection.

public static readonly int TRACK_AUTO

Field Value

int

TRACK_NOT_SET

Indicates that no track is set.

public static readonly int TRACK_NOT_SET

Field Value

int

Properties

AbsolutePlaybackTime

Gets the absolute playback time when playing streams with absolute timestamps.

public DateTime? AbsolutePlaybackTime { get; }

Property Value

DateTime?

AudioStreamCount

Gets the number of available audio streams.

public int AudioStreamCount { get; }

Property Value

int

AudioStreamIndex

Gets or sets the index of the currently selected audio stream.

public int AudioStreamIndex { get; set; }

Property Value

int

AutoPlay

Gets or sets whether playback starts automatically when a source is set.

public bool AutoPlay { get; set; }

Property Value

bool

Balance

Gets or sets the audio balance between left and right channels. Value ranges from 0.0 (left) to 1.0 (right), with 0.5 being center.

public float Balance { get; set; }

Property Value

float

CanPause

Gets whether the current media source supports pausing.

public bool CanPause { get; }

Property Value

bool

CanSeek

Gets whether the current media source supports seeking.

public bool CanSeek { get; }

Property Value

bool

CurrentState

Gets the current player state.

public PlayerState CurrentState { get; }

Property Value

PlayerState

CurrentStatistics

Gets current network statistics

public NetworkStat CurrentStatistics { get; }

Property Value

NetworkStat

Duration

Gets the total duration of the media.

public TimeSpan Duration { get; }

Property Value

TimeSpan

EchoCanceller

Gets or sets echo canceller. Should be set only when two-way communication is used.

public IEchoCanceller EchoCanceller { get; set; }

Property Value

IEchoCanceller

InstanceId

Gets the unique identifier for this player instance.

public Guid InstanceId { get; }

Property Value

Guid

IsFullScreen

Gets or sets whether the player is in full screen mode.

public bool IsFullScreen { get; set; }

Property Value

bool

IsLooping

Gets or sets whether playback loops when the end of media is reached.

public bool IsLooping { get; set; }

Property Value

bool

IsMuted

Gets or sets whether audio is muted.

public bool IsMuted { get; set; }

Property Value

bool

PlaybackParameters

Gets or sets the playback parameters. Can only be set before playback starts.

public PlaybackParameters PlaybackParameters { get; set; }

Property Value

PlaybackParameters

PlaybackRate

Gets or sets the playback rate. Normal speed is 1.0. Supports rates from 0.01 to 32.0 (forward) and -0.01 to -32.0 (backward).

public double PlaybackRate { get; set; }

Property Value

double

PlayerBackgroundColor

Gets or sets background color. The value is a hex string. Acceptable formats: #AARRGGBB, #RRGGBB, AARRGGBB, RRGGBB. Examples: #FFFFFFFF, #FFFF00, FFFF0000, FF0000. The default value is #FF000000, or black color.

public string PlayerBackgroundColor { get; set; }

Property Value

string

Position

Gets or sets the current playback position.

public TimeSpan Position { get; set; }

Property Value

TimeSpan

Source

Gets or sets the media source URI.

public Uri Source { get; set; }

Property Value

Uri

SourceMedia

Gets or sets the media source object directly. Use this instead of Source when working with pre-created media sources.

public IMediaSource SourceMedia { get; set; }

Property Value

IMediaSource

Stretch

Gets or sets how the video is stretched to fit the display area.

public StretchType Stretch { get; set; }

Property Value

StretchType

SubtitleDecoration

Gets or sets the subtitle styling options.

public SubtitleDecoration SubtitleDecoration { get; set; }

Property Value

SubtitleDecoration

SubtitleStreamCount

Gets the number of available subtitle streams.

public int SubtitleStreamCount { get; }

Property Value

int

SubtitleStreamIndex

Gets or sets the index of the currently selected subtitle stream.

public int SubtitleStreamIndex { get; set; }

Property Value

int

VideoStreamCount

Gets the number of available video streams.

public int VideoStreamCount { get; }

Property Value

int

VideoStreamIndex

Gets or sets the index of the currently selected video stream.

public int VideoStreamIndex { get; set; }

Property Value

int

Volume

Gets or sets the audio volume. Value ranges from 0.0 (silent) to 1.0 (full volume).

public float Volume { get; set; }

Property Value

float

Methods

Dispose()

Release resources

public void Dispose()

GetAudioMediaType(int)

Gets the media type of the specified audio stream.

public MediaType GetAudioMediaType(int streamIndex)

Parameters

streamIndex int

The audio stream index.

Returns

MediaType

The MediaType of the audio stream, or null if not found.

GetSubtitleMediaType(int)

Gets the media type of the specified subtitle stream.

public MediaType GetSubtitleMediaType(int streamIndex)

Parameters

streamIndex int

The subtitle stream index.

Returns

MediaType

The MediaType of the subtitle stream, or null if not found.

GetVideoMediaType(int)

Gets the media type of the specified video stream.

public MediaType GetVideoMediaType(int streamIndex)

Parameters

streamIndex int

The video stream index.

Returns

MediaType

The MediaType of the video stream, or null if not found.

Pause()

Pauses playback if the media source supports pausing.

public void Pause()

Play()

Starts or resumes playback.

public void Play()

RemoveOverlay()

Removes any overlay image from the video display.

public void RemoveOverlay()

SetOverlay(VersatileBuffer)

Sets an overlay image to be displayed over the video.

public void SetOverlay(VersatileBuffer buffer)

Parameters

buffer VersatileBuffer

The buffer containing the overlay image data.

Stop()

Stops playback and releases resources.

public void Stop()

TakeSnapshot()

Takes a JPEG image snapshot and returns its stream

public Task<Stream> TakeSnapshot()

Returns

Task<Stream>

JPEG image data stream

Events

CurrentStateChanged

Occurs when the current state of the player changes.

public event EventHandler<PlayerState> CurrentStateChanged

Event Type

EventHandler<PlayerState>

Remarks

Subscribe to this event to be notified whenever the player's state transitions, such as from playing to paused or stopped. The event provides the new state as a PlayerState value in the event arguments.

MediaEnded

Occurs when media playback has reached the end of the media source.

public event EventHandler MediaEnded

Event Type

EventHandler

Remarks

Subscribe to this event to be notified when playback completes. This event is typically used to trigger actions such as starting a new media item or updating the user interface when playback finishes.

MediaFailed

Occurs when an error is encountered during media playback or processing.

public event EventHandler<ErrorEventArgs> MediaFailed

Event Type

EventHandler<ErrorEventArgs>

Remarks

This event provides information about the error through the ErrorEventArgs parameter. Handlers can use this information to determine the cause of the failure and take appropriate action, such as displaying an error message or attempting recovery.

MediaOpened

Occurs when the media source has been successfully opened and is ready for playback.

public event EventHandler MediaOpened

Event Type

EventHandler

Remarks

Subscribe to this event to perform actions when the media is ready, such as starting playback or updating the user interface. This event is raised after the media has been loaded and any necessary initialization is complete.

SeekCompleted

Occurs when a seek operation has completed.

public event EventHandler SeekCompleted

Event Type

EventHandler

Remarks

Subscribe to this event to be notified when a seek request finishes, such as after calling a method to change the current position in a media stream. The event is raised on the thread that initiated the seek operation unless otherwise specified by the implementation.

VideoRenderingStarted

Occurs when video rendering begins.

public event EventHandler VideoRenderingStarted

Event Type

EventHandler

Remarks

Subscribe to this event to perform actions when the video rendering process starts. This event is typically raised before any video frames are rendered.