Interface IMediaPlayerControls
- Namespace
- VisioForge.Core.Types
- Assembly
- VisioForge.Core.dll
Defines a standard set of controls for a media player component. This interface provides a common API for controlling playback of media files, including play, pause, stop, seek, and volume adjustments. It also includes asynchronous versions of most methods for use in responsive UI applications.
public interface IMediaPlayerControls : IVideoEffectsControlsImplements
Remarks
This interface inherits from VisioForge.Core.Types.IVideoEffectsControls, providing access to video effect adjustments in addition to playback controls. Implementations of this interface are expected to manage the underlying media playback engine (GStreamer, Media Foundation, FFmpeg, etc.). All asynchronous methods return Task objects to support modern async/await programming patterns. The interface supports both synchronous and asynchronous operations to accommodate different programming styles and scenarios. Position and duration are represented using TimeSpan for precise timing control. The State property provides real-time status of the player (Playing, Paused, Stopped).
Properties
State
Gets the current playback state of the media player (e.g., Playing, Paused, Stopped).
PlaybackState State { get; }Property Value
Methods
Duration()
Gets the total duration of the media.
TimeSpan Duration()Returns
DurationAsync()
Asynchronously gets the total duration of the media.
Task<TimeSpan> DurationAsync()Returns
- Task<TimeSpan>
-
A task that represents the asynchronous operation. The task result contains the media's duration as a TimeSpan.
GetFileThumbnail(string)
Extracts a thumbnail image from a specified media file.
SKBitmap GetFileThumbnail(string filename)Parameters
filenamestring-
The path to the media file.
Returns
- SKBitmap
-
An SkiaSharp.SKBitmap containing the thumbnail image, or
nullif a thumbnail could not be extracted.
NextFrame()
Advances playback to the next frame. This is useful for frame-by-frame analysis.
bool NextFrame()Returns
- bool
-
trueif the operation is successful,falseotherwise.
OpenAsync(string)
Asynchronously opens a media file from a specified path.
Task<bool> OpenAsync(string path)Parameters
pathstring-
The file path or URL of the media to open.
Returns
- Task<bool>
-
A task that represents the asynchronous operation. The task result contains
trueif the file was opened successfully,falseotherwise.
Pause()
Pauses the currently playing media.
bool Pause()Returns
- bool
-
trueif the operation is successful,falseotherwise.
PauseAsync()
Asynchronously pauses the currently playing media.
Task<bool> PauseAsync()Returns
- Task<bool>
-
A task that represents the asynchronous operation. The task result contains
trueif successful,falseotherwise.
Play(bool)
Starts or preloads the media for playback.
bool Play(bool onlyPreload = false)Parameters
onlyPreloadbool-
If set to
true, the media is loaded and ready to play but does not start automatically.
Returns
- bool
-
trueif the operation is successful,falseotherwise.
PlayAsync(bool)
Asynchronously starts or preloads the media for playback.
Task<bool> PlayAsync(bool onlyPreload = false)Parameters
onlyPreloadbool-
If set to
true, the media is loaded and ready to play but does not start automatically.
Returns
- Task<bool>
-
A task that represents the asynchronous operation. The task result contains
trueif successful,falseotherwise.
Position_Get()
Gets the current playback position.
TimeSpan Position_Get()Returns
Position_GetAsync()
Asynchronously gets the current playback position.
Task<TimeSpan> Position_GetAsync()Returns
- Task<TimeSpan>
-
A task that represents the asynchronous operation. The task result contains the current position as a TimeSpan.
Position_Set(TimeSpan, bool)
Sets the current playback position to a specified time.
void Position_Set(TimeSpan position, bool seekToKeyframe = false)Parameters
positionTimeSpan-
The time to seek to.
seekToKeyframebool-
If set to
true, the seek will be to the nearest keyframe, which is faster but less precise.
Position_SetAsync(TimeSpan, bool)
Asynchronously sets the current playback position to a specified time.
Task Position_SetAsync(TimeSpan position, bool seekToKeyframe = false)Parameters
positionTimeSpan-
The time to seek to.
seekToKeyframebool-
If set to
true, the seek will be to the nearest keyframe, which is faster but less precise.
Returns
- Task
-
A task that represents the asynchronous operation.
PrevFrame()
Moves playback to the previous frame. This is useful for frame-by-frame analysis.
bool PrevFrame()Returns
- bool
-
trueif the operation is successful,falseotherwise.
Resume()
Resumes playback from a paused state.
bool Resume()Returns
- bool
-
trueif the operation is successful,falseotherwise.
ResumeAsync()
Asynchronously resumes playback from a paused state.
Task<bool> ResumeAsync()Returns
- Task<bool>
-
A task that represents the asynchronous operation. The task result contains
trueif successful,falseotherwise.
SetSpeed(double)
Sets the playback speed.
bool SetSpeed(double speed)Parameters
speeddouble-
The playback speed, where 1.0 is normal speed, 0.5 is half speed, and 2.0 is double speed.
Returns
- bool
-
trueif the operation is successful,falseotherwise.
SetSpeedAsync(double)
Asynchronously sets the playback speed.
Task<bool> SetSpeedAsync(double speed)Parameters
speeddouble-
The playback speed.
Returns
- Task<bool>
-
A task that represents the asynchronous operation. The task result contains
trueif successful,falseotherwise.
Stop()
Stops playback and resets the media position to the beginning.
void Stop()StopAsync()
Asynchronously stops playback and resets the media position to the beginning.
Task StopAsync()Returns
- Task
-
A task that represents the asynchronous operation.
Volume_Get()
Gets the current audio volume level.
double Volume_Get()Returns
- double
-
The current volume level.
Volume_Set(double)
Sets the audio volume level.
void Volume_Set(double volume)Parameters
volumedouble-
The volume level, typically from 0.0 (silent) to 1.0 (full volume).