chore: stop audio when route changes and before playing token audio (#2054)
This commit is contained in:
parent
fe2b79ca1f
commit
888cc7e13d
5 changed files with 18 additions and 5 deletions
|
|
@ -129,6 +129,7 @@ class ChatController extends State<ChatPageWithRoom>
|
|||
final PangeaController pangeaController = MatrixState.pangeaController;
|
||||
late Choreographer choreographer = Choreographer(pangeaController, this);
|
||||
StreamSubscription? _levelSubscription;
|
||||
late GoRouter _router;
|
||||
// Pangea#
|
||||
Room get room => sendingClient.getRoomById(roomId) ?? widget.room;
|
||||
|
||||
|
|
@ -619,11 +620,21 @@ class ChatController extends State<ChatPageWithRoom>
|
|||
stopAudioStream.close();
|
||||
hideTextController.dispose();
|
||||
_levelSubscription?.cancel();
|
||||
_router.routeInformationProvider.removeListener(_onRouteChanged);
|
||||
//Pangea#
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
// #Pangea
|
||||
@override
|
||||
void didChangeDependencies() {
|
||||
super.didChangeDependencies();
|
||||
_router = GoRouter.of(context);
|
||||
_router.routeInformationProvider.addListener(_onRouteChanged);
|
||||
}
|
||||
|
||||
void _onRouteChanged() => stopAudioStream.add(null);
|
||||
|
||||
// TextEditingController sendController = TextEditingController();
|
||||
PangeaTextController get sendController => choreographer.textController;
|
||||
|
||||
|
|
|
|||
|
|
@ -131,7 +131,6 @@ 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');
|
||||
},
|
||||
),
|
||||
|
|
@ -140,7 +139,6 @@ 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 {
|
||||
|
|
|
|||
|
|
@ -27,7 +27,6 @@ class ActivityPlanPageLaunchIconButton extends StatelessWidget {
|
|||
icon: const Icon(Icons.event_note_outlined),
|
||||
tooltip: L10n.of(context).activityPlannerTitle,
|
||||
onPressed: () {
|
||||
controller.stopAudioStream.add(null);
|
||||
context.go('/rooms/${controller.room.id}/planner');
|
||||
},
|
||||
);
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ class Choreographer {
|
|||
late IgcController igc;
|
||||
late AlternativeTranslator altTranslator;
|
||||
late ErrorService errorService;
|
||||
final tts = TtsController();
|
||||
late TtsController tts;
|
||||
|
||||
bool isFetching = false;
|
||||
int _timesClicked = 0;
|
||||
|
|
@ -62,6 +62,7 @@ class Choreographer {
|
|||
_initialize();
|
||||
}
|
||||
_initialize() {
|
||||
tts = TtsController(chatController: chatController);
|
||||
_textController = PangeaTextController(choreographer: this);
|
||||
InputPasteListener(
|
||||
_textController,
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import 'package:flutter_tts/flutter_tts.dart' as flutter_tts;
|
|||
import 'package:matrix/matrix_api_lite/utils/logs.dart';
|
||||
import 'package:text_to_speech/text_to_speech.dart';
|
||||
|
||||
import 'package:fluffychat/pages/chat/chat.dart';
|
||||
import 'package:fluffychat/pangea/common/utils/error_handler.dart';
|
||||
import 'package:fluffychat/pangea/instructions/instructions_enum.dart';
|
||||
import 'package:fluffychat/pangea/instructions/instructions_show_popup.dart';
|
||||
|
|
@ -19,6 +20,8 @@ import 'package:fluffychat/utils/platform_infos.dart';
|
|||
import 'package:fluffychat/widgets/matrix.dart';
|
||||
|
||||
class TtsController {
|
||||
final ChatController? chatController;
|
||||
|
||||
String? get l2LangCode =>
|
||||
MatrixState.pangeaController.languageController.userL2?.langCode;
|
||||
|
||||
|
|
@ -33,7 +36,7 @@ class TtsController {
|
|||
UserController get userController =>
|
||||
MatrixState.pangeaController.userController;
|
||||
|
||||
TtsController() {
|
||||
TtsController({this.chatController}) {
|
||||
setupTTS();
|
||||
_languageSubscription =
|
||||
userController.stateStream.listen((_) => setupTTS());
|
||||
|
|
@ -182,6 +185,7 @@ class TtsController {
|
|||
// Target ID for where to show warning popup
|
||||
String? targetID,
|
||||
}) async {
|
||||
chatController?.stopAudioStream.add(null);
|
||||
await _setLanguage();
|
||||
final enableTTS = MatrixState
|
||||
.pangeaController.userController.profile.toolSettings.enableTTS;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue