play method

Future<AudioPlayer> play(
  1. String fileName, {
  2. double volume = 1.0,
  3. bool? isNotification,
  4. PlayerMode mode = PlayerMode.MEDIA_PLAYER,
  5. bool stayAwake = false,
  6. bool recordingActive = false,
  7. bool? duckAudio,
})

Plays the given fileName.

If the file is already cached, it plays immediately. Otherwise, first waits for the file to load (might take a few milliseconds). It creates a new instance of AudioPlayer, so it does not affect other audios playing (unless you specify a fixedPlayer, in which case it always use the same). The instance is returned, to allow later access (either way), like pausing and resuming.

isNotification and stayAwake are not implemented on macOS

Implementation

Future<AudioPlayer> play(
  String fileName, {
  double volume = 1.0,
  bool? isNotification,
  PlayerMode mode = PlayerMode.MEDIA_PLAYER,
  bool stayAwake = false,
  bool recordingActive = false,
  bool? duckAudio,
}) async {
  final uri = await load(fileName);
  final player = _player(mode);
  if (fixedPlayer != null) {
    await player.setReleaseMode(ReleaseMode.STOP);
  }
  await player.play(
    uri.toString(),
    volume: volume,
    respectSilence: isNotification ?? respectSilence,
    stayAwake: stayAwake,
    recordingActive: recordingActive,
    duckAudio: duckAudio ?? this.duckAudio,
  );
  return player;
}