1
0
Fork 0
mirror of https://github.com/immich-app/immich.git synced 2025-01-16 16:56:46 +01:00

faster initialization for remote videos

This commit is contained in:
mertalev 2024-11-16 23:51:48 -05:00
parent 03211c43f9
commit aa890c0858
No known key found for this signature in database
GPG key ID: CA85EF6600C9E8AD

View file

@ -61,6 +61,7 @@ class NativeVideoViewerPage extends HookConsumerWidget {
// If the swipe is canceled, `currentAsset` will not have changed and video A will continue to play.
final currentAsset = useState(ref.read(currentAssetProvider));
final isCurrent = currentAsset.value == asset;
final isVisible = useState(asset.isLocal || asset.isMotionPhoto);
final log = Logger('NativeVideoViewerPage');
@ -167,9 +168,12 @@ class NativeVideoViewerPage extends HookConsumerWidget {
return;
}
// if opening a remote video from a hero animation, delay initialization to avoid a stutter
// if opening a remote video from a hero animation, delay visibility to avoid a stutter
if (!asset.isLocal && isCurrent) {
await Future.delayed(const Duration(milliseconds: 200));
Timer(
const Duration(milliseconds: 200),
() => isVisible.value = true,
);
}
videoSource.value = videoSourceRes;
@ -431,8 +435,15 @@ class NativeVideoViewerPage extends HookConsumerWidget {
const [],
);
final video = aspectRatio.value != null
? Center(
return Stack(
children: [
// This remains under the video to avoid flickering
// For motion videos, this is the image portion of the asset
Center(key: ValueKey(asset.id), child: image),
Visibility.maintain(
key: ValueKey(asset),
visible: (asset.isVideo || showMotionVideo) && isVisible.value,
child: Center(
key: ValueKey(asset),
child: AspectRatio(
key: ValueKey(asset),
@ -444,22 +455,8 @@ class NativeVideoViewerPage extends HookConsumerWidget {
)
: null,
),
)
: null;
return Stack(
children: [
// This remains under the video to avoid flickering
// For motion videos, this is the image portion of the asset
Center(key: ValueKey(asset.id), child: image),
if (video != null)
asset.isVideo
? video
: Visibility.maintain(
key: ValueKey(asset),
visible: showMotionVideo,
child: video,
),
),
),
if (showControls) const Center(child: CustomVideoPlayerControls()),
],
);