2024-01-15 16:50:33 +00:00
|
|
|
import 'package:auto_route/auto_route.dart';
|
2022-02-06 00:07:56 -06:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:chewie/chewie.dart';
|
2024-02-23 00:18:02 -05:00
|
|
|
import 'package:flutter_hooks/flutter_hooks.dart';
|
|
|
|
import 'package:immich_mobile/modules/asset_viewer/hooks/chewiew_controller_hook.dart';
|
2023-06-26 18:27:47 +03:00
|
|
|
import 'package:immich_mobile/modules/asset_viewer/ui/video_player_controls.dart';
|
2022-11-08 18:00:24 +01:00
|
|
|
import 'package:immich_mobile/shared/models/asset.dart';
|
2024-02-23 00:18:02 -05:00
|
|
|
import 'package:immich_mobile/shared/ui/delayed_loading_indicator.dart';
|
2022-02-06 00:07:56 -06:00
|
|
|
|
2024-01-15 16:50:33 +00:00
|
|
|
@RoutePage()
|
2022-04-02 12:31:53 -05:00
|
|
|
// ignore: must_be_immutable
|
2024-02-23 00:18:02 -05:00
|
|
|
class VideoViewerPage extends HookWidget {
|
2022-11-08 18:00:24 +01:00
|
|
|
final Asset asset;
|
2022-11-18 23:12:54 -06:00
|
|
|
final bool isMotionVideo;
|
2023-06-20 17:17:43 -04:00
|
|
|
final Widget? placeholder;
|
2024-02-07 23:07:50 -05:00
|
|
|
final VoidCallback? onVideoEnded;
|
2023-02-05 07:57:07 -05:00
|
|
|
final VoidCallback? onPlaying;
|
|
|
|
final VoidCallback? onPaused;
|
2024-02-07 23:07:50 -05:00
|
|
|
final Duration hideControlsTimer;
|
|
|
|
final bool showControls;
|
|
|
|
final bool showDownloadingIndicator;
|
2022-02-06 00:07:56 -06:00
|
|
|
|
2022-11-18 23:12:54 -06:00
|
|
|
const VideoViewerPage({
|
2024-01-27 16:14:32 +00:00
|
|
|
super.key,
|
2022-11-18 23:12:54 -06:00
|
|
|
required this.asset,
|
2024-02-07 23:07:50 -05:00
|
|
|
this.isMotionVideo = false,
|
|
|
|
this.onVideoEnded,
|
2023-02-05 07:57:07 -05:00
|
|
|
this.onPlaying,
|
|
|
|
this.onPaused,
|
2023-06-20 17:17:43 -04:00
|
|
|
this.placeholder,
|
2024-02-07 23:07:50 -05:00
|
|
|
this.showControls = true,
|
|
|
|
this.hideControlsTimer = const Duration(seconds: 5),
|
|
|
|
this.showDownloadingIndicator = true,
|
2024-01-27 16:14:32 +00:00
|
|
|
});
|
2022-02-06 00:07:56 -06:00
|
|
|
|
|
|
|
@override
|
2024-02-23 00:18:02 -05:00
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final controller = useChewieController(
|
|
|
|
asset,
|
2023-04-06 13:51:52 -04:00
|
|
|
controlsSafeAreaMinimum: const EdgeInsets.only(
|
2023-04-18 11:23:56 -05:00
|
|
|
bottom: 100,
|
2023-04-06 13:51:52 -04:00
|
|
|
),
|
2024-02-28 16:48:59 -05:00
|
|
|
placeholder: placeholder,
|
2024-02-23 00:18:02 -05:00
|
|
|
showControls: showControls && !isMotionVideo,
|
|
|
|
hideControlsTimer: hideControlsTimer,
|
2023-06-26 18:27:47 +03:00
|
|
|
customControls: const VideoPlayerControls(),
|
2024-02-23 00:18:02 -05:00
|
|
|
onPlaying: onPlaying,
|
|
|
|
onPaused: onPaused,
|
|
|
|
onVideoEnded: onVideoEnded,
|
2022-02-06 00:07:56 -06:00
|
|
|
);
|
|
|
|
|
2024-02-23 00:18:02 -05:00
|
|
|
// Loading
|
|
|
|
return PopScope(
|
|
|
|
child: AnimatedSwitcher(
|
|
|
|
duration: const Duration(milliseconds: 400),
|
|
|
|
child: Builder(
|
|
|
|
builder: (context) {
|
|
|
|
if (controller == null) {
|
|
|
|
return Stack(
|
|
|
|
children: [
|
2024-02-28 16:48:59 -05:00
|
|
|
if (placeholder != null) placeholder!,
|
|
|
|
const Positioned.fill(
|
|
|
|
child: Center(
|
|
|
|
child: DelayedLoadingIndicator(
|
|
|
|
fadeInDuration: Duration(milliseconds: 500),
|
|
|
|
),
|
|
|
|
),
|
2024-02-23 00:18:02 -05:00
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
final size = MediaQuery.of(context).size;
|
|
|
|
return SizedBox(
|
|
|
|
height: size.height,
|
|
|
|
width: size.width,
|
|
|
|
child: Chewie(
|
|
|
|
controller: controller,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
},
|
2023-04-18 11:23:56 -05:00
|
|
|
),
|
2024-02-23 00:18:02 -05:00
|
|
|
),
|
|
|
|
);
|
2022-02-06 00:07:56 -06:00
|
|
|
}
|
|
|
|
}
|