clone method

Future<Video> clone ()

Clone this video instance and the underlying HTML VideoElement to play the video independantly from this video.

Implementation

Future<Video> clone() {
  var videoElement = this.videoElement.clone(true) as VideoElement;
  var completer = Completer<Video>();
  StreamSubscription onCanPlaySubscription;
  StreamSubscription onErrorSubscription;

  void onCanPlay(html.Event e) {
    var video = Video._(videoElement);
    video.volume = volume;
    video.muted = muted;
    onCanPlaySubscription.cancel();
    onErrorSubscription.cancel();
    completer.complete(video);
  }

  void onError(html.Event e) {
    onCanPlaySubscription.cancel();
    onErrorSubscription.cancel();
    var error = videoElement.error;
    var loadError = LoadError('Failed to clone video.', error);
    completer.completeError(loadError);
  }

  onCanPlaySubscription = videoElement.onCanPlay.listen(onCanPlay);
  onErrorSubscription = videoElement.onError.listen(onError);
  return completer.future;
}