Skip to content

Offline gym log for Android. No account, no ads, no internet.

Show a frame of your own video as the exercise preview

InlitXd9b98eeb007b
diff --git a/lib/widgets/exercise_media.dart b/lib/widgets/exercise_media.dart
index 1c23c92..53ccb07 100644
--- a/lib/widgets/exercise_media.dart
+++ b/lib/widgets/exercise_media.dart
@@ -1,5 +1,6 @@
import 'dart:async';
import 'dart:io';
+import 'dart:math' as math;
import 'package:flutter/cupertino.dart';
import 'package:phosphoricons_flutter/phosphoricons_flutter.dart';
@@ -50,9 +51,10 @@ class ExerciseMedia extends StatelessWidget {
return _VideoTile(
key: ValueKey(path), path: path, height: height, radius: radius, short: loops != null);
}
- if (isVideo && ex.art.isNotEmpty) {
+ if (isVideo) {
return Stack(children: [
- ExerciseArt(slug: ex.art, height: height, radius: radius, bordered: bordered),
+ _VideoTile(
+ key: ValueKey('still-$path'), path: path, height: height, radius: radius, bordered: bordered, still: true),
Positioned(right: 6, bottom: 6, child: _PlayBadge(height: height)),
]);
}
@@ -60,18 +62,16 @@ class ExerciseMedia extends StatelessWidget {
height: height,
radius: radius,
bordered: bordered,
- child: isVideo
- ? _VideoPoster(height: height)
- : Center(
- child: Image.file(
- File(path),
- key: ValueKey(media),
- fit: BoxFit.contain,
- alignment: Alignment.center,
- gaplessPlayback: true,
- errorBuilder: (_, _, _) => _fallbackIcon(context, height),
- ),
- ),
+ child: Center(
+ child: Image.file(
+ File(path),
+ key: ValueKey(media),
+ fit: BoxFit.contain,
+ alignment: Alignment.center,
+ gaplessPlayback: true,
+ errorBuilder: (_, _, _) => _fallbackIcon(context, height),
+ ),
+ ),
);
}
}
@@ -108,20 +108,6 @@ class _MediaFrame extends StatelessWidget {
}
}
-class _VideoPoster extends StatelessWidget {
- const _VideoPoster({required this.height});
- final double height;
-
- @override
- Widget build(BuildContext context) {
- final gc = context.gc;
- return Center(
- child: Icon(PhosphorIconsFill.playCircle,
- size: (height * 0.34).clamp(18.0, 54.0), color: gc.textSecondary),
- );
- }
-}
-
class _PlayBadge extends StatelessWidget {
const _PlayBadge({required this.height});
final double height;
@@ -145,11 +131,15 @@ class _VideoTile extends StatefulWidget {
required this.path,
required this.height,
required this.radius,
- this.short = false});
+ this.short = false,
+ this.still = false,
+ this.bordered = true});
final String path;
final double height;
final double radius;
final bool short;
+ final bool still;
+ final bool bordered;
@override
State<_VideoTile> createState() => _VideoTileState();
@@ -171,9 +161,14 @@ class _VideoTileState extends State<_VideoTile> {
try {
final c = VideoPlayerController.file(File(widget.path), videoPlayerOptions: VideoPlayerOptions(mixWithOthers: true));
await c.initialize();
- await c.setLooping(true);
await c.setVolume(0);
- await c.play();
+ if (widget.still) {
+ final ms = c.value.duration.inMilliseconds;
+ await c.seekTo(Duration(milliseconds: math.min(500, ms ~/ 3)));
+ } else {
+ await c.setLooping(true);
+ await c.play();
+ }
if (!mounted) {
c.dispose();
return;
@@ -216,6 +211,6 @@ class _VideoTileState extends State<_VideoTile> {
const Center(child: CupertinoActivityIndicator()),
]);
}
- return _MediaFrame(height: widget.height, radius: widget.radius, child: child);
+ return _MediaFrame(height: widget.height, radius: widget.radius, bordered: widget.bordered, child: child);
}
}