play method

  1. @override
Future<void> play({
  1. AndroidSound? android,
  2. IosSound? ios,
  3. String? fromAsset,
  4. String? fromFile,
  5. double? volume,
  6. bool? looping,
  7. bool? asAlarm,
})
override

This is generic method allowing you to specify individual sounds you wish to be played for each platform

asAlarm is an Android only flag that lets play given sound as an alarm, that is, phone will make sound even if it is in silent or vibration mode.

See also:

Implementation

@override
Future<void> play({
  AndroidSound? android,
  IosSound? ios,
  String? fromAsset,
  String? fromFile,
  double? volume,
  bool? looping,
  bool? asAlarm,
}) async {
  if (fromAsset == null && android == null && ios == null) {
    throw "Please specify the sound source.";
  }
  if (fromFile != null) {
    fromAsset = await _generateFileUri(fromFile);
  } else if (fromAsset == null) {
    if (android == null) {
      throw "Please specify android sound.";
    }
    if (ios == null) {
      throw "Please specify ios sound.";
    }
  } else {
    fromAsset = await _generateAssetUri(fromAsset);
  }
  try {
    var args = <String, dynamic>{};
    if (android != null) args['android'] = android.value;
    if (ios != null) args['ios'] = ios.value;
    if (fromAsset != null) args['uri'] = fromAsset;
    if (looping != null) args['looping'] = looping;
    if (volume != null) args['volume'] = volume;
    if (asAlarm != null) args['asAlarm'] = asAlarm;

    _channel.invokeMethod('play', args);
  } on PlatformException {
    // Not handled
  }
}