Fix voice messages

This commit is contained in:
Christian Pauly 2020-03-15 12:00:25 +01:00
parent 4342f0a8b6
commit 8ce271a234

View File

@ -37,6 +37,8 @@ class _AudioPlayerState extends State<AudioPlayer> {
double currentPosition = 0; double currentPosition = 0;
double maxPosition = 0; double maxPosition = 0;
static String currentMxc;
@override @override
void dispose() { void dispose() {
if (flutterSound.audioState == t_AUDIO_STATE.IS_PLAYING) { if (flutterSound.audioState == t_AUDIO_STATE.IS_PLAYING) {
@ -61,6 +63,14 @@ class _AudioPlayerState extends State<AudioPlayer> {
} }
_playAction() async { _playAction() async {
if (currentMxc != widget.content.mxc) {
if (currentMxc != null) {
if (flutterSound.audioState != t_AUDIO_STATE.IS_STOPPED) {
await flutterSound.stopPlayer();
}
currentMxc = widget.content.mxc;
}
}
switch (flutterSound.audioState) { switch (flutterSound.audioState) {
case t_AUDIO_STATE.IS_PLAYING: case t_AUDIO_STATE.IS_PLAYING:
await flutterSound.pausePlayer(); await flutterSound.pausePlayer();
@ -76,7 +86,13 @@ class _AudioPlayerState extends State<AudioPlayer> {
codec: t_CODEC.CODEC_AAC, codec: t_CODEC.CODEC_AAC,
); );
soundSubscription ??= flutterSound.onPlayerStateChanged.listen((e) { soundSubscription ??= flutterSound.onPlayerStateChanged.listen((e) {
if (e != null) { if (currentMxc != widget.content.mxc) {
soundSubscription?.cancel()?.then((f) => soundSubscription = null);
this.setState(() {
currentPosition = 0;
statusText = "00:00";
});
} else if (e != null) {
DateTime date = DateTime date =
DateTime.fromMillisecondsSinceEpoch(e.currentPosition.toInt()); DateTime.fromMillisecondsSinceEpoch(e.currentPosition.toInt());
String txt = DateFormat('mm:ss', 'en_US').format(date); String txt = DateFormat('mm:ss', 'en_US').format(date);