From ad877bfd43b7b924034645b59d6d3e5f5dde3f93 Mon Sep 17 00:00:00 2001 From: ggurdin Date: Wed, 2 Jul 2025 13:03:28 -0400 Subject: [PATCH] chore: fix autoplay bot messages on android --- lib/pages/chat/chat.dart | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/lib/pages/chat/chat.dart b/lib/pages/chat/chat.dart index bc820b81a..1b6ad5331 100644 --- a/lib/pages/chat/chat.dart +++ b/lib/pages/chat/chat.dart @@ -16,6 +16,7 @@ import 'package:go_router/go_router.dart'; import 'package:image_picker/image_picker.dart'; import 'package:just_audio/just_audio.dart'; import 'package:matrix/matrix.dart'; +import 'package:path_provider/path_provider.dart'; import 'package:scroll_to_index/scroll_to_index.dart'; import 'package:sentry_flutter/sentry_flutter.dart'; import 'package:shared_preferences/shared_preferences.dart'; @@ -506,12 +507,21 @@ class ChatController extends State ); if (audioFile == null) return; - matrix.audioPlayer!.setAudioSource( - BytesAudioSource( - audioFile.bytes, - audioFile.mimeType, - ), - ); + if (!kIsWeb) { + final tempDir = await getTemporaryDirectory(); + + File? file; + file = File('${tempDir.path}/${audioFile.name}'); + await file.writeAsBytes(audioFile.bytes); + matrix.audioPlayer!.setFilePath(file.path); + } else { + matrix.audioPlayer!.setAudioSource( + BytesAudioSource( + audioFile.bytes, + audioFile.mimeType, + ), + ); + } matrix.audioPlayer!.play(); });