'
@@ -304,6 +308,12 @@ export function initLightbox () {
}
})
+ // Start buffering only the video on screen, as soon as its slide is current
+ state.lightbox.on('contentActivate', ({ content }: { content: { element?: HTMLElement } }) => {
+ const video = content.element?.querySelector('video')
+ if (video && video.preload !== 'auto') video.preload = 'auto'
+ })
+
// Video autoplay (off by default, ipp.lightbox.autoPlayVideos). PhotoSwipe
// fires contentActivate/contentDeactivate as slides become / stop being the
// current slide, including the initial slide on open.
@@ -342,7 +352,8 @@ export function initLightbox () {
const video = content.element?.querySelector('video')
if (video) {
video.pause()
- video.currentTime = 0
+ // Seeking (even to 0) fetches again; skip it for a video never played
+ if (video.currentTime > 0) video.currentTime = 0
}
})