play method

Future<int> play(
  1. String url, {
  2. bool? isLocal,
  3. double volume = 1.0,
  4. Duration? position,
  5. bool respectSilence = false,
  6. bool stayAwake = false,
  7. bool duckAudio = false,
  8. bool recordingActive = false,
})

Plays an audio.

If isLocal is true, url must be a local file system path. If isLocal is false, url must be a remote URL.

respectSilence and stayAwake are not implemented on macOS.

Implementation

Future<int> play(
  String url, {
  bool? isLocal,
  double volume = 1.0,
  // position must be null by default to be compatible with radio streams
  Duration? position,
  bool respectSilence = false,
  bool stayAwake = false,
  bool duckAudio = false,
  bool recordingActive = false,
}) async {
  isLocal ??= isLocalUrl(url);

  final int result = await _invokeMethod('play', {
    'url': url,
    'isLocal': isLocal,
    'volume': volume,
    'position': position?.inMilliseconds,
    'respectSilence': respectSilence,
    'stayAwake': stayAwake,
    'duckAudio': duckAudio,
    'recordingActive': recordingActive,
  });

  if (result == 1) {
    state = AudioPlayerState.PLAYING;
  }

  return result;
}