1
0
Fork 0
mirror of https://github.com/immich-app/immich.git synced 2025-01-01 08:31:59 +00:00

add native player library

This commit is contained in:
Alex 2024-08-09 14:20:45 -05:00 committed by mertalev
parent 4b5657c21e
commit a8994ffb22
No known key found for this signature in database
GPG key ID: CA85EF6600C9E8AD
5 changed files with 81 additions and 25 deletions

View file

@ -65,6 +65,8 @@ PODS:
- maplibre_gl (0.0.1): - maplibre_gl (0.0.1):
- Flutter - Flutter
- MapLibre (= 5.14.0-pre3) - MapLibre (= 5.14.0-pre3)
- native_video_player (1.0.0):
- Flutter
- package_info_plus (0.4.5): - package_info_plus (0.4.5):
- Flutter - Flutter
- path_provider_foundation (0.0.1): - path_provider_foundation (0.0.1):
@ -115,6 +117,7 @@ DEPENDENCIES:
- integration_test (from `.symlinks/plugins/integration_test/ios`) - integration_test (from `.symlinks/plugins/integration_test/ios`)
- isar_flutter_libs (from `.symlinks/plugins/isar_flutter_libs/ios`) - isar_flutter_libs (from `.symlinks/plugins/isar_flutter_libs/ios`)
- maplibre_gl (from `.symlinks/plugins/maplibre_gl/ios`) - maplibre_gl (from `.symlinks/plugins/maplibre_gl/ios`)
- native_video_player (from `.symlinks/plugins/native_video_player/ios`)
- package_info_plus (from `.symlinks/plugins/package_info_plus/ios`) - package_info_plus (from `.symlinks/plugins/package_info_plus/ios`)
- path_provider_foundation (from `.symlinks/plugins/path_provider_foundation/darwin`) - path_provider_foundation (from `.symlinks/plugins/path_provider_foundation/darwin`)
- path_provider_ios (from `.symlinks/plugins/path_provider_ios/ios`) - path_provider_ios (from `.symlinks/plugins/path_provider_ios/ios`)
@ -168,6 +171,8 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/isar_flutter_libs/ios" :path: ".symlinks/plugins/isar_flutter_libs/ios"
maplibre_gl: maplibre_gl:
:path: ".symlinks/plugins/maplibre_gl/ios" :path: ".symlinks/plugins/maplibre_gl/ios"
native_video_player:
:path: ".symlinks/plugins/native_video_player/ios"
package_info_plus: package_info_plus:
:path: ".symlinks/plugins/package_info_plus/ios" :path: ".symlinks/plugins/package_info_plus/ios"
path_provider_foundation: path_provider_foundation:
@ -210,6 +215,7 @@ SPEC CHECKSUMS:
isar_flutter_libs: fdf730ca925d05687f36d7f1d355e482529ed097 isar_flutter_libs: fdf730ca925d05687f36d7f1d355e482529ed097
MapLibre: 620fc933c1d6029b33738c905c1490d024e5d4ef MapLibre: 620fc933c1d6029b33738c905c1490d024e5d4ef
maplibre_gl: a2efec727dd340e4c65e26d2b03b584f14881fd9 maplibre_gl: a2efec727dd340e4c65e26d2b03b584f14881fd9
native_video_player: d12af78a1a4a8cf09775a5177d5b392def6fd23c
package_info_plus: 58f0028419748fad15bf008b270aaa8e54380b1c package_info_plus: 58f0028419748fad15bf008b270aaa8e54380b1c
path_provider_foundation: 2b6b4c569c0fb62ec74538f866245ac84301af46 path_provider_foundation: 2b6b4c569c0fb62ec74538f866245ac84301af46
path_provider_ios: 14f3d2fd28c4fdb42f44e0f751d12861c43cee02 path_provider_ios: 14f3d2fd28c4fdb42f44e0f751d12861c43cee02

View file

@ -103,7 +103,7 @@ class VideoViewerPage extends HookConsumerWidget {
// Done in a microtask to avoid setting the state while the is building // Done in a microtask to avoid setting the state while the is building
if (!isMotionVideo) { if (!isMotionVideo) {
Future.microtask(() { Future.microtask(() {
ref.read(showControlsProvider.notifier).show = false; ref.read(showControlsProvider.notifier).show = true;
}); });
} }
@ -148,16 +148,20 @@ class VideoViewerPage extends HookConsumerWidget {
), ),
if (controller != null) if (controller != null)
SizedBox( SizedBox(
height: size.height, height: 16 / 9 * size.width,
width: size.width, width: size.width,
child: VideoPlayerViewer( child: AspectRatio(
controller: controller, aspectRatio: 16 / 9,
isMotionVideo: isMotionVideo, child: VideoPlayerViewer(
placeholder: placeholder, controller: controller,
hideControlsTimer: hideControlsTimer, isMotionVideo: isMotionVideo,
showControls: showControls, placeholder: placeholder,
showDownloadingIndicator: showDownloadingIndicator, hideControlsTimer: hideControlsTimer,
loopVideo: loopVideo, showControls: showControls,
showDownloadingIndicator: showDownloadingIndicator,
loopVideo: loopVideo,
asset: asset,
),
), ),
), ),
], ],

View file

@ -1,8 +1,11 @@
import 'package:chewie/chewie.dart'; import 'package:chewie/chewie.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:immich_mobile/entities/asset.entity.dart';
import 'package:immich_mobile/entities/store.entity.dart';
import 'package:immich_mobile/utils/hooks/chewiew_controller_hook.dart'; import 'package:immich_mobile/utils/hooks/chewiew_controller_hook.dart';
import 'package:immich_mobile/widgets/asset_viewer/custom_video_player_controls.dart'; import 'package:immich_mobile/widgets/asset_viewer/custom_video_player_controls.dart';
import 'package:native_video_player/native_video_player.dart';
import 'package:video_player/video_player.dart'; import 'package:video_player/video_player.dart';
class VideoPlayerViewer extends HookConsumerWidget { class VideoPlayerViewer extends HookConsumerWidget {
@ -13,6 +16,7 @@ class VideoPlayerViewer extends HookConsumerWidget {
final bool showControls; final bool showControls;
final bool showDownloadingIndicator; final bool showDownloadingIndicator;
final bool loopVideo; final bool loopVideo;
final Asset asset;
const VideoPlayerViewer({ const VideoPlayerViewer({
super.key, super.key,
@ -23,26 +27,59 @@ class VideoPlayerViewer extends HookConsumerWidget {
required this.showControls, required this.showControls,
required this.showDownloadingIndicator, required this.showDownloadingIndicator,
required this.loopVideo, required this.loopVideo,
required this.asset,
}); });
@override @override
Widget build(BuildContext context, WidgetRef ref) { Widget build(BuildContext context, WidgetRef ref) {
final chewie = useChewieController( // final chewie = useChewieController(
controller: controller, // controller: controller,
controlsSafeAreaMinimum: const EdgeInsets.only( // controlsSafeAreaMinimum: const EdgeInsets.only(
bottom: 100, // bottom: 100,
), // ),
placeholder: SizedBox.expand(child: placeholder), // placeholder: SizedBox.expand(child: placeholder),
customControls: CustomVideoPlayerControls( // customControls: CustomVideoPlayerControls(
hideTimerDuration: hideControlsTimer, // hideTimerDuration: hideControlsTimer,
), // ),
showControls: showControls && !isMotionVideo, // showControls: showControls && !isMotionVideo,
hideControlsTimer: hideControlsTimer, // hideControlsTimer: hideControlsTimer,
loopVideo: loopVideo, // loopVideo: loopVideo,
); // );
return Chewie( // return Chewie(
controller: chewie, // controller: chewie,
// );
return NativeVideoPlayerView(
onViewReady: (controller) async {
try {
String path = '';
VideoSourceType type = VideoSourceType.file;
if (asset.isLocal && asset.livePhotoVideoId == null) {
// Use a local file for the video player controller
final file = await asset.local!.file;
if (file == null) {
throw Exception('No file found for the video');
}
path = file.path;
type = VideoSourceType.file;
final videoSource = await VideoSource.init(
path: path,
type: type,
);
await controller.loadVideoSource(videoSource);
await controller.play();
Future.delayed(const Duration(milliseconds: 100), () async {
await controller.setVolume(0.5);
});
}
} catch (e) {
print('Error loading video: $e');
}
},
); );
} }
} }

View file

@ -1024,6 +1024,14 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "1.0.4" version: "1.0.4"
native_video_player:
dependency: "direct main"
description:
name: native_video_player
sha256: "8df92df138c13ebf9df6b30525f9c4198534705fd450a98da14856d3a0e48cd4"
url: "https://pub.dev"
source: hosted
version: "1.3.1"
nested: nested:
dependency: transitive dependency: transitive
description: description:

View file

@ -64,6 +64,7 @@ dependencies:
async: ^2.11.0 async: ^2.11.0
dynamic_color: ^1.7.0 #package to apply system theme dynamic_color: ^1.7.0 #package to apply system theme
background_downloader: ^8.5.5 background_downloader: ^8.5.5
native_video_player: ^1.3.1
#image editing packages #image editing packages
crop_image: ^1.0.13 crop_image: ^1.0.13