VideoTrackListImplWeb constructor

VideoTrackListImplWeb(
  1. THEOplayerArrayList<THEOplayerVideoTrack> _theoPlayerVideoTracks
)

Implementation

VideoTrackListImplWeb(this._theoPlayerVideoTracks) {
  addTrackEventListener = allowInterop((AddVideoTrackEventJS event) {
    var track = event.track;

    VideoQualities qualities = toFlutterVideoQualities(track.qualities);

    var flutterTrack = VideoTrackImplWeb(
      track.id,
      track.uid,
      track.label,
      track.language,
      track.kind,
      qualities,
      track.enabled,
      track
    );
    add(flutterTrack);
    dispatchEvent(AddVideoTrackEvent(track: flutterTrack));
  });

  removeTrackEventListener = allowInterop((RemoveVideoTrackEventJS event) {
    var track = event.track;

    var flutterTrack = firstWhereOrNull((item) => item.uid == track.uid);
    if (flutterTrack == null) {
      return;
    }

    remove(flutterTrack);
    dispatchEvent(RemoveVideoTrackEvent(track: flutterTrack));
  });

  //only triggered for enable/disable
  changeTrackEventListener = allowInterop((VideoTrackListChangeEventJS event) {
    var track = event.track;

    var flutterTrack = firstWhereOrNull((item) => item.uid == track.uid);
    if (flutterTrack == null) {
      return;
    }

    dispatchEvent(VideoTrackListChangeEvent(track: flutterTrack));
  });

  _theoPlayerVideoTracks.addEventListener(VideoTracksEventTypes.ADDTRACK.toLowerCase(), addTrackEventListener);
  _theoPlayerVideoTracks.addEventListener(VideoTracksEventTypes.REMOVETRACK.toLowerCase(), removeTrackEventListener);
  _theoPlayerVideoTracks.addEventListener(VideoTracksEventTypes.CHANGE.toLowerCase(), changeTrackEventListener);
}