playSound method
Plays a sound from the assets. This method is intended only for short/small audiofiles. Consider using playBackgroundSound otherwise.
Implementation
playSound(String assetPath, {double volume = 1}) async {
try {
final player = AudioPlayer();
player.setAsset(assetPath);
player.setVolume(volume);
player.play();
player.playerStateStream.listen((event) {
if (event.processingState == ProcessingState.completed) {
player.dispose();
}
});
} catch (e) {
log('[AUDIO] $e', error: e);
}
}