some fixes
This commit is contained in:
parent
102f113cb8
commit
d0f889d314
3 changed files with 33 additions and 32 deletions
|
|
@ -236,30 +236,37 @@ class AudioPlayerState extends State<AudioPlayerWidget> {
|
|||
|
||||
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
|
||||
void initState() {
|
||||
super.initState();
|
||||
waveform = _getWaveform();
|
||||
// #Pangea
|
||||
if (widget.matrixFile != null) {
|
||||
if (!kIsWeb) {
|
||||
getTemporaryDirectory().then((val) {
|
||||
final tempDir = val;
|
||||
final file = File('${tempDir.path}/${widget.matrixFile!.name}');
|
||||
file.writeAsBytesSync(widget.matrixFile!.bytes);
|
||||
audioFile = file;
|
||||
});
|
||||
}
|
||||
status = AudioPlayerStatus.downloaded;
|
||||
setState(() {});
|
||||
}
|
||||
|
||||
if (widget.autoplay) {
|
||||
_downloadMatrixFile().then((_) {
|
||||
setState(() => status = AudioPlayerStatus.downloaded);
|
||||
if (widget.autoplay) {
|
||||
status == AudioPlayerStatus.downloaded
|
||||
? _playAction()
|
||||
: _downloadAction();
|
||||
}
|
||||
});
|
||||
} else if (widget.autoplay) {
|
||||
status == AudioPlayerStatus.downloaded
|
||||
? _playAction()
|
||||
: _downloadAction();
|
||||
// Pangea#
|
||||
}
|
||||
// Pangea#
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
|
|||
|
|
@ -83,8 +83,16 @@ class PangeaMessageEvent {
|
|||
return true;
|
||||
}
|
||||
|
||||
Future<PangeaAudioFile> getMatrixAudioFile(String langCode) async {
|
||||
final String text = representationByLanguage(langCode)?.text ?? body;
|
||||
Future<PangeaAudioFile> getMatrixAudioFile(
|
||||
String langCode,
|
||||
BuildContext context,
|
||||
) async {
|
||||
final String text = (await representationByLanguageGlobal(
|
||||
context: context,
|
||||
langCode: langCode,
|
||||
))
|
||||
?.text ??
|
||||
body;
|
||||
final TextToSpeechRequest params = TextToSpeechRequest(
|
||||
text: text,
|
||||
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/pangea/models/pangea_message_event.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);
|
||||
} catch (e, _) {
|
||||
debugPrint(StackTrace.current.toString());
|
||||
|
|
@ -78,20 +78,6 @@ class MessageAudioCardState extends State<MessageAudioCard> {
|
|||
|
||||
@override
|
||||
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(
|
||||
padding: const EdgeInsets.all(8),
|
||||
child: _isLoading
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue