mirror of
https://github.com/twonlyapp/twonly-app.git
synced 2026-01-15 13:08:42 +00:00
videos should work #25
This commit is contained in:
parent
6e4a1d0624
commit
0f7b1755ba
5 changed files with 33 additions and 19 deletions
|
|
@ -178,7 +178,7 @@ Future<client.Response> handleDownloadData(DownloadData data) async {
|
||||||
if (content.isVideo) {
|
if (content.isVideo) {
|
||||||
final splited = extractUint8Lists(imageBytes);
|
final splited = extractUint8Lists(imageBytes);
|
||||||
imageBytes = splited[0];
|
imageBytes = splited[0];
|
||||||
await writeMediaFile(media.messageId, "video", splited[1]);
|
await writeMediaFile(media.messageId, "mp4", splited[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
await writeMediaFile(media.messageId, "image", imageBytes);
|
await writeMediaFile(media.messageId, "image", imageBytes);
|
||||||
|
|
@ -212,7 +212,7 @@ Future<Uint8List?> getImageBytes(int mediaId) async {
|
||||||
|
|
||||||
Future<File?> getVideoPath(int mediaId) async {
|
Future<File?> getVideoPath(int mediaId) async {
|
||||||
String basePath = await getMediaFilePath(mediaId, "received");
|
String basePath = await getMediaFilePath(mediaId, "received");
|
||||||
return File("$basePath.video");
|
return File("$basePath.mp4");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// --- helper functions ---
|
/// --- helper functions ---
|
||||||
|
|
|
||||||
|
|
@ -170,6 +170,7 @@ Future handleCompressionState(MediaUpload media) async {
|
||||||
try {
|
try {
|
||||||
Uint8List imageBytesCompressed =
|
Uint8List imageBytesCompressed =
|
||||||
await FlutterImageCompress.compressWithList(
|
await FlutterImageCompress.compressWithList(
|
||||||
|
format: CompressFormat.png,
|
||||||
imageBytes,
|
imageBytes,
|
||||||
quality: 90,
|
quality: 90,
|
||||||
);
|
);
|
||||||
|
|
@ -177,6 +178,7 @@ Future handleCompressionState(MediaUpload media) async {
|
||||||
if (imageBytesCompressed.length >= 1 * 1000 * 1000) {
|
if (imageBytesCompressed.length >= 1 * 1000 * 1000) {
|
||||||
// if the media file is over 1MB compress it with 60%
|
// if the media file is over 1MB compress it with 60%
|
||||||
imageBytesCompressed = await FlutterImageCompress.compressWithList(
|
imageBytesCompressed = await FlutterImageCompress.compressWithList(
|
||||||
|
format: CompressFormat.png,
|
||||||
imageBytes,
|
imageBytes,
|
||||||
quality: 60,
|
quality: 60,
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -414,6 +414,9 @@ class _CameraPreviewViewState extends State<CameraPreviewView> {
|
||||||
onLongPressEnd: (a) {
|
onLongPressEnd: (a) {
|
||||||
stopVideoRecording();
|
stopVideoRecording();
|
||||||
},
|
},
|
||||||
|
onPanEnd: (a) {
|
||||||
|
stopVideoRecording();
|
||||||
|
},
|
||||||
onPanUpdate: onPanUpdate,
|
onPanUpdate: onPanUpdate,
|
||||||
child: Stack(
|
child: Stack(
|
||||||
children: [
|
children: [
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,8 @@ List<Layer> layers = [];
|
||||||
List<Layer> undoLayers = [];
|
List<Layer> undoLayers = [];
|
||||||
List<Layer> removedLayers = [];
|
List<Layer> removedLayers = [];
|
||||||
|
|
||||||
|
const gMediaShowInfinite = 999999;
|
||||||
|
|
||||||
class ShareImageEditorView extends StatefulWidget {
|
class ShareImageEditorView extends StatefulWidget {
|
||||||
const ShareImageEditorView(
|
const ShareImageEditorView(
|
||||||
{super.key, this.imageBytes, this.sendTo, this.videoFilePath});
|
{super.key, this.imageBytes, this.sendTo, this.videoFilePath});
|
||||||
|
|
@ -40,7 +42,7 @@ class ShareImageEditorView extends StatefulWidget {
|
||||||
class _ShareImageEditorView extends State<ShareImageEditorView> {
|
class _ShareImageEditorView extends State<ShareImageEditorView> {
|
||||||
bool _isRealTwonly = false;
|
bool _isRealTwonly = false;
|
||||||
bool videoWithAudio = true;
|
bool videoWithAudio = true;
|
||||||
int maxShowTime = 999999;
|
int maxShowTime = gMediaShowInfinite;
|
||||||
String? sendNextMediaToUserName;
|
String? sendNextMediaToUserName;
|
||||||
double tabDownPostion = 0;
|
double tabDownPostion = 0;
|
||||||
bool sendingOrLoadingImage = true;
|
bool sendingOrLoadingImage = true;
|
||||||
|
|
@ -58,6 +60,7 @@ class _ShareImageEditorView extends State<ShareImageEditorView> {
|
||||||
if (widget.imageBytes != null) {
|
if (widget.imageBytes != null) {
|
||||||
loadImage(widget.imageBytes!);
|
loadImage(widget.imageBytes!);
|
||||||
} else if (widget.videoFilePath != null) {
|
} else if (widget.videoFilePath != null) {
|
||||||
|
layers.add(FilterLayerData());
|
||||||
setState(() {
|
setState(() {
|
||||||
sendingOrLoadingImage = false;
|
sendingOrLoadingImage = false;
|
||||||
});
|
});
|
||||||
|
|
@ -161,7 +164,7 @@ class _ShareImageEditorView extends State<ShareImageEditorView> {
|
||||||
: maxShowTime.toString(),
|
: maxShowTime.toString(),
|
||||||
child: ActionButton(
|
child: ActionButton(
|
||||||
(widget.videoFilePath != null)
|
(widget.videoFilePath != null)
|
||||||
? maxShowTime == 1
|
? maxShowTime == 999999
|
||||||
? Icons.repeat_rounded
|
? Icons.repeat_rounded
|
||||||
: Icons.repeat_one_rounded
|
: Icons.repeat_one_rounded
|
||||||
: Icons.timer_outlined,
|
: Icons.timer_outlined,
|
||||||
|
|
@ -169,14 +172,18 @@ class _ShareImageEditorView extends State<ShareImageEditorView> {
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
if (widget.videoFilePath != null) {
|
if (widget.videoFilePath != null) {
|
||||||
setState(() {
|
setState(() {
|
||||||
maxShowTime = (maxShowTime + 1) % 2;
|
if (maxShowTime == gMediaShowInfinite) {
|
||||||
|
maxShowTime = 0;
|
||||||
|
} else {
|
||||||
|
maxShowTime = gMediaShowInfinite;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (maxShowTime == 999999) {
|
if (maxShowTime == gMediaShowInfinite) {
|
||||||
maxShowTime = 4;
|
maxShowTime = 4;
|
||||||
} else if (maxShowTime >= 22) {
|
} else if (maxShowTime >= 22) {
|
||||||
maxShowTime = 999999;
|
maxShowTime = gMediaShowInfinite;
|
||||||
} else {
|
} else {
|
||||||
maxShowTime = maxShowTime + 8;
|
maxShowTime = maxShowTime + 8;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ import 'package:logging/logging.dart';
|
||||||
import 'package:lottie/lottie.dart';
|
import 'package:lottie/lottie.dart';
|
||||||
import 'package:no_screenshot/no_screenshot.dart';
|
import 'package:no_screenshot/no_screenshot.dart';
|
||||||
import 'package:twonly/globals.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/animate_icon.dart';
|
||||||
import 'package:twonly/src/views/components/media_view_sizing.dart';
|
import 'package:twonly/src/views/components/media_view_sizing.dart';
|
||||||
import 'package:twonly/src/database/twonly_database.dart';
|
import 'package:twonly/src/database/twonly_database.dart';
|
||||||
|
|
@ -183,8 +184,10 @@ class _MediaViewerViewState extends State<MediaViewerView> {
|
||||||
final vidoePath = await getVideoPath(current.messageId);
|
final vidoePath = await getVideoPath(current.messageId);
|
||||||
if (vidoePath != null) {
|
if (vidoePath != null) {
|
||||||
videoController = VideoPlayerController.file(File(vidoePath.path));
|
videoController = VideoPlayerController.file(File(vidoePath.path));
|
||||||
videoController?.setLooping(content.maxShowTime == 1);
|
videoController?.setLooping(content.maxShowTime == gMediaShowInfinite);
|
||||||
if (content.maxShowTime == 0) {
|
videoController?.initialize().then((_) {
|
||||||
|
videoController!.play();
|
||||||
|
if (content.maxShowTime != gMediaShowInfinite) {
|
||||||
videoController?.addListener(() {
|
videoController?.addListener(() {
|
||||||
if (videoController?.value.position ==
|
if (videoController?.value.position ==
|
||||||
videoController?.value.duration) {
|
videoController?.value.duration) {
|
||||||
|
|
@ -192,8 +195,6 @@ class _MediaViewerViewState extends State<MediaViewerView> {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
videoController?.initialize().then((_) {
|
|
||||||
videoController!.play();
|
|
||||||
setState(() {});
|
setState(() {});
|
||||||
}).catchError((Object error) {
|
}).catchError((Object error) {
|
||||||
Logger("media_viewer_view.dart").shout(error);
|
Logger("media_viewer_view.dart").shout(error);
|
||||||
|
|
@ -219,11 +220,11 @@ class _MediaViewerViewState extends State<MediaViewerView> {
|
||||||
canBeSeenUntil = DateTime.now().add(
|
canBeSeenUntil = DateTime.now().add(
|
||||||
Duration(seconds: content.maxShowTime),
|
Duration(seconds: content.maxShowTime),
|
||||||
);
|
);
|
||||||
maxShowTime = content.maxShowTime;
|
|
||||||
startTimer();
|
startTimer();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setState(() {
|
setState(() {
|
||||||
|
maxShowTime = content.maxShowTime;
|
||||||
isDownloading = false;
|
isDownloading = false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
@ -291,7 +292,7 @@ class _MediaViewerViewState extends State<MediaViewerView> {
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
if (maxShowTime == 999999)
|
if (maxShowTime == gMediaShowInfinite)
|
||||||
OutlinedButton(
|
OutlinedButton(
|
||||||
style: OutlinedButton.styleFrom(
|
style: OutlinedButton.styleFrom(
|
||||||
iconColor: imageSaved
|
iconColor: imageSaved
|
||||||
|
|
@ -424,8 +425,9 @@ class _MediaViewerViewState extends State<MediaViewerView> {
|
||||||
duration: const Duration(milliseconds: 200),
|
duration: const Duration(milliseconds: 200),
|
||||||
child: frame != null
|
child: frame != null
|
||||||
? child
|
? child
|
||||||
: SizedBox(
|
: Container(
|
||||||
height: 60,
|
height: 60,
|
||||||
|
color: Colors.transparent,
|
||||||
width: 60,
|
width: 60,
|
||||||
child: CircularProgressIndicator(
|
child: CircularProgressIndicator(
|
||||||
strokeWidth: 2,
|
strokeWidth: 2,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue