ensureInitialized method

void ensureInitialized()

Ensures the underlying resources are initialized to reduce possible delays when playing once.

Implementation

void ensureInitialized() {
  try {
    // Set `handleAudioSessionActivation` to `false` to avoid stopping
    // background audio on [once].
    _jaPlayer ??= ja.AudioPlayer(handleAudioSessionActivation: false);
  } 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',
      );
    }
  }
}