playAudioOnWeb function

Future<void> playAudioOnWeb(
  1. Uint8List audioBytes
)

Implementation

Future<void> playAudioOnWeb(Uint8List audioBytes) async {
  final blob = html.Blob([audioBytes]);
  final url = html.Url.createObjectUrlFromBlob(blob);
  final AudioPlayer audioPlayer = AudioPlayer(); // Initialize AudioPlayer here

  try {
    await audioPlayer.play(UrlSource(url));
  } catch (e) {
    print('Error playing audio on the web: $e');
  } finally {
    html.Url.revokeObjectUrl(url); // Clean up
  }
}