diff --git a/frontend/apps/artcraft-webapp/src/components/generation-gallery/CreateMediaPageShell.tsx b/frontend/apps/artcraft-webapp/src/components/generation-gallery/CreateMediaPageShell.tsx index dc036e78d2..4523591713 100644 --- a/frontend/apps/artcraft-webapp/src/components/generation-gallery/CreateMediaPageShell.tsx +++ b/frontend/apps/artcraft-webapp/src/components/generation-gallery/CreateMediaPageShell.tsx @@ -7,7 +7,7 @@ import { TabSelector } from "@storyteller/ui-tab-selector"; import { TruchetPattern } from "@storyteller/ui-vfx"; import Seo from "../../components/seo"; import { useIsMobile } from "../ui/use-mobile"; -import { GalleryViewToggle } from "./GalleryViewToggle"; +import { GalleryAutoplayToggle, GalleryViewToggle } from "./GalleryViewToggle"; import { MobileCreateTabsProvider, type MobileCreateTab, @@ -23,6 +23,9 @@ interface CreateMediaPageShellProps { authChecked: boolean; // Content hasContent: boolean; + // Video page only: playing/still toggle for video preview thumbnails, + // rendered next to the grid/list toggle on the mobile History tab. + showAutoplayToggle?: boolean; emptyStateTitle: string; emptyStateSubtitle: string; // Optional CTA rendered under the empty-state subtitle (e.g. a signup button @@ -54,6 +57,7 @@ export function CreateMediaPageShell({ description, authChecked, hasContent, + showAutoplayToggle = false, emptyStateTitle, emptyStateSubtitle, emptyStateCta, @@ -100,7 +104,8 @@ export function CreateMediaPageShell({ className="w-auto" /> {mobileTab === "history" && hasContent && ( -
+
+ {showAutoplayToggle && }
)} diff --git a/frontend/apps/artcraft-webapp/src/components/generation-gallery/GalleryViewToggle.tsx b/frontend/apps/artcraft-webapp/src/components/generation-gallery/GalleryViewToggle.tsx index 03cfe3b0ef..3f570e1182 100644 --- a/frontend/apps/artcraft-webapp/src/components/generation-gallery/GalleryViewToggle.tsx +++ b/frontend/apps/artcraft-webapp/src/components/generation-gallery/GalleryViewToggle.tsx @@ -1,2 +1,5 @@ // Moved to the shared generation-list lib (used by both webapp and desktop). -export { GalleryViewToggle } from "@storyteller/ui-generation-list"; +export { + GalleryViewToggle, + GalleryAutoplayToggle, +} from "@storyteller/ui-generation-list"; diff --git a/frontend/apps/artcraft-webapp/src/components/generation-gallery/index.ts b/frontend/apps/artcraft-webapp/src/components/generation-gallery/index.ts index 03739f07d3..6d4e0dbbee 100644 --- a/frontend/apps/artcraft-webapp/src/components/generation-gallery/index.ts +++ b/frontend/apps/artcraft-webapp/src/components/generation-gallery/index.ts @@ -1,7 +1,7 @@ export { GenerationGallery } from "./GenerationGallery"; export { GenerationGalleryGrid } from "./GenerationGalleryGrid"; export { GenerationGalleryList } from "./GenerationGalleryList"; -export { GalleryViewToggle } from "./GalleryViewToggle"; +export { GalleryViewToggle, GalleryAutoplayToggle } from "./GalleryViewToggle"; export { useGalleryData, type GalleryItem } from "./useGalleryData"; export { useSessionMediaByClass } from "@storyteller/ui-generation-list"; export { diff --git a/frontend/apps/artcraft-webapp/src/components/lightbox/lightbox.tsx b/frontend/apps/artcraft-webapp/src/components/lightbox/lightbox.tsx index 2fbc2cef19..e08445c017 100644 --- a/frontend/apps/artcraft-webapp/src/components/lightbox/lightbox.tsx +++ b/frontend/apps/artcraft-webapp/src/components/lightbox/lightbox.tsx @@ -32,6 +32,7 @@ import { applyMakeVideoFromImage, applyRecreateFromMediaToken, } from "../../lib/recreate"; +import { useLightboxSoundStore } from "../../lib/lightbox-sound-store"; // ── Types ────────────────────────────────────────────────────────────────── @@ -80,6 +81,7 @@ export function Lightbox({ showBatchCarousel = true, }: LightboxProps) { const navigate = useNavigate(); + const soundEnabled = useLightboxSoundStore((s) => s.soundEnabled); const [mediaLoaded, setMediaLoaded] = useState(false); const [promptData, setPromptData] = useState(EMPTY_PROMPT); const [creator, setCreator] = useState(null); @@ -379,7 +381,7 @@ export function Lightbox({ controls loop autoPlay - muted + muted={!soundEnabled} playsInline disablePictureInPicture controlsList="nodownload noplaybackrate nofullscreen" @@ -389,6 +391,22 @@ export function Lightbox({ const el = e.currentTarget; setMediaWidth(el.videoWidth); setMediaHeight(el.videoHeight); + // Restore the user's last volume (getState: subscribing + // would re-render on every tick of a volume drag). + el.volume = useLightboxSoundStore.getState().volume; + // If the browser blocked unmuted autoplay, fall back to + // muted playback rather than leaving the video frozen. + if (soundEnabled && el.paused) { + el.play().catch(() => { + el.muted = true; + el.play().catch(() => {}); + }); + } + }} + onVolumeChange={(e) => { + useLightboxSoundStore + .getState() + .setVolume(e.currentTarget.volume); }} ref={(el) => { if (el) { diff --git a/frontend/apps/artcraft-webapp/src/components/settings-modal/SettingsModal.tsx b/frontend/apps/artcraft-webapp/src/components/settings-modal/SettingsModal.tsx index 18bbe29dee..d4af621326 100644 --- a/frontend/apps/artcraft-webapp/src/components/settings-modal/SettingsModal.tsx +++ b/frontend/apps/artcraft-webapp/src/components/settings-modal/SettingsModal.tsx @@ -6,6 +6,7 @@ import { Switch } from "@storyteller/ui-switch"; import { USER_FEATURE_FLAGS } from "@storyteller/api"; import { twMerge } from "tailwind-merge"; import { useEnterToGenerateStore } from "../../lib/enter-to-generate-store"; +import { useLightboxSoundStore } from "../../lib/lightbox-sound-store"; import { useSession } from "../../lib/session"; import { AccountSection } from "./AccountSection"; import { ApiKeySection } from "./ApiKeySection"; @@ -105,6 +106,8 @@ export function SettingsModal({ isOpen, onClose }: SettingsModalProps) { function GeneralPanel() { const enterToGenerate = useEnterToGenerateStore((s) => s.enabled); const setEnterToGenerate = useEnterToGenerateStore((s) => s.setEnabled); + const lightboxSound = useLightboxSoundStore((s) => s.soundEnabled); + const setLightboxSound = useLightboxSoundStore((s) => s.setSoundEnabled); return (
@@ -123,6 +126,20 @@ function GeneralPanel() { offClassName="bg-white/20" />
+
+
+

Play videos with sound

+

+ When on, videos in the media viewer start unmuted so you don't have + to click unmute every time. When off (default), they start muted. +

+
+ +
); } diff --git a/frontend/apps/artcraft-webapp/src/components/topbar/topbar.tsx b/frontend/apps/artcraft-webapp/src/components/topbar/topbar.tsx index c6e9659984..cbb58ae341 100644 --- a/frontend/apps/artcraft-webapp/src/components/topbar/topbar.tsx +++ b/frontend/apps/artcraft-webapp/src/components/topbar/topbar.tsx @@ -1,6 +1,9 @@ import { Link, useLocation } from "react-router-dom"; import { SidebarTrigger, useSidebar } from "../ui/sidebar"; -import { GalleryViewToggle } from "../generation-gallery/GalleryViewToggle"; +import { + GalleryAutoplayToggle, + GalleryViewToggle, +} from "../generation-gallery/GalleryViewToggle"; import { Breadcrumbs } from "./breadcrumbs"; import { TopBarActions } from "./TopBarActions"; @@ -14,6 +17,8 @@ export function TopBar() { // On mobile the toggle lives next to the Generate/History tabs (see // CreateMediaPageShell), so keep it out of the top bar there. const showViewToggle = !isMobile && GALLERY_VIEW_ROUTES.has(pathname); + // Playing/still video previews only matter where the feed has videos. + const showAutoplayToggle = showViewToggle && pathname === "/create-video"; return (
@@ -41,6 +46,7 @@ export function TopBar() { {/* Right: gallery layout toggle (create pages) + credits / upgrade / task queue / avatar */}
+ {showAutoplayToggle && } {showViewToggle && }
diff --git a/frontend/apps/artcraft-webapp/src/lib/lightbox-sound-store.ts b/frontend/apps/artcraft-webapp/src/lib/lightbox-sound-store.ts new file mode 100644 index 0000000000..801fa27f7d --- /dev/null +++ b/frontend/apps/artcraft-webapp/src/lib/lightbox-sound-store.ts @@ -0,0 +1,26 @@ +import { create } from "zustand"; +import { persist } from "zustand/middleware"; + +// Audio behavior for lightbox videos: whether they open with sound (off by +// default, toggled in the settings modal's General tab) and the last volume +// the user picked, so each video doesn't reset to 100%. + +interface LightboxSoundStore { + soundEnabled: boolean; + setSoundEnabled: (enabled: boolean) => void; + // 0..1, mirrors HTMLMediaElement.volume. + volume: number; + setVolume: (volume: number) => void; +} + +export const useLightboxSoundStore = create()( + persist( + (set) => ({ + soundEnabled: false, + setSoundEnabled: (soundEnabled) => set({ soundEnabled }), + volume: 1, + setVolume: (volume) => set({ volume }), + }), + { name: "artcraft-lightbox-sound" }, + ), +); diff --git a/frontend/apps/artcraft-webapp/src/pages/create-video/create-video.tsx b/frontend/apps/artcraft-webapp/src/pages/create-video/create-video.tsx index bb1acd232a..aebca86e25 100644 --- a/frontend/apps/artcraft-webapp/src/pages/create-video/create-video.tsx +++ b/frontend/apps/artcraft-webapp/src/pages/create-video/create-video.tsx @@ -1454,6 +1454,7 @@ export default function CreateVideo() { description="Generate stunning AI videos with ArtCraft" authChecked={authChecked} hasContent={hasContent} + showAutoplayToggle emptyStateTitle="Create Video" emptyStateSubtitle="Describe a scene. See it in motion." emptyStateCta={ diff --git a/frontend/apps/artcraft/app/src/components/generation-feed/useDesktopGenerationFeed.ts b/frontend/apps/artcraft/app/src/components/generation-feed/useDesktopGenerationFeed.ts index 50c86897eb..96d88a6069 100644 --- a/frontend/apps/artcraft/app/src/components/generation-feed/useDesktopGenerationFeed.ts +++ b/frontend/apps/artcraft/app/src/components/generation-feed/useDesktopGenerationFeed.ts @@ -8,6 +8,7 @@ import { } from "@storyteller/tauri-events"; import { MediaFilesApi } from "@storyteller/api"; import { + getMediaStillThumbnail, getMediaThumbnail, getThumbnailUrl, THUMBNAIL_SIZES, @@ -410,6 +411,12 @@ async function taskToGalleryItems( id: batchFile.token, label, thumbnail: thumbnail || cdnUrl, + stillThumbnail: + mediaType === "video" + ? getMediaStillThumbnail(batchFile.media_links, { + size: THUMBNAIL_SIZES.LARGE, + }) + : null, fullImage: cdnUrl, createdAt, mediaClass: mediaType, diff --git a/frontend/apps/artcraft/app/src/components/signaled/TopBar/TopBar.tsx b/frontend/apps/artcraft/app/src/components/signaled/TopBar/TopBar.tsx index 8dcb5ecc32..f35af8e282 100644 --- a/frontend/apps/artcraft/app/src/components/signaled/TopBar/TopBar.tsx +++ b/frontend/apps/artcraft/app/src/components/signaled/TopBar/TopBar.tsx @@ -8,7 +8,6 @@ import { faCoins, faGear, faGem, - faGrid2, faHouse, faImages, faCalculator, @@ -51,7 +50,10 @@ import { useCostBreakdownModalStore, CreditsModal, } from "@storyteller/ui-pricing-modal"; -import { GalleryViewToggle } from "@storyteller/ui-generation-list"; +import { + GalleryAutoplayToggle, + GalleryViewToggle, +} from "@storyteller/ui-generation-list"; import { SettingsModal } from "@storyteller/ui-settings-modal"; import { Tooltip } from "@storyteller/ui-tooltip"; import { useEffect, useRef, useState } from "react"; @@ -500,6 +502,7 @@ export const TopBar = ({ pageName }: Props) => {
+ {tabStore.activeTabId === "VIDEO" && } {(tabStore.activeTabId === "IMAGE" || tabStore.activeTabId === "VIDEO" || tabStore.activeTabId === "AUDIO") && } diff --git a/frontend/libs/common/src/lib/utils/thumbnail-utils.ts b/frontend/libs/common/src/lib/utils/thumbnail-utils.ts index 774c647b00..95b21d2384 100644 --- a/frontend/libs/common/src/lib/utils/thumbnail-utils.ts +++ b/frontend/libs/common/src/lib/utils/thumbnail-utils.ts @@ -84,6 +84,41 @@ export function getMediaThumbnail( return thumbnailUrl; } +// Still-frame thumbnail for a video (first frame), for hosts that let the +// user turn off animated previews. Falls back to the regular thumbnail +// template when the backend hasn't attached still previews. +export function getMediaStillThumbnail( + mediaLinks: + | { + maybe_thumbnail_template?: string | null; + maybe_video_previews?: { + still?: string | null; + still_thumbnail_template?: string | null; + } | null; + } + | null + | undefined, + options: MediaThumbnailOptions = {}, +): string | null { + if (!mediaLinks) return null; + + const { size = THUMBNAIL_SIZES.MEDIUM } = options; + const previews = mediaLinks.maybe_video_previews; + + if (previews?.still_thumbnail_template) { + return getThumbnailUrl(previews.still_thumbnail_template, { width: size }); + } + if (previews?.still) { + return previews.still; + } + if (mediaLinks.maybe_thumbnail_template) { + return getThumbnailUrl(mediaLinks.maybe_thumbnail_template, { + width: size, + }); + } + return null; +} + export function getContextImageThumbnail( contextImage: { media_links: { diff --git a/frontend/libs/components/generation-list/src/index.ts b/frontend/libs/components/generation-list/src/index.ts index 448224d40d..4a7bca1fd1 100644 --- a/frontend/libs/components/generation-list/src/index.ts +++ b/frontend/libs/components/generation-list/src/index.ts @@ -5,6 +5,7 @@ export * from "./lib/prompts-cache"; export * from "./lib/media-prompt-token-cache"; export * from "./lib/gallery-view-store"; export * from "./lib/GalleryViewToggle"; +export * from "./lib/GalleryAutoplayToggle"; export * from "./lib/useGalleryData"; export * from "./lib/useSessionMediaByClass"; export * from "./lib/useGalleryEntries"; diff --git a/frontend/libs/components/generation-list/src/lib/GalleryAutoplayToggle.tsx b/frontend/libs/components/generation-list/src/lib/GalleryAutoplayToggle.tsx new file mode 100644 index 0000000000..d3d792e8ff --- /dev/null +++ b/frontend/libs/components/generation-list/src/lib/GalleryAutoplayToggle.tsx @@ -0,0 +1,51 @@ +import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; +import { faPause, faPlay } from "@fortawesome/pro-solid-svg-icons"; +import type { IconDefinition } from "@fortawesome/fontawesome-svg-core"; +import { Tooltip } from "@storyteller/ui-tooltip"; +import { useGalleryViewStore } from "./gallery-view-store"; + +const OPTIONS: { + autoplay: boolean; + icon: IconDefinition; + label: string; +}[] = [ + { autoplay: true, icon: faPlay, label: "Play video previews" }, + { autoplay: false, icon: faPause, label: "Still thumbnails" }, +]; + +// Segmented playing/still switch for video preview thumbnails. Sits next to +// GalleryViewToggle on the video page; the selection is shared with the +// gallery via useGalleryViewStore. +export function GalleryAutoplayToggle() { + const autoplayVideos = useGalleryViewStore((s) => s.autoplayVideos); + const setAutoplayVideos = useGalleryViewStore((s) => s.setAutoplayVideos); + + return ( +
+ {OPTIONS.map(({ autoplay, icon, label }) => { + const active = autoplayVideos === autoplay; + return ( + + + + ); + })} +
+ ); +} diff --git a/frontend/libs/components/generation-list/src/lib/GalleryCard.tsx b/frontend/libs/components/generation-list/src/lib/GalleryCard.tsx index 7945ac7fe2..d1cb1ff853 100644 --- a/frontend/libs/components/generation-list/src/lib/GalleryCard.tsx +++ b/frontend/libs/components/generation-list/src/lib/GalleryCard.tsx @@ -185,6 +185,7 @@ export const GalleryCard = memo(function GalleryCard({ ) : ( s.autoplayVideos); + // With autoplay off, videos freeze on their still first frame. The still is + // also what the retry machinery below polls in that mode. + const thumbnail = + isVideo && !autoplayVideos && stillThumbnail + ? stillThumbnail + : animatedThumbnail; // "retrying" flips to true only after the first error, so videos with ready // thumbnails render the normal path with zero overhead. While retrying, // a hidden loads via ref (no re-renders) and the spinner stays stable. diff --git a/frontend/libs/components/generation-list/src/lib/gallery-view-store.ts b/frontend/libs/components/generation-list/src/lib/gallery-view-store.ts index ae8cfc5c4b..b8191cdd39 100644 --- a/frontend/libs/components/generation-list/src/lib/gallery-view-store.ts +++ b/frontend/libs/components/generation-list/src/lib/gallery-view-store.ts @@ -10,6 +10,10 @@ export type GalleryViewMode = "grid" | "list"; interface GalleryViewState { viewMode: GalleryViewMode; setViewMode: (mode: GalleryViewMode) => void; + // Whether video cards play their animated previews. When off, they show the + // still first-frame thumbnail instead (toggled from the video page TopBar). + autoplayVideos: boolean; + setAutoplayVideos: (autoplay: boolean) => void; } export const useGalleryViewStore = create()( @@ -17,6 +21,8 @@ export const useGalleryViewStore = create()( (set) => ({ viewMode: "grid", setViewMode: (viewMode) => set({ viewMode }), + autoplayVideos: true, + setAutoplayVideos: (autoplayVideos) => set({ autoplayVideos }), }), { name: "artcraft-gallery-view" }, ), diff --git a/frontend/libs/components/generation-list/src/lib/types.ts b/frontend/libs/components/generation-list/src/lib/types.ts index 893b161fae..dea2117e0f 100644 --- a/frontend/libs/components/generation-list/src/lib/types.ts +++ b/frontend/libs/components/generation-list/src/lib/types.ts @@ -42,6 +42,9 @@ export interface GalleryItem { id: string; label: string; thumbnail: string | null; + // Still first-frame thumbnail for videos, shown when the user turns off + // animated previews (thumbnail holds the animated one). + stillThumbnail?: string | null; fullImage: string | null; createdAt: string; mediaClass: string; diff --git a/frontend/libs/components/generation-list/src/lib/useGalleryData.ts b/frontend/libs/components/generation-list/src/lib/useGalleryData.ts index 7f2d797056..ce0e2d6e60 100644 --- a/frontend/libs/components/generation-list/src/lib/useGalleryData.ts +++ b/frontend/libs/components/generation-list/src/lib/useGalleryData.ts @@ -4,7 +4,11 @@ import { FilterMediaClasses, FilterMediaType, } from "@storyteller/api"; -import { getMediaThumbnail, THUMBNAIL_SIZES } from "@storyteller/common"; +import { + getMediaStillThumbnail, + getMediaThumbnail, + THUMBNAIL_SIZES, +} from "@storyteller/common"; import type { GalleryItem } from "./types"; import { is3DMediaClass } from "./types"; @@ -83,6 +87,12 @@ export function useGalleryData(options: { id: item.token, label: getLabel(item), thumbnail, + stillThumbnail: + item.media_class === "video" + ? getMediaStillThumbnail(item.media_links, { + size: THUMBNAIL_SIZES.LARGE, + }) + : null, fullImage: item.media_links?.cdn_url || null, createdAt: item.created_at, mediaClass: item.media_class || "image", diff --git a/frontend/libs/components/generation-list/src/lib/useGenerationJobs.ts b/frontend/libs/components/generation-list/src/lib/useGenerationJobs.ts index 0e893dbbf0..f9fabc9c21 100644 --- a/frontend/libs/components/generation-list/src/lib/useGenerationJobs.ts +++ b/frontend/libs/components/generation-list/src/lib/useGenerationJobs.ts @@ -1,7 +1,11 @@ import { useCallback, useEffect, useMemo, useRef, useState } from "react"; import { JobsApi, JobStatus, MediaFilesApi } from "@storyteller/api"; import type { Job, Prompts } from "@storyteller/api"; -import { getMediaThumbnail, THUMBNAIL_SIZES } from "@storyteller/common"; +import { + getMediaStillThumbnail, + getMediaThumbnail, + THUMBNAIL_SIZES, +} from "@storyteller/common"; import { getModelDisplayName, getProviderDisplayName, @@ -252,6 +256,12 @@ function jobToGalleryItem( id: result.entity_token, label: getPrompt(job, promptsMap) || "Generation", thumbnail, + stillThumbnail: + mediaClass === "video" + ? getMediaStillThumbnail(result.media_links, { + size: THUMBNAIL_SIZES.LARGE, + }) + : null, fullImage: result.media_links?.cdn_url || null, // Sort by job creation time (not completion time) so the completed card // occupies the same Masonry slot the pending card held — no layout shift. @@ -294,6 +304,12 @@ async function expandBatchItems( id: file.token, label: item.label, thumbnail, + stillThumbnail: + item.mediaClass === "video" + ? getMediaStillThumbnail(file.media_links, { + size: THUMBNAIL_SIZES.LARGE, + }) + : null, fullImage: cdnUrl, createdAt: item.createdAt, mediaClass: item.mediaClass,