setTrack method Null safety
- MediaStreamTrack? track
Sets the the current video track of the VideoView(s) that this controller is
connected to, on unsets it if track
is null.
Does nothing if the id of the given track's ID is the same as the current track's ID.
Throws StateError if the track no longer exists.
Implementation
Future<void> setTrack(MediaStreamTrack? track) => _lock.synchronized(() async {
if (track?.id == _trackId || _wasDisposed) return;
_trackId = track?.id;
final platformBridge = await PlatformBridge.instance;
await _renderer?.let(platformBridge.disposeTextureRenderer);
_lastUpdate = null;
_renderer = await track?.let(platformBridge.renderTrackTexture);
if (track == null) {
await _trackUpdateSubscription?.cancel();
_trackUpdateSubscription = null;
} else {
_trackUpdateSubscription ??= platformBridge.platformEvents.listen(_handlePlatformEvent);
}
notifyListeners();
});