Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix: play Media Gen history video previews with sound on mobile

Adam Eivy92236dc673dd
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index 8e5fa35314..ba5ec77db2 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -20,3 +20,4 @@ TBD
- **Chief of Staff pane overflow** — content panel collapses to a single `flex-1 min-h-0 min-w-0 overflow-y-auto overflow-x-hidden` div so tall tab content scrolls inside the panel instead of expanding it. Event log rows in both `EventLog` and `TerminalCoSPanel` get `break-all` so long unbreakable tokens (URLs, hashes, paths) wrap inside the 320px sidebar instead of pushing the column wider visually.
- **Videos now load in the Media Gen preview on mobile.** Both the preview-modal (lightbox) `<video>` and the Video Gen page's inline result preview autoplayed unmuted, which iOS/Android block outside a direct user gesture — so the clip never started and the area showed only black ("not loading"). They now play `muted` (autoplay-eligible everywhere; controls let you unmute) and render the thumbnail as a `poster`, so the frame is visible immediately even while the clip buffers.
+- **Video previews now play with sound on mobile.** Opening a video from Media Gen history previously stayed silent because the muted-autoplay baseline (needed so the clip loads at all on iOS/Android) was never upgraded to audible. The lightbox now unmutes and re-plays on open — the opening tap's user activation lets iOS grant audible playback — and falls back to muted if the browser blocks it, so the clip always runs and the controls can unmute it manually.
diff --git a/client/src/components/media/MediaLightbox.jsx b/client/src/components/media/MediaLightbox.jsx
index d2fbe7af4e..f027d9c7b3 100644
--- a/client/src/components/media/MediaLightbox.jsx
+++ b/client/src/components/media/MediaLightbox.jsx
@@ -91,6 +91,27 @@ export default function MediaLightbox({
const starred = !!annotation?.starred;
const refs = useRef({ onClose, onPrevious, onNext, onAnnotationChange, starred });
useEffect(() => { refs.current = { onClose, onPrevious, onNext, onAnnotationChange, starred }; });
+ const videoRef = useRef(null);
+ // Play videos with SOUND on open. The declarative `muted autoPlay` baseline
+ // (on the <video> below) is what lets the clip start at all on mobile —
+ // iOS/Android block *unmuted* autoplay that isn't tied to a user gesture. But
+ // the lightbox is opened by a tap (history thumbnail / grid item), so the
+ // tap's transient user activation is usually still live when this effect runs.
+ // So we unmute and re-play here to upgrade the muted baseline to audible.
+ // If the browser rejects the unmuted play (activation expired / low
+ // media-engagement index), we fall back to muted playback so the clip still
+ // runs and the on-screen controls can unmute it manually.
+ useEffect(() => {
+ const v = videoRef.current;
+ if (!v || item?.kind !== 'video') return;
+ // Promise.resolve() normalizes both a real play() promise and the
+ // undefined some environments return, so the .catch chain is uniform.
+ v.muted = false;
+ Promise.resolve(v.play()).catch(() => {
+ v.muted = true;
+ Promise.resolve(v.play()).catch(() => {});
+ });
+ }, [item?.key, item?.kind]);
useEffect(() => {
if (!item) return;
const onKey = (e) => {
@@ -230,14 +251,17 @@ export default function MediaLightbox({
- playsInline keeps iOS Safari from auto-promoting autoplay video
to a native fullscreen player — exiting that leaves the modal
laid out as a tiny strip with no reachable close button.
- - muted is required for autoplay under the mobile media-engagement
+ - muted is the autoplay BASELINE under the mobile media-engagement
policy: iOS/Android block unmuted autoplay that isn't fired from
a direct user gesture, so without it the clip never starts and the
- area just shows black ("not loading"). Controls let the user unmute.
+ area just shows black ("not loading"). The effect above upgrades
+ this to audible playback when the opening tap's user activation
+ allows it; otherwise the controls let the user unmute manually.
- poster paints the thumbnail immediately so there's no blank box
while the clip buffers (and a visible frame even if playback is
deferred). previewUrl is the video's thumbnail; omit when absent. */
<video
+ ref={videoRef}
src={item.downloadUrl}
poster={item.previewUrl || undefined}
controls
diff --git a/client/src/components/media/MediaLightbox.test.jsx b/client/src/components/media/MediaLightbox.test.jsx
index 81c334ffec..2d62603259 100644
--- a/client/src/components/media/MediaLightbox.test.jsx
+++ b/client/src/components/media/MediaLightbox.test.jsx
@@ -1,5 +1,5 @@
-import { describe, it, expect, vi } from 'vitest';
-import { render } from '@testing-library/react';
+import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
+import { render, waitFor } from '@testing-library/react';
import MediaLightbox from './MediaLightbox';
// The footer's AddToCollectionMenu and the (closed) PromptRefineModal pull the
@@ -21,7 +21,18 @@ const videoItem = {
};
describe('MediaLightbox video element (mobile playback)', () => {
- it('renders the <video> with a poster + muted + playsInline so it loads/autoplays on mobile', () => {
+ // jsdom doesn't implement HTMLMediaElement.play; stub it per-test so we can
+ // drive the unmute-on-open effect down both the granted and blocked paths.
+ let playMock;
+ beforeEach(() => {
+ playMock = vi.fn(() => Promise.resolve());
+ HTMLMediaElement.prototype.play = playMock;
+ });
+ afterEach(() => {
+ delete HTMLMediaElement.prototype.play;
+ });
+
+ it('renders the <video> with a poster + playsInline + muted autoplay baseline so it loads on mobile', () => {
const { container } = render(<MediaLightbox item={videoItem} onClose={() => {}} />);
const video = container.querySelector('video');
expect(video).toBeTruthy();
@@ -30,14 +41,33 @@ describe('MediaLightbox video element (mobile playback)', () => {
// poster = thumbnail so a blank box never shows while the clip buffers,
// and the frame is visible even if mobile autoplay is deferred.
expect(video.getAttribute('poster')).toBe('/data/video-thumbnails/abc.jpg');
- // muted is required for autoplay under mobile media-engagement policy.
- expect(video.muted).toBe(true);
+ // muted autoplay is the baseline that lets the clip start under the mobile
+ // media-engagement policy; the effect then unmutes for sound.
+ expect(video.hasAttribute('autoplay')).toBe(true);
// playsInline keeps iOS from promoting to a native fullscreen player.
expect(video.hasAttribute('playsinline')).toBe(true);
expect(video.hasAttribute('loop')).toBe(true);
expect(video.hasAttribute('controls')).toBe(true);
});
+ it('unmutes and plays for sound when the opening gesture allows audible playback', async () => {
+ const { container } = render(<MediaLightbox item={videoItem} onClose={() => {}} />);
+ const video = container.querySelector('video');
+ await waitFor(() => expect(playMock).toHaveBeenCalled());
+ // play() resolved (gesture activation present) → stays unmuted for sound.
+ expect(video.muted).toBe(false);
+ });
+
+ it('falls back to muted playback when audible autoplay is blocked', async () => {
+ playMock.mockImplementation(() => Promise.reject(new Error('NotAllowedError')));
+ const { container } = render(<MediaLightbox item={videoItem} onClose={() => {}} />);
+ const video = container.querySelector('video');
+ // First (unmuted) play rejects → effect re-mutes and re-plays so the clip
+ // still runs; the user can unmute via the controls.
+ await waitFor(() => expect(video.muted).toBe(true));
+ expect(playMock.mock.calls.length).toBeGreaterThanOrEqual(2);
+ });
+
it('omits poster when the video has no thumbnail rather than rendering an empty poster', () => {
const { container } = render(
<MediaLightbox item={{ ...videoItem, previewUrl: null }} onClose={() => {}} />