Class MediaPlayer
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
TRACK_NOT_SET
Indicates that no track is set.
public static readonly int TRACK_NOT_SET
Field Value
Properties
AbsolutePlaybackTime
Gets the absolute playback time when playing streams with absolute timestamps.
public DateTime? AbsolutePlaybackTime { get; }
Property Value
AudioStreamCount
Gets the number of available audio streams.
public int AudioStreamCount { get; }
Property Value
AudioStreamIndex
Gets or sets the index of the currently selected audio stream.
public int AudioStreamIndex { get; set; }
Property Value
AutoPlay
Gets or sets whether playback starts automatically when a source is set.
public bool AutoPlay { get; set; }
Property Value
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
CanPause
Gets whether the current media source supports pausing.
public bool CanPause { get; }
Property Value
CanSeek
Gets whether the current media source supports seeking.
public bool CanSeek { get; }
Property Value
CurrentState
Gets the current player state.
public PlayerState CurrentState { get; }
Property Value
CurrentStatistics
Gets current network statistics
public NetworkStat CurrentStatistics { get; }
Property Value
Duration
Gets the total duration of the media.
public TimeSpan Duration { get; }
Property Value
EchoCanceller
Gets or sets echo canceller. Should be set only when two-way communication is used.
public IEchoCanceller EchoCanceller { get; set; }
Property Value
InstanceId
Gets the unique identifier for this player instance.
public Guid InstanceId { get; }
Property Value
IsFullScreen
Gets or sets whether the player is in full screen mode.
public bool IsFullScreen { get; set; }
Property Value
IsLooping
Gets or sets whether playback loops when the end of media is reached.
public bool IsLooping { get; set; }
Property Value
IsMuted
Gets or sets whether audio is muted.
public bool IsMuted { get; set; }
Property Value
PlaybackParameters
Gets or sets the playback parameters. Can only be set before playback starts.
public PlaybackParameters PlaybackParameters { get; set; }
Property Value
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
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
Position
Gets or sets the current playback position.
public TimeSpan Position { get; set; }
Property Value
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
Stretch
Gets or sets how the video is stretched to fit the display area.
public StretchType Stretch { get; set; }
Property Value
SubtitleDecoration
Gets or sets the subtitle styling options.
public SubtitleDecoration SubtitleDecoration { get; set; }
Property Value
SubtitleStreamCount
Gets the number of available subtitle streams.
public int SubtitleStreamCount { get; }
Property Value
SubtitleStreamIndex
Gets or sets the index of the currently selected subtitle stream.
public int SubtitleStreamIndex { get; set; }
Property Value
VideoStreamCount
Gets the number of available video streams.
public int VideoStreamCount { get; }
Property Value
VideoStreamIndex
Gets or sets the index of the currently selected video stream.
public int VideoStreamIndex { get; set; }
Property Value
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
Methods
Dispose()
Release resources
public void Dispose()
GetAudioMediaType(int)
Gets the media type of the specified audio stream.
public MediaType GetAudioMediaType(int streamIndex)
Parameters
streamIndexintThe audio stream index.
Returns
GetSubtitleMediaType(int)
Gets the media type of the specified subtitle stream.
public MediaType GetSubtitleMediaType(int streamIndex)
Parameters
streamIndexintThe subtitle stream index.
Returns
GetVideoMediaType(int)
Gets the media type of the specified video stream.
public MediaType GetVideoMediaType(int streamIndex)
Parameters
streamIndexintThe video stream index.
Returns
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
bufferVersatileBufferThe 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
Events
CurrentStateChanged
Occurs when the current state of the player changes.
public event EventHandler<PlayerState> CurrentStateChanged
Event Type
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
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
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
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
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
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.