openMedia method

Future<void> openMedia(
  1. {required BuildContext context,
  2. required WidgetRef ref,
  3. required MediaSource mediaSource,
  4. bool killOnPop = false,
  5. bool pushReplacement = false,
  6. MediaItem? item}
)

A helper function for launching a media source.

Implementation

Future<void> openMedia({
  required BuildContext context,
  required WidgetRef ref,
  required MediaSource mediaSource,
  bool killOnPop = false,
  bool pushReplacement = false,
  MediaItem? item,
}) async {
  if (killOnPop) {
    _shouldKillMediaOnPop = true;
  }

  mediaSource.clearCurrentSentence();
  mediaSource.clearExtraData();
  await initialiseAudioHandler();

  _currentMediaSource = mediaSource;
  if (item != null) {
    _currentMediaItem = item;
  }

  _currentSubtitleOptions = ValueNotifier(subtitleOptions);
  _overrideDictionaryColor = null;
  _overrideDictionaryTheme = null;

  await Wakelock.enable();
  await SystemChrome.setEnabledSystemUIMode(SystemUiMode.immersiveSticky);

  if (item != null && mediaSource.implementsHistory) {
    addMediaItem(item);
  }

  if (pushReplacement) {
    await Navigator.pushReplacement(
      _navigatorKey.currentContext!,
      MaterialPageRoute(
        builder: (context) => mediaSource.buildLaunchPage(item: item),
      ),
    );
  } else {
    await Navigator.push(
      _navigatorKey.currentContext!,
      MaterialPageRoute(
        builder: (context) => mediaSource.buildLaunchPage(item: item),
      ),
    );
  }
}