Video class

The Video class is used to load and control videos.

The video will be rendered to a RenderTexture and therefore can be used like any other static image content. The sample below creates a BitmapData from the video and also a VideoObject display object.

var resourceManager = ResourceManager();
resourceManager.addVideo("vid1", "video.webm");
resourceManager.load().then((_) {

  var video = resourceManager.getVideo("vid1");
  video.play();

  // create a BitmapData used with a Bitmap
  var bitmapData = BitmapData.fromVideoElement(video.videoElement);
  var bitmap = Bitmap(bitmapData);
  stage.addChild(bitmap);

  // create a convenient VideoObject display object
  var videoObject = VideoObject(video);
  stage.addChild(videoObject);
});

Please note that a video can be used with more than one display objects. To control the video independantly from each other the clone method creates a clone of this instance.

video.clone().then((newVideo) => {
  var videoObject = VideoObject(newVideo);
  stage.addChild(videoObject);
});

If the video codec of the file is not supported by the browser, the runtime will automatically fallback to a different codec. Therefore please provide the same video with different codecs. The supported codecs are webm, mp4 and ogg.

Properties

currentTime num
Get or set the current time (playback position) of the video.
getter/setter pair
hashCode int
The hash code for this object.
no setterinherited
isPlaying bool
Returns if the video is playing or not.
no setter
loop bool
getter/setter pair
muted bool
Get or set if the video is muted.
getter/setter pair
onEnded Stream<Video>
no setter
onError Stream<Video>
no setter
onPause Stream<Video>
no setter
onPlay Stream<Video>
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
videoElement VideoElement
final
volume num
Get or set the volume of the video.
getter/setter pair

Methods

clone() Future<Video>
Clone this video instance and the underlying HTML VideoElement to play the video independantly from this video.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
pause() → void
Pause the video.
play() → void
Play the video.
toString() String
A string representation of this object.
inherited

Operators

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

Static Properties

defaultLoadOptions VideoLoadOptions
The default video load options are used if no custom video load options are provided for the load method. This default video load options enable all supported video file formats: mp4, webm and ogg.
getter/setter pair

Static Methods

load(String url, [VideoLoadOptions? videoLoadOptions]) Future<Video>
Use this method to load a video from a given url. If you don't provide videoLoadOptions the defaultLoadOptions will be used.