ensureInitialized method
Ensures the underlying resources are initialized to reduce possible delays when playing once.
Implementation
void ensureInitialized() {
try {
if (_isMobile) {
// Set `handleAudioSessionActivation` to `false` to avoid stopping
// background audio on [once].
_jaPlayer ??= ja.AudioPlayer(handleAudioSessionActivation: false);
} else {
_player ??= Player();
}
} catch (e) {
// If [Player] isn't available on the current platform, this throws a
// `null check operator used on a null value`.
if (e is! TypeError) {
Log.error(
'Failed to initialize `Player`: ${e.toString()}',
'$runtimeType',
);
}
}
}