Add config option for autoplay videos

This commit is contained in:
Alan Grainger
2026-06-11 16:12:00 +12:00
parent 46438f1c74
commit 652f2903ce
6 changed files with 56 additions and 20 deletions
+2 -1
View File
@@ -46,7 +46,8 @@
"lightbox": { "lightbox": {
"showArrows": true, "showArrows": true,
"showDownload": true, "showDownload": true,
"mobileArrows": false "mobileArrows": false,
"autoPlayVideos": false
} }
} }
} }
+6 -2
View File
@@ -132,8 +132,12 @@ html.pswp-no-arrows .pswp__button--arrow {
} }
.pswp__video-wrap video { .pswp__video-wrap video {
max-width: 100%; /* Fill the slide area immediately (the poster sizes the element before the
max-height: 100%; 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; outline: none;
pointer-events: auto; pointer-events: auto;
background: #000; background: #000;
+28
View File
@@ -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) // Optional control hiding (defaults match Immich's behavior)
const docEl = document.documentElement const docEl = document.documentElement
if (!state.lightboxConfig.showArrows) docEl.classList.add('pswp-no-arrows') if (!state.lightboxConfig.showArrows) docEl.classList.add('pswp-no-arrows')
+1
View File
@@ -135,6 +135,7 @@ export async function gallery (res: Response, share: SharedLink, openItem?: numb
showDownload: downloadAllowed && !!getConfigOption('ipp.lightbox.showDownload', true), showDownload: downloadAllowed && !!getConfigOption('ipp.lightbox.showDownload', true),
showArrows: !!getConfigOption('ipp.lightbox.showArrows', true), showArrows: !!getConfigOption('ipp.lightbox.showArrows', true),
mobileArrows: !!getConfigOption('ipp.lightbox.mobileArrows', false), mobileArrows: !!getConfigOption('ipp.lightbox.mobileArrows', false),
autoPlayVideos: !!getConfigOption('ipp.lightbox.autoPlayVideos', false),
options: lightboxOptions options: lightboxOptions
}, },
metadataConfig: { metadataConfig: {
+1
View File
@@ -60,6 +60,7 @@ export interface LightboxConfig {
showArrows: boolean showArrows: boolean
showDownload: boolean showDownload: boolean
mobileArrows: boolean mobileArrows: boolean
autoPlayVideos: boolean
options?: Record<string, unknown> options?: Record<string, unknown>
} }
+18 -17
View File
@@ -105,6 +105,7 @@ The gallery's lightbox is powered by [PhotoSwipe](https://photoswipe.com/). Conf
| `showArrows` | `bool` | Show the prev/next arrows on desktop. They appear when the user hovers the lightbox. Default `true`. | | `showArrows` | `bool` | Show the prev/next arrows on desktop. They appear when the user hovers the lightbox. Default `true`. |
| `showDownload` | `bool` | Show a download button in the lightbox toolbar. Only takes effect when downloads are also allowed by `allowDownloadAll`. Default `true`. | | `showDownload` | `bool` | Show a download button in the lightbox toolbar. Only takes effect when downloads are also allowed by `allowDownloadAll`. Default `true`. |
| `mobileArrows` | `bool` | Show prev/next arrows on mobile (under 640px viewport). Off by default since swipe is the natural mobile navigation. | | `mobileArrows` | `bool` | Show prev/next arrows on mobile (under 640px viewport). Off by default since swipe is the natural mobile navigation. |
| `autoPlayVideos` | `bool` | Automatically play videos when their slide opens or becomes active. If the browser blocks unmuted autoplay (e.g. when deep-linking straight to a video), playback falls back to muted. Default `false`. |
| `options` | `object` | Custom [PhotoSwipe options](https://photoswipe.com/options/) to override defaults (e.g. `{"wheelToZoom": true}`). | | `options` | `object` | Custom [PhotoSwipe options](https://photoswipe.com/options/) to override defaults (e.g. `{"wheelToZoom": true}`). |
Example: hide the download button inside the lightbox even though zip downloads are otherwise allowed. Example: hide the download button inside the lightbox even though zip downloads are otherwise allowed.
@@ -123,10 +124,10 @@ Example: hide the download button inside the lightbox even though zip downloads
Configured under `ipp.showMetadata`. The lightbox includes a slide-in info sidebar (toggle with the **i** key or the info button in the toolbar) that surfaces whatever metadata you opt into here. Configured under `ipp.showMetadata`. The lightbox includes a slide-in info sidebar (toggle with the **i** key or the info button in the toolbar) that surfaces whatever metadata you opt into here.
| Option | Type | Description | | Option | Type | Description |
|---------------|----------|---------------------------------------------------------------------------------------------------------------------------------------------------| |---------------|----------|------------------------------------------------------------------------------------------------------------------------------------|
| `description` | `object` | Where to show the description. `{ "caption": bool, "sidebar": bool }`. Both default `false`. See [Description](#description). | | `description` | `object` | Where to show the description. `{ "caption": bool, "sidebar": bool }`. Both default `false`. See [Description](#description). |
| `exif` | `object` | Camera / file EXIF group. Per-field opt-in flags, all default `false`. See [EXIF group](#exif-group). | | `exif` | `object` | Camera / file EXIF group. Per-field opt-in flags, all default `false`. See [EXIF group](#exif-group). |
| `location` | `object` | Location group (city / state / country / GPS). Per-field opt-in flags, all default `false`. See [Location group](#location-group). | | `location` | `object` | Location group (city / state / country / GPS). Per-field opt-in flags, all default `false`. See [Location group](#location-group). |
Every per-field flag defaults to `false`. A field is sent to the client only when its flag is explicitly `true`. There is no master switch - this is deliberate, so that fields IPP adds in future releases don't auto-expose without your action. Every per-field flag defaults to `false`. A field is sent to the client only when its flag is explicitly `true`. There is no master switch - this is deliberate, so that fields IPP adds in future releases don't auto-expose without your action.
@@ -171,12 +172,12 @@ Under `ipp.showMetadata.exif`.
Under `ipp.showMetadata.location`. Under `ipp.showMetadata.location`.
| Option | Type | Description | | Option | Type | Description |
|------------|--------|----------------------------------------------------------------------| |------------|--------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `city` | `bool` | Show city. | | `city` | `bool` | Show city. |
| `state` | `bool` | Show state / region. | | `state` | `bool` | Show state / region. |
| `country` | `bool` | Show country. | | `country` | `bool` | Show country. |
| `gps` | `bool` | Show GPS coordinates. | | `gps` | `bool` | Show GPS coordinates. |
| `webLink` | `bool` | Show an "Open in OpenStreetMap" link below the coordinates. The link is rendered with `rel="noreferrer"` so the share URL is not leaked to the map provider when a viewer clicks it. Has no effect unless `gps` is also true. Default `true`. | | `webLink` | `bool` | Show an "Open in OpenStreetMap" link below the coordinates. The link is rendered with `rel="noreferrer"` so the share URL is not leaked to the map provider when a viewer clicks it. Has no effect unless `gps` is also true. Default `true`. |
A full example showing the description in the sidebar only (not as a lightbox caption), exposing camera EXIF, and revealing place names but not the GPS coordinates: A full example showing the description in the sidebar only (not as a lightbox caption), exposing camera EXIF, and revealing place names but not the GPS coordinates:
@@ -219,13 +220,13 @@ A few config keys have been renamed across versions. Existing configs continue t
**Gallery keys moved under `ipp.gallery.*` (v2.0).** The old top-level keys are mapped automatically: **Gallery keys moved under `ipp.gallery.*` (v2.0).** The old top-level keys are mapped automatically:
| Legacy key | New key | | Legacy key | New key |
|---------------------------|-------------------------------| |------------------------------|----------------------------------|
| `ipp.singleImageGallery` | `ipp.gallery.singleImage` | | `ipp.singleImageGallery` | `ipp.gallery.singleImage` |
| `ipp.singleItemAutoOpen` | `ipp.gallery.singleItemAutoOpen` | | `ipp.singleItemAutoOpen` | `ipp.gallery.singleItemAutoOpen` |
| `ipp.showGalleryTitle` | `ipp.gallery.showTitle` | | `ipp.showGalleryTitle` | `ipp.gallery.showTitle` |
| `ipp.showGalleryDescription` | `ipp.gallery.showDescription` | | `ipp.showGalleryDescription` | `ipp.gallery.showDescription` |
| `ipp.groupGalleryByDate` | `ipp.gallery.groupByDate` | | `ipp.groupGalleryByDate` | `ipp.gallery.groupByDate` |
**`showMetadata.description` is now an object.** It used to be a single boolean. A legacy `description: true` migrates to `{ caption: true, sidebar: true }` (and `false` to both `false`). Move to the explicit form to silence the deprecation notice and so you can target the caption vs. the sidebar independently. **`showMetadata.description` is now an object.** It used to be a single boolean. A legacy `description: true` migrates to `{ caption: true, sidebar: true }` (and `false` to both `false`). Move to the explicit form to silence the deprecation notice and so you can target the caption vs. the sidebar independently.