AudioTrackListImplWeb constructor

AudioTrackListImplWeb(
  1. THEOplayerArrayList<THEOplayerAudioTrack> _theoPlayerAudioTracks
)

Implementation

AudioTrackListImplWeb(this._theoPlayerAudioTracks) {
  addTrackEventListener = allowInterop((AddAudioTrackEventJS event) {
    var track = event.track;

    AudioQualities qualities = toFlutterAudioQualities(track.qualities);

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

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

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

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

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

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

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

  _theoPlayerAudioTracks.addEventListener(AudioTracksEventTypes.ADDTRACK.toLowerCase(), addTrackEventListener);
  _theoPlayerAudioTracks.addEventListener(AudioTracksEventTypes.REMOVETRACK.toLowerCase(), removeTrackEventListener);
  _theoPlayerAudioTracks.addEventListener(AudioTracksEventTypes.CHANGE.toLowerCase(), changeTrackEventListener);
}