chore: stop audio message playing on 1) navigate to different route, 2) play other message, 3) open toolbar (#1982)
This commit is contained in:
parent
f839b79e81
commit
912efa7bb8
4 changed files with 15 additions and 2 deletions
|
|
@ -612,6 +612,7 @@ class ChatController extends State<ChatPageWithRoom>
|
|||
clearSelectedEvents();
|
||||
MatrixState.pAnyState.closeOverlay();
|
||||
showToolbarStream.close();
|
||||
stopAudioStream.close();
|
||||
hideTextController.dispose();
|
||||
_levelSubscription?.cancel();
|
||||
//Pangea#
|
||||
|
|
@ -1771,6 +1772,8 @@ class ChatController extends State<ChatPageWithRoom>
|
|||
final StreamController<String> showToolbarStream =
|
||||
StreamController.broadcast();
|
||||
|
||||
final StreamController<void> stopAudioStream = StreamController.broadcast();
|
||||
|
||||
void showToolbar(
|
||||
Event event, {
|
||||
PangeaMessageEvent? pangeaMessageEvent,
|
||||
|
|
@ -1827,6 +1830,8 @@ class ChatController extends State<ChatPageWithRoom>
|
|||
HapticFeedback.mediumImpact();
|
||||
}
|
||||
|
||||
stopAudioStream.add(null);
|
||||
|
||||
Future.delayed(
|
||||
Duration(milliseconds: buttonEventID == event.eventId ? 200 : 0), () {
|
||||
OverlayUtil.showOverlay(
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -171,6 +171,9 @@ class AudioPlayerState extends State<AudioPlayerWidget> {
|
|||
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<AudioPlayerWidget> {
|
|||
}
|
||||
|
||||
_onShowToolbar =
|
||||
widget.chatController.showToolbarStream.stream.listen((eventID) {
|
||||
widget.chatController.stopAudioStream.stream.listen((eventID) {
|
||||
audioPlayer?.pause();
|
||||
audioPlayer?.seek(Duration.zero);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue