play method

void play({
  1. required Sound sound,
  2. String? customSound,
  3. String? packageName,
  4. bool? isLooping = false,
})

Implementation

void play(
    {required Sound sound,
    String? customSound,
    String? packageName, // Use it only when using other plugin
       bool? isLooping = false,
    }) async {
  String soundPath = "";

  if (customSound != null && customSound.isNotEmpty) {
    soundPath = customSound;

    if (Platform.isAndroid && packageName != null && packageName.isNotEmpty) {
      soundPath = soundPath;
    }
  } else {
    soundPath = _getDefaultSoundPath(sound);
    packageName ??= UIConstants.packageName;
    if (Platform.isAndroid) {
      soundPath = "packages/$packageName/$soundPath";
    }
  }
  await UIConstants.channel.invokeMethod("playCustomSound",
      {'assetAudioPath': soundPath, 'package': packageName, 'isLooping': isLooping});
}