From 0f7b1755bab6036342f3309919d9f1b0acb44df7 Mon Sep 17 00:00:00 2001 From: otsmr Date: Tue, 29 Apr 2025 14:11:55 +0200 Subject: [PATCH] videos should work #25 --- lib/src/providers/api/media_received.dart | 4 +-- lib/src/providers/api/media_send.dart | 2 ++ lib/src/views/camera/camera_preview_view.dart | 3 +++ .../views/camera/share_image_editor_view.dart | 17 ++++++++---- lib/src/views/chats/media_viewer_view.dart | 26 ++++++++++--------- 5 files changed, 33 insertions(+), 19 deletions(-) diff --git a/lib/src/providers/api/media_received.dart b/lib/src/providers/api/media_received.dart index 13ac873..05a16d9 100644 --- a/lib/src/providers/api/media_received.dart +++ b/lib/src/providers/api/media_received.dart @@ -178,7 +178,7 @@ Future handleDownloadData(DownloadData data) async { if (content.isVideo) { final splited = extractUint8Lists(imageBytes); imageBytes = splited[0]; - await writeMediaFile(media.messageId, "video", splited[1]); + await writeMediaFile(media.messageId, "mp4", splited[1]); } await writeMediaFile(media.messageId, "image", imageBytes); @@ -212,7 +212,7 @@ Future getImageBytes(int mediaId) async { Future getVideoPath(int mediaId) async { String basePath = await getMediaFilePath(mediaId, "received"); - return File("$basePath.video"); + return File("$basePath.mp4"); } /// --- helper functions --- diff --git a/lib/src/providers/api/media_send.dart b/lib/src/providers/api/media_send.dart index 0963b79..f3f30f3 100644 --- a/lib/src/providers/api/media_send.dart +++ b/lib/src/providers/api/media_send.dart @@ -170,6 +170,7 @@ Future handleCompressionState(MediaUpload media) async { try { Uint8List imageBytesCompressed = await FlutterImageCompress.compressWithList( + format: CompressFormat.png, imageBytes, quality: 90, ); @@ -177,6 +178,7 @@ Future handleCompressionState(MediaUpload media) async { if (imageBytesCompressed.length >= 1 * 1000 * 1000) { // if the media file is over 1MB compress it with 60% imageBytesCompressed = await FlutterImageCompress.compressWithList( + format: CompressFormat.png, imageBytes, quality: 60, ); diff --git a/lib/src/views/camera/camera_preview_view.dart b/lib/src/views/camera/camera_preview_view.dart index 43285fc..e7e897d 100644 --- a/lib/src/views/camera/camera_preview_view.dart +++ b/lib/src/views/camera/camera_preview_view.dart @@ -414,6 +414,9 @@ class _CameraPreviewViewState extends State { onLongPressEnd: (a) { stopVideoRecording(); }, + onPanEnd: (a) { + stopVideoRecording(); + }, onPanUpdate: onPanUpdate, child: Stack( children: [ diff --git a/lib/src/views/camera/share_image_editor_view.dart b/lib/src/views/camera/share_image_editor_view.dart index b86c32c..33f2537 100644 --- a/lib/src/views/camera/share_image_editor_view.dart +++ b/lib/src/views/camera/share_image_editor_view.dart @@ -27,6 +27,8 @@ List layers = []; List undoLayers = []; List removedLayers = []; +const gMediaShowInfinite = 999999; + class ShareImageEditorView extends StatefulWidget { const ShareImageEditorView( {super.key, this.imageBytes, this.sendTo, this.videoFilePath}); @@ -40,7 +42,7 @@ class ShareImageEditorView extends StatefulWidget { class _ShareImageEditorView extends State { bool _isRealTwonly = false; bool videoWithAudio = true; - int maxShowTime = 999999; + int maxShowTime = gMediaShowInfinite; String? sendNextMediaToUserName; double tabDownPostion = 0; bool sendingOrLoadingImage = true; @@ -58,6 +60,7 @@ class _ShareImageEditorView extends State { if (widget.imageBytes != null) { loadImage(widget.imageBytes!); } else if (widget.videoFilePath != null) { + layers.add(FilterLayerData()); setState(() { sendingOrLoadingImage = false; }); @@ -161,7 +164,7 @@ class _ShareImageEditorView extends State { : maxShowTime.toString(), child: ActionButton( (widget.videoFilePath != null) - ? maxShowTime == 1 + ? maxShowTime == 999999 ? Icons.repeat_rounded : Icons.repeat_one_rounded : Icons.timer_outlined, @@ -169,14 +172,18 @@ class _ShareImageEditorView extends State { onPressed: () async { if (widget.videoFilePath != null) { setState(() { - maxShowTime = (maxShowTime + 1) % 2; + if (maxShowTime == gMediaShowInfinite) { + maxShowTime = 0; + } else { + maxShowTime = gMediaShowInfinite; + } }); return; } - if (maxShowTime == 999999) { + if (maxShowTime == gMediaShowInfinite) { maxShowTime = 4; } else if (maxShowTime >= 22) { - maxShowTime = 999999; + maxShowTime = gMediaShowInfinite; } else { maxShowTime = maxShowTime + 8; } diff --git a/lib/src/views/chats/media_viewer_view.dart b/lib/src/views/chats/media_viewer_view.dart index 37c5982..3ead83c 100644 --- a/lib/src/views/chats/media_viewer_view.dart +++ b/lib/src/views/chats/media_viewer_view.dart @@ -8,6 +8,7 @@ import 'package:logging/logging.dart'; import 'package:lottie/lottie.dart'; import 'package:no_screenshot/no_screenshot.dart'; import 'package:twonly/globals.dart'; +import 'package:twonly/src/views/camera/share_image_editor_view.dart'; import 'package:twonly/src/views/components/animate_icon.dart'; import 'package:twonly/src/views/components/media_view_sizing.dart'; import 'package:twonly/src/database/twonly_database.dart'; @@ -183,17 +184,17 @@ class _MediaViewerViewState extends State { final vidoePath = await getVideoPath(current.messageId); if (vidoePath != null) { videoController = VideoPlayerController.file(File(vidoePath.path)); - videoController?.setLooping(content.maxShowTime == 1); - if (content.maxShowTime == 0) { - videoController?.addListener(() { - if (videoController?.value.position == - videoController?.value.duration) { - nextMediaOrExit(); - } - }); - } + videoController?.setLooping(content.maxShowTime == gMediaShowInfinite); videoController?.initialize().then((_) { videoController!.play(); + if (content.maxShowTime != gMediaShowInfinite) { + videoController?.addListener(() { + if (videoController?.value.position == + videoController?.value.duration) { + nextMediaOrExit(); + } + }); + } setState(() {}); }).catchError((Object error) { Logger("media_viewer_view.dart").shout(error); @@ -219,11 +220,11 @@ class _MediaViewerViewState extends State { canBeSeenUntil = DateTime.now().add( Duration(seconds: content.maxShowTime), ); - maxShowTime = content.maxShowTime; startTimer(); } } setState(() { + maxShowTime = content.maxShowTime; isDownloading = false; }); } @@ -291,7 +292,7 @@ class _MediaViewerViewState extends State { mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center, children: [ - if (maxShowTime == 999999) + if (maxShowTime == gMediaShowInfinite) OutlinedButton( style: OutlinedButton.styleFrom( iconColor: imageSaved @@ -424,8 +425,9 @@ class _MediaViewerViewState extends State { duration: const Duration(milliseconds: 200), child: frame != null ? child - : SizedBox( + : Container( height: 60, + color: Colors.transparent, width: 60, child: CircularProgressIndicator( strokeWidth: 2,