2022-04-24 04:08:45 +02:00
|
|
|
import 'package:auto_route/auto_route.dart';
|
2022-02-06 08:07:56 +02:00
|
|
|
import 'package:flutter/material.dart';
|
2022-04-02 19:31:53 +02:00
|
|
|
import 'package:flutter_hooks/flutter_hooks.dart';
|
2022-04-24 04:08:45 +02:00
|
|
|
import 'package:flutter_swipe_detector/flutter_swipe_detector.dart';
|
2022-02-06 08:07:56 +02:00
|
|
|
import 'package:hive/hive.dart';
|
2022-04-02 19:31:53 +02:00
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
2022-02-06 08:07:56 +02:00
|
|
|
import 'package:immich_mobile/constants/hive_box.dart';
|
|
|
|
import 'package:chewie/chewie.dart';
|
2022-04-02 19:31:53 +02:00
|
|
|
import 'package:immich_mobile/modules/asset_viewer/models/image_viewer_page_state.model.dart';
|
|
|
|
import 'package:immich_mobile/modules/asset_viewer/providers/image_viewer_page_state.provider.dart';
|
|
|
|
import 'package:immich_mobile/modules/asset_viewer/ui/download_loading_indicator.dart';
|
|
|
|
import 'package:immich_mobile/modules/asset_viewer/ui/exif_bottom_sheet.dart';
|
|
|
|
import 'package:immich_mobile/modules/asset_viewer/ui/top_control_app_bar.dart';
|
|
|
|
import 'package:immich_mobile/modules/home/services/asset.service.dart';
|
2022-07-13 14:23:48 +02:00
|
|
|
import 'package:openapi/api.dart';
|
2022-02-06 08:07:56 +02:00
|
|
|
import 'package:video_player/video_player.dart';
|
|
|
|
|
2022-04-02 19:31:53 +02:00
|
|
|
// ignore: must_be_immutable
|
|
|
|
class VideoViewerPage extends HookConsumerWidget {
|
2022-02-06 08:07:56 +02:00
|
|
|
final String videoUrl;
|
2022-07-13 14:23:48 +02:00
|
|
|
final AssetResponseDto asset;
|
|
|
|
AssetResponseDto? assetDetail;
|
2022-02-06 08:07:56 +02:00
|
|
|
|
2022-06-25 20:46:51 +02:00
|
|
|
VideoViewerPage({Key? key, required this.videoUrl, required this.asset})
|
|
|
|
: super(key: key);
|
2022-02-06 08:07:56 +02:00
|
|
|
|
|
|
|
@override
|
2022-04-02 19:31:53 +02:00
|
|
|
Widget build(BuildContext context, WidgetRef ref) {
|
2022-06-25 20:46:51 +02:00
|
|
|
final downloadAssetStatus =
|
|
|
|
ref.watch(imageViewerStateProvider).downloadAssetStatus;
|
2022-04-02 19:31:53 +02:00
|
|
|
|
2022-02-06 08:07:56 +02:00
|
|
|
String jwtToken = Hive.box(userInfoBox).get(accessTokenKey);
|
|
|
|
|
2022-04-24 04:08:45 +02:00
|
|
|
void showInfo() {
|
|
|
|
showModalBottomSheet(
|
|
|
|
backgroundColor: Colors.black,
|
|
|
|
barrierColor: Colors.transparent,
|
|
|
|
isScrollControlled: false,
|
|
|
|
context: context,
|
|
|
|
builder: (context) {
|
|
|
|
return ExifBottomSheet(assetDetail: assetDetail!);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-04-02 19:31:53 +02:00
|
|
|
getAssetExif() async {
|
2022-06-25 20:46:51 +02:00
|
|
|
assetDetail =
|
|
|
|
await ref.watch(assetServiceProvider).getAssetById(asset.id);
|
2022-04-02 19:31:53 +02:00
|
|
|
}
|
|
|
|
|
2022-07-13 14:23:48 +02:00
|
|
|
useEffect(
|
|
|
|
() {
|
|
|
|
getAssetExif();
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
[],
|
|
|
|
);
|
2022-04-02 19:31:53 +02:00
|
|
|
|
2022-02-06 08:07:56 +02:00
|
|
|
return Scaffold(
|
|
|
|
backgroundColor: Colors.black,
|
2022-04-02 19:31:53 +02:00
|
|
|
appBar: TopControlAppBar(
|
|
|
|
asset: asset,
|
|
|
|
onMoreInfoPressed: () {
|
2022-04-24 04:08:45 +02:00
|
|
|
showInfo();
|
2022-04-02 19:31:53 +02:00
|
|
|
},
|
|
|
|
onDownloadPressed: () {
|
2022-06-25 20:46:51 +02:00
|
|
|
ref
|
|
|
|
.watch(imageViewerStateProvider.notifier)
|
|
|
|
.downloadAsset(asset, context);
|
2022-04-02 19:31:53 +02:00
|
|
|
},
|
2022-02-06 08:07:56 +02:00
|
|
|
),
|
2022-04-24 04:08:45 +02:00
|
|
|
body: SwipeDetector(
|
|
|
|
onSwipeDown: (_) {
|
|
|
|
AutoRouter.of(context).pop();
|
|
|
|
},
|
|
|
|
onSwipeUp: (_) {
|
|
|
|
showInfo();
|
|
|
|
},
|
|
|
|
child: SafeArea(
|
|
|
|
child: Stack(
|
|
|
|
children: [
|
|
|
|
VideoThumbnailPlayer(
|
|
|
|
url: videoUrl,
|
|
|
|
jwtToken: jwtToken,
|
2022-04-02 19:31:53 +02:00
|
|
|
),
|
2022-04-24 04:08:45 +02:00
|
|
|
if (downloadAssetStatus == DownloadAssetStatus.loading)
|
|
|
|
const Center(
|
|
|
|
child: DownloadLoadingIndicator(),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
2022-02-06 08:07:56 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class VideoThumbnailPlayer extends StatefulWidget {
|
|
|
|
final String url;
|
|
|
|
final String? jwtToken;
|
|
|
|
|
2022-06-25 20:46:51 +02:00
|
|
|
const VideoThumbnailPlayer({Key? key, required this.url, this.jwtToken})
|
|
|
|
: super(key: key);
|
2022-02-06 08:07:56 +02:00
|
|
|
|
|
|
|
@override
|
|
|
|
State<VideoThumbnailPlayer> createState() => _VideoThumbnailPlayerState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _VideoThumbnailPlayerState extends State<VideoThumbnailPlayer> {
|
|
|
|
late VideoPlayerController videoPlayerController;
|
|
|
|
ChewieController? chewieController;
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
initializePlayer();
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> initializePlayer() async {
|
|
|
|
try {
|
2022-07-13 14:23:48 +02:00
|
|
|
videoPlayerController = VideoPlayerController.network(
|
|
|
|
widget.url,
|
|
|
|
httpHeaders: {"Authorization": "Bearer ${widget.jwtToken}"},
|
|
|
|
);
|
2022-02-06 08:07:56 +02:00
|
|
|
|
|
|
|
await videoPlayerController.initialize();
|
|
|
|
_createChewieController();
|
|
|
|
setState(() {});
|
|
|
|
} catch (e) {
|
|
|
|
debugPrint("ERROR initialize video player");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_createChewieController() {
|
|
|
|
chewieController = ChewieController(
|
|
|
|
showOptions: true,
|
|
|
|
showControlsOnInitialize: false,
|
|
|
|
videoPlayerController: videoPlayerController,
|
|
|
|
autoPlay: true,
|
|
|
|
autoInitialize: false,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void dispose() {
|
|
|
|
super.dispose();
|
|
|
|
videoPlayerController.pause();
|
|
|
|
videoPlayerController.dispose();
|
|
|
|
chewieController?.dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2022-07-01 03:08:49 +02:00
|
|
|
return chewieController?.videoPlayerController.value.isInitialized == true
|
2022-02-06 08:07:56 +02:00
|
|
|
? SizedBox(
|
|
|
|
child: Chewie(
|
|
|
|
controller: chewieController!,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
: const SizedBox(
|
|
|
|
width: 75,
|
|
|
|
height: 75,
|
|
|
|
child: CircularProgressIndicator.adaptive(
|
|
|
|
strokeWidth: 2,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|