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