Add config option for autoplay videos
This commit is contained in:
+2
-1
@@ -46,7 +46,8 @@
|
||||
"lightbox": {
|
||||
"showArrows": true,
|
||||
"showDownload": true,
|
||||
"mobileArrows": false
|
||||
"mobileArrows": false,
|
||||
"autoPlayVideos": false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -132,8 +132,12 @@ html.pswp-no-arrows .pswp__button--arrow {
|
||||
}
|
||||
|
||||
.pswp__video-wrap video {
|
||||
max-width: 100%;
|
||||
max-height: 100%;
|
||||
/* Fill the slide area immediately (the poster sizes the element before the
|
||||
stream loads) so the container doesn't snap to a new size when the video's
|
||||
real dimensions arrive. */
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: contain;
|
||||
outline: none;
|
||||
pointer-events: auto;
|
||||
background: #000;
|
||||
|
||||
@@ -163,6 +163,34 @@ export function initLightbox () {
|
||||
}
|
||||
})
|
||||
|
||||
// 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.
|
||||
if (state.lightboxConfig.autoPlayVideos) {
|
||||
state.lightbox.on('contentActivate', ({ content }: { content: { element?: HTMLElement } }) => {
|
||||
const video = content.element?.querySelector('video')
|
||||
if (video) {
|
||||
video.play().catch(() => {
|
||||
// Browsers block unmuted autoplay without a user gesture (e.g. a
|
||||
// deep link straight to a video slide) - retry muted.
|
||||
video.muted = true
|
||||
video.play().catch(() => {})
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Pause and rewind videos when sliding away so audio doesn't bleed into
|
||||
// the neighbouring slides (PhotoSwipe keeps them mounted). Applies whether
|
||||
// playback started automatically or manually.
|
||||
state.lightbox.on('contentDeactivate', ({ content }: { content: { element?: HTMLElement } }) => {
|
||||
const video = content.element?.querySelector('video')
|
||||
if (video) {
|
||||
video.pause()
|
||||
video.currentTime = 0
|
||||
}
|
||||
})
|
||||
|
||||
// Optional control hiding (defaults match Immich's behavior)
|
||||
const docEl = document.documentElement
|
||||
if (!state.lightboxConfig.showArrows) docEl.classList.add('pswp-no-arrows')
|
||||
|
||||
@@ -135,6 +135,7 @@ export async function gallery (res: Response, share: SharedLink, openItem?: numb
|
||||
showDownload: downloadAllowed && !!getConfigOption('ipp.lightbox.showDownload', true),
|
||||
showArrows: !!getConfigOption('ipp.lightbox.showArrows', true),
|
||||
mobileArrows: !!getConfigOption('ipp.lightbox.mobileArrows', false),
|
||||
autoPlayVideos: !!getConfigOption('ipp.lightbox.autoPlayVideos', false),
|
||||
options: lightboxOptions
|
||||
},
|
||||
metadataConfig: {
|
||||
|
||||
@@ -60,6 +60,7 @@ export interface LightboxConfig {
|
||||
showArrows: boolean
|
||||
showDownload: boolean
|
||||
mobileArrows: boolean
|
||||
autoPlayVideos: boolean
|
||||
options?: Record<string, unknown>
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user