some fixes

pull/1011/head
Gabby Gurdin 2 years ago
parent 102f113cb8
commit d0f889d314

@ -236,30 +236,37 @@ class AudioPlayerState extends State<AudioPlayerWidget> {
late final List<int> waveform; late final List<int> waveform;
// #Pangea
Future<void> _downloadMatrixFile() async {
if (kIsWeb) return;
final temp = await getTemporaryDirectory();
final tempDir = temp;
final file = File('${tempDir.path}/${widget.matrixFile!.name}');
await file.writeAsBytes(widget.matrixFile!.bytes);
audioFile = file;
}
// Pangea#
@override @override
void initState() { void initState() {
super.initState(); super.initState();
waveform = _getWaveform(); waveform = _getWaveform();
// #Pangea // #Pangea
if (widget.matrixFile != null) { if (widget.matrixFile != null) {
if (!kIsWeb) { _downloadMatrixFile().then((_) {
getTemporaryDirectory().then((val) { setState(() => status = AudioPlayerStatus.downloaded);
final tempDir = val; if (widget.autoplay) {
final file = File('${tempDir.path}/${widget.matrixFile!.name}'); status == AudioPlayerStatus.downloaded
file.writeAsBytesSync(widget.matrixFile!.bytes); ? _playAction()
audioFile = file; : _downloadAction();
}); }
} });
status = AudioPlayerStatus.downloaded; } else if (widget.autoplay) {
setState(() {});
}
if (widget.autoplay) {
status == AudioPlayerStatus.downloaded status == AudioPlayerStatus.downloaded
? _playAction() ? _playAction()
: _downloadAction(); : _downloadAction();
// Pangea#
} }
// Pangea#
} }
@override @override

@ -83,8 +83,16 @@ class PangeaMessageEvent {
return true; return true;
} }
Future<PangeaAudioFile> getMatrixAudioFile(String langCode) async { Future<PangeaAudioFile> getMatrixAudioFile(
final String text = representationByLanguage(langCode)?.text ?? body; String langCode,
BuildContext context,
) async {
final String text = (await representationByLanguageGlobal(
context: context,
langCode: langCode,
))
?.text ??
body;
final TextToSpeechRequest params = TextToSpeechRequest( final TextToSpeechRequest params = TextToSpeechRequest(
text: text, text: text,
langCode: langCode, langCode: langCode,

@ -1,4 +1,3 @@
import 'package:fluffychat/config/app_config.dart';
import 'package:fluffychat/pages/chat/events/audio_player.dart'; import 'package:fluffychat/pages/chat/events/audio_player.dart';
import 'package:fluffychat/pangea/models/pangea_message_event.dart'; import 'package:fluffychat/pangea/models/pangea_message_event.dart';
import 'package:fluffychat/pangea/utils/error_handler.dart'; import 'package:fluffychat/pangea/utils/error_handler.dart';
@ -46,7 +45,8 @@ class MessageAudioCardState extends State<MessageAudioCard> {
} }
} }
audioFile = await widget.messageEvent.getMatrixAudioFile(langCode); audioFile =
await widget.messageEvent.getMatrixAudioFile(langCode, context);
if (mounted) setState(() => _isLoading = false); if (mounted) setState(() => _isLoading = false);
} catch (e, _) { } catch (e, _) {
debugPrint(StackTrace.current.toString()); debugPrint(StackTrace.current.toString());
@ -78,20 +78,6 @@ class MessageAudioCardState extends State<MessageAudioCard> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final playButton = InkWell(
borderRadius: BorderRadius.circular(64),
onTap: fetchAudio,
child: Material(
color: AppConfig.primaryColor.withAlpha(64),
borderRadius: BorderRadius.circular(64),
child: const Icon(
// Change the icon based on some condition. If you have an audio player state, use it here.
Icons.play_arrow_outlined,
color: AppConfig.primaryColor,
),
),
);
return Padding( return Padding(
padding: const EdgeInsets.all(8), padding: const EdgeInsets.all(8),
child: _isLoading child: _isLoading

Loading…
Cancel
Save