setupSubtitleSource method

Future<void> setupSubtitleSource(
  1. PipFlutterPlayerSubtitlesSource subtitlesSource, {
  2. bool sourceInitialize = false,
})

Setup subtitles to be displayed from given subtitle source. If subtitles source is segmented then don't load videos at start. Videos will load with just in time policy.

Implementation

Future<void> setupSubtitleSource(
    PipFlutterPlayerSubtitlesSource subtitlesSource,
    {bool sourceInitialize = false}) async {
  _pipFlutterPlayerSubtitlesSource = subtitlesSource;
  subtitlesLines.clear();
  _asmsSegmentsLoaded.clear();
  _asmsSegmentsLoading = false;

  if (subtitlesSource.type != PipFlutterPlayerSubtitlesSourceType.none) {
    if (subtitlesSource.asmsIsSegmented == true) {
      return;
    }
    final subtitlesParsed =
        await PipFlutterPlayerSubtitlesFactory.parseSubtitles(
            subtitlesSource);
    subtitlesLines.addAll(subtitlesParsed);
  }

  _postEvent(
      PipFlutterPlayerEvent(PipFlutterPlayerEventType.changedSubtitles));
  if (!_disposed && !sourceInitialize) {
    _postControllerEvent(PipFlutterPlayerControllerEvent.changeSubtitles);
  }
}