MediaPlayer
The MediaPlayer
class provides the core functionality for media playback in Avalonia applications. It handles media
loading, playback control, and platform-specific backend management, serving as the engine behind
the MediaPlayerControl
.
Properties
Media Source Properties
Property | Type | Description |
---|---|---|
Source | MediaSource | Gets or sets the media source to be played (UriSource or StreamSource ). |
Playback Properties
Property | Type | Description |
---|---|---|
Position | TimeSpan | Gets or sets the current playback position. |
Duration | TimeSpan? | Gets the total duration of the media. Null for non-seekable media. |
LoadedBehavior | MediaPlayerLoadedBehavior | Gets or sets playback behavior when media is loaded. |
State Properties
Property | Type | Description |
---|---|---|
IsSeekable | bool | Gets whether the current media supports seeking. |
IsBuffering | bool | Gets whether the media is currently buffering. |
BufferProgress | double? | Gets buffer progress (0.0-1.0). Null if not available. |
HasVideo | bool | Gets whether the current media contains video content. |
LastErrorMessage | string | Gets the most recent error message in error state. |
Audio Properties
Property | Type | Description |
---|---|---|
Volume | double | Gets or sets the playback volume (0.0-1.0). |
IsMuted | bool | Gets or sets whether audio is muted. |
Advanced Properties
Property | Type | Description |
---|---|---|
Statistics | MediaStatistics | Gets playback statistics information if available. |
ForceVlcBackend | bool (static) | Forces the use of VLC backend (debugging only). |
Events
Event | Description |
---|---|
NaturalSizeChanged | Occurs when the natural size of the video changes. |
MediaPrepared | Occurs when the media has been prepared and is ready. |
MediaStarted | Occurs when media playback has started. |
MediaPaused | Occurs when media playback has been paused. |
MediaStopped | Occurs when media playback has been stopped. |
MediaPlaybackCompleted | Occurs when media playback has completed. |
ErrorOccurred | Occurs when an error is encountered. |
PropertyChanged | Standard INotifyPropertyChanged event. |
Methods
Method | Return Type | Description |
---|---|---|
InitializeAsync() | Task | Initializes the media player and its backend. |
PrepareAsync() | Task | Prepares the media for playback. |
PlayAsync() | Task | Starts or resumes media playback. |
PauseAsync() | Task | Pauses media playback. |
StopAsync() | Task | Stops media playback. |
ReleaseAsync() | Task | Releases resources for the current media. |
UnInitialize() | Task | Releases all resources used by the player. |
Backend Architecture
The MediaPlayer
uses a pluggable backend architecture to support different platforms:
The backend selection is automatic based on the platform: