VideoPlayerController class

Controls a platform video player, and provides updates when the state is changing.

Instances must be initialized with initialize.

The video is displayed in a Flutter app by creating a VideoPlayer widget.

To reclaim the resources used by the player call dispose.

After dispose all further calls are ignored.

Inheritance

Constructors

VideoPlayerController.asset(String dataSource, {String? package, Future<ClosedCaptionFile>? closedCaptionFile, VideoPlayerOptions? videoPlayerOptions})
Constructs a VideoPlayerController playing a video from an asset.
VideoPlayerController.contentUri(Uri contentUri, {Future<ClosedCaptionFile>? closedCaptionFile, VideoPlayerOptions? videoPlayerOptions})
Constructs a VideoPlayerController playing a video from a contentUri.
VideoPlayerController.file(File file, {Future<ClosedCaptionFile>? closedCaptionFile, VideoPlayerOptions? videoPlayerOptions})
Constructs a VideoPlayerController playing a video from a file.
VideoPlayerController.network(String dataSource, {VideoFormat? formatHint, Future<ClosedCaptionFile>? closedCaptionFile, VideoPlayerOptions? videoPlayerOptions, Map<String, String> httpHeaders = const <String, String>{}, DrmConfigs? drmConfigs, Map<String, dynamic>? playerOptions, Map<StreamingPropertyType, String>? streamingProperty})
Constructs a VideoPlayerController playing a video from obtained from the network.

Properties

audioTracks Future<List<AudioTrack>?>
The audio tracks in the current video.
no setter
closedCaptionFile Future<ClosedCaptionFile>?
Optional field to specify a file containing the closed captioning.
final
dataSource String
The URI to the video file. This will be in different formats depending on the DataSourceType of the original video.
final
dataSourceType DataSourceType
Describes the type of data source this VideoPlayerController is constructed with.
final
drmConfigs DrmConfigs?
Configurations for playing DRM content (optional). Only for VideoPlayerController.network.
final
duration Future<DurationRange?>
The duration in the current video.
no setter
formatHint VideoFormat?
Android only. Will override the platform's generic file format detection with whatever is set here.
final
hashCode int
The hash code for this object.
no setterinherited
hasListeners bool
Whether any listeners are currently registered.
no setterinherited
httpHeaders Map<String, String>
HTTP headers used for the request to the dataSource. Only for VideoPlayerController.network. Always empty for other video types.
final
package String?
Only set for asset videos. The package that the asset was loaded from.
final
playerId int
This is just exposed for testing. It shouldn't be used by anyone depending on the plugin.
no setter
playerOptions Map<String, dynamic>?
Player Options used for add additional parameters. Only for VideoPlayerController.network.
final
position Future<Duration?>
The position in the current video.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
streamingProperty Map<StreamingPropertyType, String>?
Sets specific feature values for HTTP, MMS, or specific streaming engine (Smooth Streaming, HLS, DASH, DivX Plus Streaming, or Widevine). The available streaming properties depend on the streaming protocol or engine. Only for VideoPlayerController.network.
final
textTracks Future<List<TextTrack>?>
The text tracks in the current video.
no setter
value VideoPlayerValue
The current value stored in this notifier.
getter/setter pairinherited
videoPlayerOptions VideoPlayerOptions?
Provide additional configuration options (optional). Like setting the audio mode to mix
final
videoTracks Future<List<VideoTrack>?>
The video tracks in the current video.
no setter

Methods

activate() Future<bool>
Sets the video activated. Use it if create two native players.
addListener(VoidCallback listener) → void
Register a closure to be called when the object changes.
inherited
deactivate() Future<bool>
Sets the video deactivated. Use it if create two native players.
dispose() Future<void>
Discards any resources used by the object. After this is called, the object is not in a usable state and should be discarded (calls to addListener will throw after the object is disposed).
override
getStreamingProperty(StreamingPropertyType type) Future<String>
Retrieves a specific property value obtained by the streaming engine (Smooth Streaming, HLS, DASH, or Widevine).
initialize() Future<void>
Attempts to open the given dataSource and load metadata about the video.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
notifyListeners() → void
Call all the registered listeners.
inherited
pause() Future<void>
Pauses the video.
play() Future<void>
Starts playing the video.
removeListener(VoidCallback listener) → void
Remove a previously registered closure from the list of closures that are notified when the object changes.
override
seekTo(Duration position) Future<void>
Sets the video's current timestamp to be at moment. The next time the video is played it will resume from the given moment.
setBufferConfig(BufferConfigType type, int value) Future<bool>
Sets the buffer size for the play and resume scenarios. The time buffer size must be at least 4 seconds. For example, if a 10 second buffer size is set, playback can only start or resume after 10 seconds of media has accumulated in the buffer. Play scenarios include user-initiated streaming playback and whenever media playback is starting for the first time. Resume scenarios include resuming playback after pause or seek operations, or when lack of data causes playback rebuffering.
setCaptionOffset(Duration offset) → void
Sets the caption offset.
setLooping(bool looping) Future<void>
Sets whether or not the video should loop after playing once. See also VideoPlayerValue.isLooping.
setPlaybackSpeed(double speed) Future<void>
Sets the playback speed of this.
setStreamingProperty(StreamingPropertyType type, String value) Future<void>
Sets specific feature values for HTTP, MMS, or specific streaming engine (Smooth Streaming, HLS, DASH, DivX Plus Streaming, or Widevine). The available streaming properties depend on the streaming protocol or engine. Use the CUSTOM_MESSAGE property for streaming engine or CP-specific settings.
setTrackSelection(Track track) Future<bool>
Sets the selected tracks.
setVolume(double volume) Future<void>
Sets the audio volume of this.
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Constants

kUninitializedPlayerId → const int
The id of a player that hasn't been initialized.