playGroup method
Play a Random Sound from a Group
- Skips if the group is unknown or throttled by
_cooldown. - Chooses a random path from the registered list and plays it (pooled).
Implementation
Future<void> playGroup(String name) async {
final now = DateTime.now();
final lastPlayed = _lastPlayedTimestamps[name];
// Throttle per group to avoid audio spam
if (lastPlayed != null && now.difference(lastPlayed) < _cooldown) return;
final sounds = _groups[name];
if (sounds == null || sounds.isEmpty) return;
final randomPath = sounds[_random.nextInt(sounds.length)];
await play(randomPath);
_lastPlayedTimestamps[name] = now;
}