chore: pause playing videos when user leaves chat page (#2708)
This commit is contained in:
parent
b724342955
commit
3eb8fcbd4a
5 changed files with 41 additions and 12 deletions
|
|
@ -569,8 +569,8 @@ class ChatController extends State<ChatPageWithRoom>
|
|||
if (state == AppLifecycleState.paused) {
|
||||
clearSelectedEvents();
|
||||
}
|
||||
if (state == AppLifecycleState.hidden && !stopAudioStream.isClosed) {
|
||||
stopAudioStream.add(null);
|
||||
if (state == AppLifecycleState.hidden && !stopMediaStream.isClosed) {
|
||||
stopMediaStream.add(null);
|
||||
}
|
||||
// Pangea#
|
||||
if (state != AppLifecycleState.resumed) return;
|
||||
|
|
@ -662,7 +662,7 @@ class ChatController extends State<ChatPageWithRoom>
|
|||
choreographer.dispose();
|
||||
MatrixState.pAnyState.closeAllOverlays(force: true);
|
||||
showToolbarStream.close();
|
||||
stopAudioStream.close();
|
||||
stopMediaStream.close();
|
||||
hideTextController.dispose();
|
||||
_levelSubscription?.cancel();
|
||||
_analyticsSubscription?.cancel();
|
||||
|
|
@ -680,7 +680,7 @@ class ChatController extends State<ChatPageWithRoom>
|
|||
}
|
||||
|
||||
void _onRouteChanged() {
|
||||
stopAudioStream.add(null);
|
||||
stopMediaStream.add(null);
|
||||
MatrixState.pAnyState.closeAllOverlays();
|
||||
}
|
||||
|
||||
|
|
@ -1007,7 +1007,7 @@ class ChatController extends State<ChatPageWithRoom>
|
|||
|
||||
void voiceMessageAction() async {
|
||||
// #Pangea
|
||||
stopAudioStream.add(null);
|
||||
stopMediaStream.add(null);
|
||||
// Pangea#
|
||||
final scaffoldMessenger = ScaffoldMessenger.of(context);
|
||||
if (PlatformInfos.isAndroid) {
|
||||
|
|
@ -1850,7 +1850,7 @@ class ChatController extends State<ChatPageWithRoom>
|
|||
final StreamController<String> showToolbarStream =
|
||||
StreamController.broadcast();
|
||||
|
||||
final StreamController<void> stopAudioStream = StreamController.broadcast();
|
||||
final StreamController<void> stopMediaStream = StreamController.broadcast();
|
||||
|
||||
void showToolbar(
|
||||
Event event, {
|
||||
|
|
@ -1910,7 +1910,7 @@ class ChatController extends State<ChatPageWithRoom>
|
|||
HapticFeedback.mediumImpact();
|
||||
}
|
||||
|
||||
stopAudioStream.add(null);
|
||||
stopMediaStream.add(null);
|
||||
|
||||
Future.delayed(
|
||||
Duration(milliseconds: buttonEventID == event.eventId ? 200 : 0), () {
|
||||
|
|
|
|||
|
|
@ -173,8 +173,8 @@ class AudioPlayerState extends State<AudioPlayerWidget> {
|
|||
// #Pangea
|
||||
// If there's another audio playing, stop it. Wait for this to come through
|
||||
// the stream so that the listener doesn't stop the audio that just started
|
||||
final future = widget.chatController.stopAudioStream.stream.first;
|
||||
widget.chatController.stopAudioStream.add(null);
|
||||
final future = widget.chatController.stopMediaStream.stream.first;
|
||||
widget.chatController.stopMediaStream.add(null);
|
||||
await future;
|
||||
|
||||
// if (AudioPlayerWidget.currentId != widget.event.eventId) {
|
||||
|
|
@ -366,7 +366,7 @@ class AudioPlayerState extends State<AudioPlayerWidget> {
|
|||
: _downloadAction();
|
||||
}
|
||||
|
||||
_onShowToolbar = widget.chatController.stopAudioStream.stream.listen((_) {
|
||||
_onShowToolbar = widget.chatController.stopMediaStream.stream.listen((_) {
|
||||
audioPlayer?.pause();
|
||||
audioPlayer?.seek(Duration.zero);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -245,7 +245,14 @@ class MessageContent extends StatelessWidget {
|
|||
linkColor: linkColor,
|
||||
);
|
||||
case MessageTypes.Video:
|
||||
return EventVideoPlayer(event, textColor: textColor);
|
||||
// #Pangea
|
||||
// return EventVideoPlayer(event, textColor: textColor);
|
||||
return EventVideoPlayer(
|
||||
event,
|
||||
textColor: textColor,
|
||||
chatController: controller,
|
||||
);
|
||||
// Pangea#
|
||||
case MessageTypes.File:
|
||||
return MessageDownloadContent(
|
||||
event,
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
|
@ -12,6 +13,7 @@ import 'package:universal_html/html.dart' as html;
|
|||
import 'package:video_player/video_player.dart';
|
||||
|
||||
import 'package:fluffychat/config/app_config.dart';
|
||||
import 'package:fluffychat/pages/chat/chat.dart';
|
||||
import 'package:fluffychat/pages/chat/events/image_bubble.dart';
|
||||
import 'package:fluffychat/utils/file_description.dart';
|
||||
import 'package:fluffychat/utils/localized_exception_extension.dart';
|
||||
|
|
@ -25,10 +27,16 @@ class EventVideoPlayer extends StatefulWidget {
|
|||
final Event event;
|
||||
final Color? textColor;
|
||||
final Color? linkColor;
|
||||
// #Pangea
|
||||
final ChatController? chatController;
|
||||
// Pangea#
|
||||
const EventVideoPlayer(
|
||||
this.event, {
|
||||
this.textColor,
|
||||
this.linkColor,
|
||||
// #Pangea
|
||||
this.chatController,
|
||||
// Pangea#
|
||||
super.key,
|
||||
});
|
||||
|
||||
|
|
@ -42,6 +50,17 @@ class EventVideoPlayerState extends State<EventVideoPlayer> {
|
|||
String? _networkUri;
|
||||
File? _tmpFile;
|
||||
|
||||
// #Pangea
|
||||
StreamSubscription? _stopVideoSubscription;
|
||||
|
||||
@override
|
||||
initState() {
|
||||
_stopVideoSubscription = widget.chatController?.stopMediaStream.stream
|
||||
.listen((_) => _chewieManager?.pause());
|
||||
super.initState();
|
||||
}
|
||||
// Pangea#
|
||||
|
||||
void _downloadAction() async {
|
||||
if (PlatformInfos.isDesktop) {
|
||||
widget.event.saveFile(context);
|
||||
|
|
@ -99,6 +118,9 @@ class EventVideoPlayerState extends State<EventVideoPlayer> {
|
|||
@override
|
||||
void dispose() {
|
||||
_chewieManager?.dispose();
|
||||
// #Pangea
|
||||
_stopVideoSubscription?.cancel();
|
||||
// Pangea#
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -166,7 +166,7 @@ class TtsController {
|
|||
String? targetID,
|
||||
BuildContext? context,
|
||||
}) async {
|
||||
chatController?.stopAudioStream.add(null);
|
||||
chatController?.stopMediaStream.add(null);
|
||||
await _setSpeakingLanguage(langCode);
|
||||
|
||||
final enableTTS = MatrixState
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue