mirror of
https://github.com/immich-app/immich.git
synced 2025-01-04 02:46:47 +01:00
fix: aspect ratio
This commit is contained in:
parent
5e8ee6dc5f
commit
46a8e9084a
2 changed files with 25 additions and 14 deletions
|
@ -37,6 +37,8 @@ class NativeVideoViewerPage extends HookConsumerWidget {
|
||||||
final controller = useState<NativeVideoPlayerController?>(null);
|
final controller = useState<NativeVideoPlayerController?>(null);
|
||||||
final lastVideoPosition = useRef(-1);
|
final lastVideoPosition = useRef(-1);
|
||||||
final isBuffering = useRef(false);
|
final isBuffering = useRef(false);
|
||||||
|
final width = useRef<double>(asset.width?.toDouble() ?? 1.0);
|
||||||
|
final height = useRef<double>(asset.height?.toDouble() ?? 1.0);
|
||||||
|
|
||||||
void checkIfBuffering([Timer? timer]) {
|
void checkIfBuffering([Timer? timer]) {
|
||||||
if (!context.mounted) {
|
if (!context.mounted) {
|
||||||
|
@ -60,10 +62,15 @@ class NativeVideoViewerPage extends HookConsumerWidget {
|
||||||
|
|
||||||
Future<VideoSource> createSource(Asset asset) async {
|
Future<VideoSource> createSource(Asset asset) async {
|
||||||
if (asset.isLocal && asset.livePhotoVideoId == null) {
|
if (asset.isLocal && asset.livePhotoVideoId == null) {
|
||||||
final file = await asset.local!.file;
|
final entity = await asset.local!.obtainForNewProperties();
|
||||||
if (file == null) {
|
final file = await entity?.file;
|
||||||
|
if (entity == null || file == null) {
|
||||||
throw Exception('No file found for the video');
|
throw Exception('No file found for the video');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
width.value = entity.orientatedWidth.toDouble();
|
||||||
|
height.value = entity.orientatedHeight.toDouble();
|
||||||
|
|
||||||
return await VideoSource.init(
|
return await VideoSource.init(
|
||||||
path: file.path,
|
path: file.path,
|
||||||
type: VideoSourceType.file,
|
type: VideoSourceType.file,
|
||||||
|
@ -165,18 +172,15 @@ class NativeVideoViewerPage extends HookConsumerWidget {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
controller.value = nc;
|
nc.onPlaybackPositionChanged.addListener(onPlaybackPositionChanged);
|
||||||
|
nc.onPlaybackStatusChanged.addListener(onPlaybackPositionChanged);
|
||||||
controller.value?.onPlaybackPositionChanged
|
nc.onPlaybackReady.addListener(onPlaybackReady);
|
||||||
.addListener(onPlaybackPositionChanged);
|
nc.onPlaybackEnded.addListener(onPlaybackEnded);
|
||||||
controller.value?.onPlaybackStatusChanged
|
|
||||||
.addListener(onPlaybackPositionChanged);
|
|
||||||
controller.value?.onPlaybackReady.addListener(onPlaybackReady);
|
|
||||||
controller.value?.onPlaybackEnded.addListener(onPlaybackEnded);
|
|
||||||
|
|
||||||
final videoSource = await createSource(asset);
|
final videoSource = await createSource(asset);
|
||||||
controller.value?.loadVideoSource(videoSource);
|
nc.loadVideoSource(videoSource);
|
||||||
|
|
||||||
|
controller.value = nc;
|
||||||
Timer(const Duration(milliseconds: 200), checkIfBuffering);
|
Timer(const Duration(milliseconds: 200), checkIfBuffering);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -206,6 +210,13 @@ class NativeVideoViewerPage extends HookConsumerWidget {
|
||||||
[],
|
[],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
double calculateAspectRatio() {
|
||||||
|
if (width.value == 0 || height.value == 0) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return width.value / height.value;
|
||||||
|
}
|
||||||
|
|
||||||
final size = MediaQuery.sizeOf(context);
|
final size = MediaQuery.sizeOf(context);
|
||||||
|
|
||||||
return SizedBox(
|
return SizedBox(
|
||||||
|
@ -224,7 +235,7 @@ class NativeVideoViewerPage extends HookConsumerWidget {
|
||||||
children: [
|
children: [
|
||||||
Center(
|
Center(
|
||||||
child: AspectRatio(
|
child: AspectRatio(
|
||||||
aspectRatio: (asset.width ?? 1) / (asset.height ?? 1),
|
aspectRatio: calculateAspectRatio(),
|
||||||
child: NativeVideoPlayerView(
|
child: NativeVideoPlayerView(
|
||||||
onViewReady: initController,
|
onViewReady: initController,
|
||||||
),
|
),
|
||||||
|
|
|
@ -1761,10 +1761,10 @@ packages:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: vm_service
|
name: vm_service
|
||||||
sha256: f652077d0bdf60abe4c1f6377448e8655008eef28f128bc023f7b5e8dfeb48fc
|
sha256: "5c5f338a667b4c644744b661f309fb8080bb94b18a7e91ef1dbd343bed00ed6d"
|
||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "14.2.4"
|
version: "14.2.5"
|
||||||
wakelock_plus:
|
wakelock_plus:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
|
|
Loading…
Reference in a new issue