setVideoTrack method

  1. @override
Future<void> setVideoTrack(
  1. VideoTrack track, {
  2. bool synchronized = true,
})
override

Sets the current VideoTrack for video output.

  • Currently selected VideoTrack can be accessed using state.track.video or stream.track.video.
  • The list of currently available VideoTracks can be obtained accessed using state.tracks.video or stream.tracks.video.

Implementation

@override
Future<void> setVideoTrack(VideoTrack track, {bool synchronized = true}) {
  Future<void> function() async {
    if (disposed) {
      throw AssertionError('[Player] has been disposed');
    }
    await waitForPlayerInitialization;
    await waitForVideoControllerInitializationIfAttached;

    final name = 'vid'.toNativeUtf8();
    final value = track.id.toNativeUtf8();
    mpv.mpv_set_property_string(
      ctx,
      name.cast(),
      value.cast(),
    );
    calloc.free(name);
    calloc.free(value);
    state = state.copyWith(
      track: state.track.copyWith(
        video: track,
      ),
    );
    if (!trackController.isClosed) {
      trackController.add(state.track);
    }
  }

  if (synchronized) {
    return lock.synchronized(function);
  } else {
    return function();
  }
}