clone method
Clone this video instance and the underlying HTML VideoElement to play the video independantly from this video.
Implementation
Future<Video> clone() {
final videoElement = this.videoElement.clone(true) as VideoElement;
final completer = Completer<Video>();
late StreamSubscription<html.Event> onCanPlaySubscription;
late StreamSubscription<html.Event> onErrorSubscription;
void onCanPlay(html.Event e) {
final 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();
final error = videoElement.error;
final loadError = LoadError('Failed to clone video.', error);
completer.completeError(loadError);
}
onCanPlaySubscription = videoElement.onCanPlay.listen(onCanPlay);
onErrorSubscription = videoElement.onError.listen(onError);
return completer.future;
}