ensureInitialized method

Future<void> ensureInitialized()

Ensure the global platform is initialized.

Implementation

Future<void> ensureInitialized() async {
  if (_lastGlobalAudioplayersPlatform != _platform) {
    // This will clear all open players on the platform when a full restart is
    // performed.
    _lastGlobalAudioplayersPlatform = _platform;
    _initCompleter = Completer<void>();
    try {
      await _platform.init();
      _initCompleter?.complete();
    } on Exception catch (e, stackTrace) {
      _initCompleter?.completeError(e, stackTrace);
    }
  }
  await _initCompleter?.future;
}