From f3798f3ee8f770bd513e9bebf632a21aa8fb4501 Mon Sep 17 00:00:00 2001 From: Krille Date: Mon, 23 Oct 2023 16:08:57 +0200 Subject: [PATCH] refactor: Preload notification sound on web --- lib/widgets/local_notifications_extension.dart | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/widgets/local_notifications_extension.dart b/lib/widgets/local_notifications_extension.dart index e5762050..44754030 100644 --- a/lib/widgets/local_notifications_extension.dart +++ b/lib/widgets/local_notifications_extension.dart @@ -17,6 +17,10 @@ import 'package:fluffychat/utils/platform_infos.dart'; import 'package:fluffychat/widgets/matrix.dart'; extension LocalNotificationsExtension on MatrixState { + static final html.AudioElement _audioPlayer = html.AudioElement() + ..src = 'assets/assets/sounds/notification.ogg' + ..load(); + void showLocalNotification(EventUpdate eventUpdate) async { final roomId = eventUpdate.roomID; if (activeRoomId == roomId) { @@ -56,10 +60,7 @@ extension LocalNotificationsExtension on MatrixState { method: ThumbnailMethod.crop, ); if (kIsWeb) { - html.AudioElement() - ..src = 'assets/assets/sounds/notification.ogg' - ..autoplay = true - ..load(); + _audioPlayer.play(); html.Notification( title, body: body,