Skip to content

Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.

fix(webv2): start preview videos at half volume and keep the viewer's setting

Lincoln Steinc9b16a3475d4
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewFrame.tsx b/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewFrame.tsx
index b0b52af7cb..3937e13d32 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewFrame.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewFrame.tsx
@@ -361,6 +361,18 @@ const PreviewImageFrame = ({
);
};
+/**
+ * The player remounts per item, so its audio settings live here for the page session: the first clip starts at half
+ * volume (the browser default of full volume is usually too loud) and later clips keep the viewer's last choice.
+ * A viewer preference, not account data, so it is deliberately not cleared on account changes.
+ */
+const previewVideoAudio = { muted: false, volume: 0.5 };
+
+const rememberPreviewVideoAudio = (event: SyntheticEvent<HTMLVideoElement>): void => {
+ previewVideoAudio.muted = event.currentTarget.muted;
+ previewVideoAudio.volume = event.currentTarget.volume;
+};
+
const PreviewVideo = ({
dragItem,
frameHeight,
@@ -439,6 +451,10 @@ const PreviewVideo = ({
const setVideoRef = useCallback(
(video: HTMLVideoElement | null) => {
videoRef.current = video;
+ if (video) {
+ video.muted = previewVideoAudio.muted;
+ video.volume = previewVideoAudio.volume;
+ }
onCopyAvailabilityChange?.(source.itemKey, isVideoFrameCopyAvailable(video));
},
[onCopyAvailabilityChange, source.itemKey]
@@ -898,6 +914,7 @@ const PreviewVideo = ({
onSeeked={publishCopyAvailability}
onSeeking={handleSpanSeeking}
onTimeUpdate={enforceSpan}
+ onVolumeChange={rememberPreviewVideoAudio}
onWaiting={publishCopyAvailability}
/>
{hasFailed ? (
diff --git a/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewFrameVideo.browser.test.tsx b/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewFrameVideo.browser.test.tsx
index a174645b8c..a32972cdb7 100644
--- a/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewFrameVideo.browser.test.tsx
+++ b/invokeai/frontend/webv2/src/workbench/widgets/preview/PreviewFrameVideo.browser.test.tsx
@@ -721,6 +721,31 @@ describe('PreviewFrame native video arm', () => {
expect(load).toHaveBeenCalledTimes(3);
});
+ it("starts at half volume and carries the viewer's volume to the next clip's player", async () => {
+ await renderVideo();
+ const firstVideo = getVideo();
+
+ expect(firstVideo.volume).toBe(0.5);
+ expect(firstVideo.muted).toBe(false);
+
+ await interact(() => {
+ firstVideo.volume = 0.2;
+ firstVideo.muted = true;
+ });
+ await renderVideo(() => true, { ...videoSource, itemKey: 'video:next.mp4' as const, label: 'Video next.mp4' });
+ const nextVideo = getVideo();
+
+ expect(nextVideo).not.toBe(firstVideo);
+ expect(nextVideo.volume).toBeCloseTo(0.2);
+ expect(nextVideo.muted).toBe(true);
+
+ // Restore the page-session default for the tests that follow.
+ await interact(() => {
+ nextVideo.volume = 0.5;
+ nextVideo.muted = false;
+ });
+ });
+
it('keys retry state to the selected video item', async () => {
await renderVideo();
const firstVideo = getVideo();