openMedia method
- {required BuildContext context,
- required WidgetRef ref,
- required MediaSource mediaSource,
- bool killOnPop = false,
- bool pushReplacement = false,
- 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),
),
);
}
}