diff --git a/app/config.json b/app/config.json index 914f027..2c4e12c 100644 --- a/app/config.json +++ b/app/config.json @@ -46,7 +46,8 @@ "lightbox": { "showArrows": true, "showDownload": true, - "mobileArrows": false + "mobileArrows": false, + "autoPlayVideos": false } } } diff --git a/app/public/photoswipe-overrides.css b/app/public/photoswipe-overrides.css index cdce3e3..2136c2f 100644 --- a/app/public/photoswipe-overrides.css +++ b/app/public/photoswipe-overrides.css @@ -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; diff --git a/app/src/client/lightbox.ts b/app/src/client/lightbox.ts index a172f5f..4018d43 100644 --- a/app/src/client/lightbox.ts +++ b/app/src/client/lightbox.ts @@ -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') diff --git a/app/src/gallery/builder.ts b/app/src/gallery/builder.ts index 0c0169b..dff6b48 100644 --- a/app/src/gallery/builder.ts +++ b/app/src/gallery/builder.ts @@ -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: { diff --git a/app/src/shared/types.ts b/app/src/shared/types.ts index ca21da8..7ad9c97 100644 --- a/app/src/shared/types.ts +++ b/app/src/shared/types.ts @@ -60,6 +60,7 @@ export interface LightboxConfig { showArrows: boolean showDownload: boolean mobileArrows: boolean + autoPlayVideos: boolean options?: Record } diff --git a/docs/configuration.md b/docs/configuration.md index c5aa825..b1a246e 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -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`. | | `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. | +| `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}`). | 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. -| Option | Type | 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). | +| Option | Type | 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). | | `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. @@ -171,12 +172,12 @@ Under `ipp.showMetadata.exif`. Under `ipp.showMetadata.location`. -| Option | Type | Description | -|------------|--------|----------------------------------------------------------------------| -| `city` | `bool` | Show city. | -| `state` | `bool` | Show state / region. | -| `country` | `bool` | Show country. | -| `gps` | `bool` | Show GPS coordinates. | +| Option | Type | Description | +|------------|--------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| `city` | `bool` | Show city. | +| `state` | `bool` | Show state / region. | +| `country` | `bool` | Show country. | +| `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`. | 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: -| Legacy key | New key | -|---------------------------|-------------------------------| -| `ipp.singleImageGallery` | `ipp.gallery.singleImage` | -| `ipp.singleItemAutoOpen` | `ipp.gallery.singleItemAutoOpen` | -| `ipp.showGalleryTitle` | `ipp.gallery.showTitle` | -| `ipp.showGalleryDescription` | `ipp.gallery.showDescription` | -| `ipp.groupGalleryByDate` | `ipp.gallery.groupByDate` | +| Legacy key | New key | +|------------------------------|----------------------------------| +| `ipp.singleImageGallery` | `ipp.gallery.singleImage` | +| `ipp.singleItemAutoOpen` | `ipp.gallery.singleItemAutoOpen` | +| `ipp.showGalleryTitle` | `ipp.gallery.showTitle` | +| `ipp.showGalleryDescription` | `ipp.gallery.showDescription` | +| `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.