play method
void
play({})
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";
}
}
try {
await UIConstants.channel.invokeMethod("playCustomSound",
{'assetAudioPath': soundPath, 'package': packageName, 'isLooping': isLooping});
} catch (e) {
if (e.toString().contains('AUDIO_FOCUS_FAILED')) {
debugPrint('Audio focus not available. Notification sound skipped.');
} else {
debugPrint('Error playing sound: $e');
}
}
}