VideoPlayer class is the primary interface for controlling video playback. It provides methods for playback control, seeking, and managing player state, as well as properties for configuring audio, volume, and playback behavior.
Constructor
The video source to play. Can be:
string- URL to a video filenumber- Require statement for local video fileVideoConfig- Configuration object with URI and additional options
Example
Properties
source
The current video source. This property is immutable. To change the source, use the
replaceSourceAsync() method.status
The current status of the player.Possible values:
'idle'- The player is idle (source is not loaded)'loading'- The player is loading the source'readyToPlay'- The player is ready to play (source is loaded)'error'- The player encountered an error
duration
The total duration of the video in seconds (1.0 = 1 second). Returns
NaN if duration is not available.currentTime
The current playback position in seconds. Can be read to get the current position or set to seek to a specific time.
volume
The playback volume from 0.0 to 1.0 (0% to 100%). If the player is muted, volume will return 0.0.
muted
Whether the player is muted. When
true, audio is silenced regardless of volume setting.loop
Whether the video should loop automatically when it reaches the end.
rate
The playback speed multiplier. Default is 1.0 (normal speed). Set to 0 to pause the video.
isPlaying
Whether the video is currently playing. This is a read-only property. Use
play() and pause() methods to control playback.mixAudioMode
Controls how this player’s audio mixes with other audio sources.Possible values:
'auto'- Uses default behavior for the player (default)'mixWithOthers'- Mix with other audio players'doNotMix'- Stop other audio when this player plays'duckOthers'- Lower volume of other audio when this player plays
ignoreSilentSwitchMode
Controls whether the player respects the device’s silent switch. iOS only.Possible values:
'auto'- Uses default behavior (default)'ignore'- Play audio even when silent switch is on'obey'- Respect the silent switch
playInBackground
Whether the player should continue playing when the app is in the background. Default is
false.This can override
playWhenInactive.playWhenInactive
Whether the player should continue playing when the app is inactive (e.g., when Control Center is opened). Default is
false. iOS only.This can be overridden by
playInBackground.showNotificationControls
Whether to show playback controls in the system notification area.
selectedTrack
The currently selected text/subtitle track, or
undefined if no track is selected.Methods
initialize()
Manually initialize the player. You don’t need to call this method unless you setinitializeOnCreation to false in the VideoConfig.
preload()
Preload the video to avoid delay when playback starts. This is useful for better user experience but preloading too many videos can lead to memory or performance issues.play()
Start or resume video playback.pause()
Pause video playback.seekTo()
Seek to a specific time position in the video.The time position to seek to in seconds. Will be clamped to the valid range (0 to duration).
This has the same effect as setting the
currentTime property.seekBy()
Seek forward or backward by a relative amount of time.The time to seek from the current position in seconds. Negative values seek backward. Will be clamped to valid range.
replaceSourceAsync()
Replace the current video source with a new one, or clear the source.The new video source, or
null to clear the current source and release resources.getAvailableTextTracks()
Get all available text/subtitle tracks for the current video.selectTextTrack()
Select a specific text/subtitle track to display, or clear the current selection.The text track to select, or
null to unselect the current track.release()
Release the player’s native resources and destroy the player. After calling this method, the player is no longer usable and accessing any properties or methods will throw an error.Complete Example
See Also
- VideoConfig - Configuration options for video sources
- Events - Listen to player events
- Video Component - UI component for displaying video