TextTrackListImplWeb constructor

TextTrackListImplWeb(
  1. THEOplayerArrayList<THEOplayerTextTrack> _theoPlayerTextTracks
)

Implementation

TextTrackListImplWeb(this._theoPlayerTextTracks) {
  addTrackEventListener = allowInterop((AddTextTrackEventJS event) {
    var track = event.track;
    var flutterTrack = TextTrackImplWeb(
      track.id,
      track.uid,
      track.label,
      track.language,
      track.kind,
      track.inBandMetadataTrackDispatchType,
      toFlutterTextTrackReadyState(track.readyState),
      toFlutterTextTrackType(track.type),
      new Cues(),
      new Cues(),
      track.src,
      track.forced,
      toFlutterTextTrackMode(track.mode),
      track
    );
    add(flutterTrack);
    dispatchEvent(AddTextTrackEvent(track: flutterTrack));
  });

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

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

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

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

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

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

  _theoPlayerTextTracks.addEventListener(TextTracksEventTypes.ADDTRACK.toLowerCase(), addTrackEventListener);
  _theoPlayerTextTracks.addEventListener(TextTracksEventTypes.REMOVETRACK.toLowerCase(), removeTrackEventListener);
  _theoPlayerTextTracks.addEventListener(TextTracksEventTypes.CHANGE.toLowerCase(), changeTrackEventListener);
}