From ca203608fa2de4882ad90f4b99b8fd33493c754c Mon Sep 17 00:00:00 2001 From: Krille Fear Date: Fri, 30 Dec 2022 10:51:26 +0100 Subject: [PATCH] feat: Add audio message support to linux --- lib/pages/chat/events/audio_player.dart | 8 ++++--- lib/pages/chat/events/message_content.dart | 4 +++- pubspec.lock | 27 +++++++++++++++++++--- pubspec.yaml | 3 ++- 4 files changed, 34 insertions(+), 8 deletions(-) diff --git a/lib/pages/chat/events/audio_player.dart b/lib/pages/chat/events/audio_player.dart index 9ba75ef8..bf9f60b7 100644 --- a/lib/pages/chat/events/audio_player.dart +++ b/lib/pages/chat/events/audio_player.dart @@ -102,6 +102,7 @@ class AudioPlayerState extends State { } onAudioPositionChanged ??= audioPlayer.positionStream.listen((state) { + if (maxPosition <= 0) return; setState(() { statusText = '${state.inMinutes.toString().padLeft(2, '0')}:${(state.inSeconds % 60).toString().padLeft(2, '0')}'; @@ -110,9 +111,10 @@ class AudioPlayerState extends State { .round(); }); }); - onDurationChanged ??= audioPlayer.durationStream.listen((max) => max == null - ? null - : setState(() => maxPosition = max.inMilliseconds.toDouble())); + onDurationChanged ??= audioPlayer.durationStream.listen((max) { + if (max == null || max == Duration.zero) return; + setState(() => maxPosition = max.inMilliseconds.toDouble()); + }); onPlayerStateChanged ??= audioPlayer.playingStream.listen((_) => setState(() {})); audioPlayer.setFilePath(audioFile!.path); diff --git a/lib/pages/chat/events/message_content.dart b/lib/pages/chat/events/message_content.dart index 71e1e7e2..cc56f6ba 100644 --- a/lib/pages/chat/events/message_content.dart +++ b/lib/pages/chat/events/message_content.dart @@ -112,7 +112,9 @@ class MessageContent extends StatelessWidget { case CuteEventContent.eventType: return CuteContent(event); case MessageTypes.Audio: - if (PlatformInfos.isMobile || PlatformInfos.isMacOS) { + if (PlatformInfos.isMobile || + PlatformInfos.isMacOS || + PlatformInfos.isLinux) { return AudioPlayerWidget( event, color: textColor, diff --git a/pubspec.lock b/pubspec.lock index 53649498..e3750f30 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -77,7 +77,7 @@ packages: name: audio_session url: "https://pub.dartlang.org" source: hosted - version: "0.1.6+1" + version: "0.1.13" badges: dependency: "direct main" description: @@ -358,6 +358,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "0.1.2" + eventify: + dependency: transitive + description: + name: eventify + url: "https://pub.dartlang.org" + source: hosted + version: "1.0.1" fake_async: dependency: transitive description: @@ -865,14 +872,21 @@ packages: name: just_audio url: "https://pub.dartlang.org" source: hosted - version: "0.9.20" + version: "0.9.30" + just_audio_mpv: + dependency: "direct main" + description: + name: just_audio_mpv + url: "https://pub.dartlang.org" + source: hosted + version: "0.1.6" just_audio_platform_interface: dependency: transitive description: name: just_audio_platform_interface url: "https://pub.dartlang.org" source: hosted - version: "4.1.0" + version: "4.2.0" just_audio_web: dependency: transitive description: @@ -994,6 +1008,13 @@ packages: url: "https://pub.dartlang.org" source: hosted version: "1.0.2" + mpv_dart: + dependency: transitive + description: + name: mpv_dart + url: "https://pub.dartlang.org" + source: hosted + version: "0.0.1" msix: dependency: "direct dev" description: diff --git a/pubspec.yaml b/pubspec.yaml index 5528e99b..44f6a305 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -56,7 +56,8 @@ dependencies: image: ^3.1.1 image_picker: ^0.8.4+8 intl: any - just_audio: ^0.9.20 + just_audio: ^0.9.30 + just_audio_mpv: ^0.1.6 keyboard_shortcuts: ^0.1.4 latlong2: ^0.8.1 matrix: ^0.15.11