play method

Future<void> play(
  1. Source source, {
  2. double? volume,
  3. double? balance,
  4. AudioContext? ctx,
  5. Duration? position,
  6. PlayerMode? mode,
})

Play an audio source.

To reduce preparation latency, instead consider calling setSource beforehand and then resume separately.

Implementation

Future<void> play(
  Source source, {
  double? volume,
  double? balance,
  AudioContext? ctx,
  Duration? position,
  PlayerMode? mode,
}) async {
  desiredState = PlayerState.playing;

  if (mode != null) {
    await setPlayerMode(mode);
  }
  if (volume != null) {
    await setVolume(volume);
  }
  if (balance != null) {
    await setBalance(balance);
  }
  if (ctx != null) {
    await setAudioContext(ctx);
  }

  await setSource(source);
  if (position != null) {
    await seek(position);
  }

  await _resume();
}