once method
- AudioSource sound, {
- AudioMode? mode = AudioMode.sound,
Plays the provided sound once.
Implementation
Future<void> once(
AudioSource sound, {
AudioMode? mode = AudioMode.sound,
}) async {
Log.debug('once($sound)', '$runtimeType');
ensureInitialized();
StreamSubscription<void>? handle = switch (mode) {
null => null,
(_) => acquire(mode).listen((_) {}),
};
try {
if (PlatformUtils.isWeb) {
final String url = sound.direct;
if (url.isNotEmpty) {
await (WebUtils.play(
'$url?${Pubspec.ref}',
)).listen((_) {}).asFuture();
}
} else {
await _jaPlayer?.setAudioSource(sound.source);
await _jaPlayer?.play();
}
} finally {
handle?.cancel();
}
}