play method
Play audio from the given path
Implementation
@override
Future<void> play({
required String path,
double volume = 1.0,
bool loop = false,
}) async {
try {
// Stop any currently playing audio
await stop();
// Create audio element
_audioElement = HTMLAudioElement()..src = path;
_audioElement!.volume = volume;
_audioElement!.loop = loop;
// Register this instance
_instances[_audioElement!] = this;
// Set up event listeners using static handlers
_audioElement!.ontimeupdate = (_handleTimeUpdate.toJS);
_audioElement!.ondurationchange = (_handleDurationChange.toJS);
_audioElement!.onended = (_handleEnded.toJS);
_audioElement!.onplay = (_handlePlay.toJS);
_audioElement!.onpause = (_handlePause.toJS);
// Start playback
try {
await _audioElement!.play().toDart;
} catch (error) {
throw Exception('Failed to play audio: $error');
}
} catch (e) {
throw Exception('Error playing audio: $e');
}
}