play method

Future<void> play(
  1. String fileName, {
  2. double volume = 1,
})

Plays and loops a background music file specified by fileName.

The volume can be specified in the optional named parameter volume where 0 means off and 1 means max.

It is safe to call this function even when a current BGM track is playing.

Implementation

Future<void> play(String fileName, {double volume = 1}) async {
  await audioPlayer.release();
  await audioPlayer.setReleaseMode(ReleaseMode.loop);
  await audioPlayer.setVolume(volume);
  await audioPlayer.setSource(AssetSource(fileName));
  await audioPlayer.resume();
  isPlaying = true;
}