From 912efa7bb8041d63d5c5efb8fe31258091254daf Mon Sep 17 00:00:00 2001 From: ggurdin <46800240+ggurdin@users.noreply.github.com> Date: Thu, 27 Feb 2025 16:27:29 -0500 Subject: [PATCH] chore: stop audio message playing on 1) navigate to different route, 2) play other message, 3) open toolbar (#1982) --- lib/pages/chat/chat.dart | 5 +++++ lib/pages/chat/chat_view.dart | 2 ++ lib/pages/chat/events/audio_player.dart | 5 ++++- .../activity_plan_page_launch_icon_button.dart | 5 ++++- 4 files changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/pages/chat/chat.dart b/lib/pages/chat/chat.dart index 03d2758f4..79abee28d 100644 --- a/lib/pages/chat/chat.dart +++ b/lib/pages/chat/chat.dart @@ -612,6 +612,7 @@ class ChatController extends State clearSelectedEvents(); MatrixState.pAnyState.closeOverlay(); showToolbarStream.close(); + stopAudioStream.close(); hideTextController.dispose(); _levelSubscription?.cancel(); //Pangea# @@ -1771,6 +1772,8 @@ class ChatController extends State final StreamController showToolbarStream = StreamController.broadcast(); + final StreamController stopAudioStream = StreamController.broadcast(); + void showToolbar( Event event, { PangeaMessageEvent? pangeaMessageEvent, @@ -1827,6 +1830,8 @@ class ChatController extends State HapticFeedback.mediumImpact(); } + stopAudioStream.add(null); + Future.delayed( Duration(milliseconds: buttonEventID == event.eventId ? 200 : 0), () { OverlayUtil.showOverlay( diff --git a/lib/pages/chat/chat_view.dart b/lib/pages/chat/chat_view.dart index 1af946cae..56e60ac4e 100644 --- a/lib/pages/chat/chat_view.dart +++ b/lib/pages/chat/chat_view.dart @@ -131,6 +131,7 @@ class ChatView extends StatelessWidget { icon: const Icon(Icons.search_outlined), tooltip: L10n.of(context).search, onPressed: () { + controller.stopAudioStream.add(null); context.go('/rooms/${controller.room.id}/search'); }, ), @@ -139,6 +140,7 @@ class ChatView extends StatelessWidget { icon: const Icon(Icons.settings_outlined), tooltip: L10n.of(context).chatDetails, onPressed: () { + controller.stopAudioStream.add(null); if (GoRouterState.of(context).uri.path.endsWith('/details')) { context.go('/rooms/${controller.room.id}'); } else { diff --git a/lib/pages/chat/events/audio_player.dart b/lib/pages/chat/events/audio_player.dart index 6bf11af6e..260b49d49 100644 --- a/lib/pages/chat/events/audio_player.dart +++ b/lib/pages/chat/events/audio_player.dart @@ -171,6 +171,9 @@ class AudioPlayerState extends State { void _playAction() async { final audioPlayer = this.audioPlayer ??= AudioPlayer(); // #Pangea + // if there's another audio playing, stop it + widget.chatController.stopAudioStream.add(null); + // if (AudioPlayerWidget.currentId != widget.event.eventId) { if (AudioPlayerWidget.currentId != widget.event?.eventId) { // Pangea# @@ -361,7 +364,7 @@ class AudioPlayerState extends State { } _onShowToolbar = - widget.chatController.showToolbarStream.stream.listen((eventID) { + widget.chatController.stopAudioStream.stream.listen((eventID) { audioPlayer?.pause(); audioPlayer?.seek(Duration.zero); }); diff --git a/lib/pangea/activity_planner/activity_plan_page_launch_icon_button.dart b/lib/pangea/activity_planner/activity_plan_page_launch_icon_button.dart index f4c6855c2..9102f4e41 100644 --- a/lib/pangea/activity_planner/activity_plan_page_launch_icon_button.dart +++ b/lib/pangea/activity_planner/activity_plan_page_launch_icon_button.dart @@ -22,7 +22,10 @@ class ActivityPlanPageLaunchIconButton extends StatelessWidget { return IconButton( icon: const Icon(Icons.event_note_outlined), tooltip: L10n.of(context).activityPlannerTitle, - onPressed: () => context.go('/rooms/${controller.room.id}/planner'), + onPressed: () { + controller.stopAudioStream.add(null); + context.go('/rooms/${controller.room.id}/planner'); + }, ); } }