videos should work #25

This commit is contained in:
otsmr 2025-04-29 14:11:55 +02:00
parent 6e4a1d0624
commit 0f7b1755ba
5 changed files with 33 additions and 19 deletions

View file

@ -178,7 +178,7 @@ Future<client.Response> 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<Uint8List?> getImageBytes(int mediaId) async {
Future<File?> getVideoPath(int mediaId) async {
String basePath = await getMediaFilePath(mediaId, "received");
return File("$basePath.video");
return File("$basePath.mp4");
}
/// --- helper functions ---

View file

@ -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,
);

View file

@ -414,6 +414,9 @@ class _CameraPreviewViewState extends State<CameraPreviewView> {
onLongPressEnd: (a) {
stopVideoRecording();
},
onPanEnd: (a) {
stopVideoRecording();
},
onPanUpdate: onPanUpdate,
child: Stack(
children: [

View file

@ -27,6 +27,8 @@ List<Layer> layers = [];
List<Layer> undoLayers = [];
List<Layer> 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<ShareImageEditorView> {
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<ShareImageEditorView> {
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<ShareImageEditorView> {
: 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<ShareImageEditorView> {
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;
}

View file

@ -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<MediaViewerView> {
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<MediaViewerView> {
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<MediaViewerView> {
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<MediaViewerView> {
duration: const Duration(milliseconds: 200),
child: frame != null
? child
: SizedBox(
: Container(
height: 60,
color: Colors.transparent,
width: 60,
child: CircularProgressIndicator(
strokeWidth: 2,