mirror of
https://gitlab.com/famedly/fluffychat.git
synced 2025-01-11 18:22:49 +01:00
chore: Follow up fix audioplayer on android
This commit is contained in:
parent
a48e42dfcf
commit
a602dc08d5
@ -1,10 +1,13 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
import 'dart:io';
|
||||||
|
|
||||||
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
import 'package:flutter_gen/gen_l10n/l10n.dart';
|
||||||
import 'package:just_audio/just_audio.dart';
|
import 'package:just_audio/just_audio.dart';
|
||||||
import 'package:matrix/matrix.dart';
|
import 'package:matrix/matrix.dart';
|
||||||
|
import 'package:path_provider/path_provider.dart';
|
||||||
|
|
||||||
import 'package:fluffychat/config/app_config.dart';
|
import 'package:fluffychat/config/app_config.dart';
|
||||||
import 'package:fluffychat/utils/localized_exception_extension.dart';
|
import 'package:fluffychat/utils/localized_exception_extension.dart';
|
||||||
@ -40,7 +43,8 @@ class AudioPlayerState extends State<AudioPlayerWidget> {
|
|||||||
int currentPosition = 0;
|
int currentPosition = 0;
|
||||||
double maxPosition = 0;
|
double maxPosition = 0;
|
||||||
|
|
||||||
MatrixFile? audioFile;
|
MatrixFile? matrixFile;
|
||||||
|
File? audioFile;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void dispose() {
|
void dispose() {
|
||||||
@ -60,8 +64,19 @@ class AudioPlayerState extends State<AudioPlayerWidget> {
|
|||||||
setState(() => status = AudioPlayerStatus.downloading);
|
setState(() => status = AudioPlayerStatus.downloading);
|
||||||
try {
|
try {
|
||||||
final matrixFile = await widget.event.downloadAndDecryptAttachment();
|
final matrixFile = await widget.event.downloadAndDecryptAttachment();
|
||||||
|
File? file;
|
||||||
|
|
||||||
|
if (!kIsWeb) {
|
||||||
|
final tempDir = await getTemporaryDirectory();
|
||||||
|
final fileName = Uri.encodeComponent(
|
||||||
|
widget.event.attachmentOrThumbnailMxcUrl()!.pathSegments.last);
|
||||||
|
file = File('${tempDir.path}/${fileName}_${matrixFile.name}');
|
||||||
|
await file.writeAsBytes(matrixFile.bytes);
|
||||||
|
}
|
||||||
|
|
||||||
setState(() {
|
setState(() {
|
||||||
audioFile = matrixFile;
|
audioFile = file;
|
||||||
|
this.matrixFile = matrixFile;
|
||||||
status = AudioPlayerStatus.downloaded;
|
status = AudioPlayerStatus.downloaded;
|
||||||
});
|
});
|
||||||
_playAction();
|
_playAction();
|
||||||
@ -110,7 +125,12 @@ class AudioPlayerState extends State<AudioPlayerWidget> {
|
|||||||
});
|
});
|
||||||
onPlayerStateChanged ??=
|
onPlayerStateChanged ??=
|
||||||
audioPlayer.playingStream.listen((_) => setState(() {}));
|
audioPlayer.playingStream.listen((_) => setState(() {}));
|
||||||
audioPlayer.setAudioSource(MatrixFileAudioSource(audioFile!));
|
final audioFile = this.audioFile;
|
||||||
|
if (audioFile != null) {
|
||||||
|
audioPlayer.setFilePath(audioFile.path);
|
||||||
|
} else {
|
||||||
|
await audioPlayer.setAudioSource(MatrixFileAudioSource(matrixFile!));
|
||||||
|
}
|
||||||
audioPlayer.play().catchError((e, s) {
|
audioPlayer.play().catchError((e, s) {
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
SnackBar(
|
SnackBar(
|
||||||
|
Loading…
Reference in New Issue
Block a user