load method

Future<Duration?> load()

Starts loading the current audio source and returns the audio duration as soon as it is known, or null if unavailable.

This method throws:

  • Exception if no audio source has been previously set.
  • PlayerException if the audio source was unable to be loaded.
  • PlayerInterruptedException if another call to load happened before this call completed or the player was stopped or disposed of before the call could complete.

Implementation

Future<Duration?> load() async {
  if (_disposed) return null;
  if (_audioSource == null) {
    throw Exception('Must set AudioSource before loading');
  }
  if (_active) {
    final initialSeekValues = _initialSeekValues;
    _initialSeekValues = null;
    return await _load(await _platform, _audioSource!,
        initialSeekValues: initialSeekValues);
  } else {
    // This will implicitly load the current audio source.
    return await _setPlatformActive(true);
  }
}