mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-26 10:55:27 +00:00
feat(transcode): add audio file support with AAC stereo mp4 proxy and styled viewer
This commit is contained in:
@@ -34,6 +34,7 @@ interface BreadcrumbNavProps {
|
||||
name?: string
|
||||
type: 'file' | 'folder'
|
||||
version?: number
|
||||
mediaType?: string | null
|
||||
}
|
||||
isRootFolder: boolean
|
||||
displayStyle?: 'card' | 'list'
|
||||
@@ -135,8 +136,11 @@ export function BreadcrumbNav({
|
||||
}
|
||||
}
|
||||
|
||||
const isAudio = currentAsset.mediaType?.startsWith('audio/')
|
||||
const hasVideoTranscodes =
|
||||
downloadInfo?.videoTranscodes && downloadInfo.videoTranscodes.filter((t) => !t.isRaw).length > 0
|
||||
!isAudio &&
|
||||
downloadInfo?.videoTranscodes &&
|
||||
downloadInfo.videoTranscodes.filter((t) => !t.isRaw).length > 0
|
||||
|
||||
const breadcrumbs: { name: string; path?: string; id?: string; isMuted?: boolean }[] = isPublic
|
||||
? [
|
||||
|
||||
@@ -3,7 +3,7 @@ import { client } from '@/ui/api/client'
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
|
||||
import { useDraggable } from '@dnd-kit/react'
|
||||
import { File, Folder, MoreVertical } from 'lucide-react'
|
||||
import { File, Folder, MoreVertical, AudioLines } from 'lucide-react'
|
||||
import React, { useEffect, useMemo, useRef, useState } from 'react'
|
||||
import { cn } from '@/ui/lib/utils'
|
||||
import type { DragState } from '../dnd-types'
|
||||
@@ -214,6 +214,9 @@ export function FileListItem({
|
||||
alt=""
|
||||
className="w-full h-full object-cover"
|
||||
/>
|
||||
) : displayItem.preview?.mediaType?.startsWith('audio/') ||
|
||||
displayItem.mediaType?.startsWith('audio/') ? (
|
||||
<AudioLines className="h-4 w-4 text-muted-foreground" />
|
||||
) : displayItem.type === 'folder' ? (
|
||||
<Folder className="h-4 w-4 text-primary" />
|
||||
) : (
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { File, Folder } from 'lucide-react'
|
||||
import { File, Folder, AudioLines } from 'lucide-react'
|
||||
import { SpriteScrubber } from '../sprite-scrubber'
|
||||
import { formatTime } from '../viewers/video/utils'
|
||||
|
||||
@@ -63,6 +63,15 @@ export const FilePreview = ({ item, showDuration = false }: FilePreviewProps) =>
|
||||
)
|
||||
}
|
||||
|
||||
const isAudio = item.preview?.mediaType?.startsWith('audio/')
|
||||
if (isAudio) {
|
||||
return (
|
||||
<div className="w-full h-full flex items-center justify-center bg-muted">
|
||||
<AudioLines className="w-8 h-8 text-muted-foreground" />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// Assumption: folders in latestChildren have no media type.
|
||||
if (!item.type) {
|
||||
return (
|
||||
|
||||
@@ -2,7 +2,7 @@ import { client } from '@/ui/api/client'
|
||||
import { cn } from '@/ui/lib/utils'
|
||||
import type { AssetInfo, AssetInfoPaginatedList } from '@shumai/dtos'
|
||||
import { Link } from '@tanstack/react-router'
|
||||
import { File, Loader2 } from 'lucide-react'
|
||||
import { File, Loader2, AudioLines } from 'lucide-react'
|
||||
import type { FC } from 'react'
|
||||
import { useEffect, useRef, useState } from 'react'
|
||||
import { useInView } from 'react-intersection-observer'
|
||||
@@ -22,6 +22,16 @@ export const CarouselFilePreview = ({ item }: { item: AssetInfo }) => {
|
||||
)
|
||||
}
|
||||
|
||||
const isAudio =
|
||||
item.preview?.mediaType?.startsWith('audio/') || item.mediaType?.startsWith('audio/')
|
||||
if (isAudio) {
|
||||
return (
|
||||
<div className="w-full h-full flex items-center justify-center bg-muted">
|
||||
<AudioLines className="w-5 h-5 text-muted-foreground" />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="w-full h-full flex items-center justify-center bg-muted">
|
||||
<File className="w-5 h-5 text-muted-foreground" />
|
||||
|
||||
@@ -412,6 +412,7 @@ export function PublicShareManager({
|
||||
? (stackFileData.versionStack.versions.find((v) => v.id === activeFileId)?.version ??
|
||||
stackFileData.versionStack.versions.length)
|
||||
: undefined,
|
||||
mediaType: viewingFileData?.mediaType || null,
|
||||
},
|
||||
isRootFolder: currentFolderId === shareInfo.rootFolderId && !viewingFileId,
|
||||
isPublic: true,
|
||||
|
||||
@@ -4,7 +4,7 @@ import { cn } from '@/ui/lib/utils'
|
||||
import { useAnnotationStore } from '@/ui/stores/annotation-store'
|
||||
import type { Annotation } from '@/ui/types'
|
||||
import type { AssetInfo } from '@shumai/dtos'
|
||||
import { Play } from 'lucide-react'
|
||||
import { Play, AudioLines } from 'lucide-react'
|
||||
import { forwardRef, useCallback, useEffect, useImperativeHandle, useRef, useState } from 'react'
|
||||
import videojs from 'video.js'
|
||||
import type Player from 'video.js/dist/types/player'
|
||||
@@ -138,8 +138,8 @@ export const CompareVideoPane = forwardRef<ComparePaneHandle, CompareVideoPanePr
|
||||
return () => observer.disconnect()
|
||||
}, [])
|
||||
|
||||
const vidW = metadata?.originalWidth ?? 1920
|
||||
const vidH = metadata?.originalHeight ?? 1080
|
||||
const vidW = metadata?.originalWidth || 1920
|
||||
const vidH = metadata?.originalHeight || 1080
|
||||
|
||||
// Auto-fit zoom
|
||||
useEffect(() => {
|
||||
@@ -439,22 +439,34 @@ export const CompareVideoPane = forwardRef<ComparePaneHandle, CompareVideoPanePr
|
||||
>
|
||||
<div ref={videoContainerRef} className="absolute inset-0 z-[-1]" />
|
||||
|
||||
{videoHtmlEl && containerSize.width > 0 && (
|
||||
<DrawingCanvas
|
||||
width={containerSize.width}
|
||||
height={containerSize.height}
|
||||
mediaDimensions={{ width: vidW, height: vidH }}
|
||||
videoElement={videoHtmlEl}
|
||||
annotations={displayAnnotations}
|
||||
scale={scale}
|
||||
offset={{ x: panX, y: panY }}
|
||||
className="absolute inset-0"
|
||||
onClick={handleAreaClick}
|
||||
isDrawing={isActive && isDrawing}
|
||||
currentTool={currentTool}
|
||||
currentColor={currentColor}
|
||||
onAddAnnotation={isActive ? addAnnotation : undefined}
|
||||
/>
|
||||
{file.mediaType?.startsWith('audio/') ? (
|
||||
<div className="flex flex-col items-center justify-center text-muted-foreground w-full h-full pointer-events-none select-none">
|
||||
<AudioLines
|
||||
className={cn(
|
||||
'w-16 h-16 text-foreground/75 transition-transform duration-500',
|
||||
isPlaying ? 'animate-pulse scale-110 text-primary' : '',
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
) : (
|
||||
videoHtmlEl &&
|
||||
containerSize.width > 0 && (
|
||||
<DrawingCanvas
|
||||
width={containerSize.width}
|
||||
height={containerSize.height}
|
||||
mediaDimensions={{ width: vidW, height: vidH }}
|
||||
videoElement={videoHtmlEl}
|
||||
annotations={displayAnnotations}
|
||||
scale={scale}
|
||||
offset={{ x: panX, y: panY }}
|
||||
className="absolute inset-0"
|
||||
onClick={handleAreaClick}
|
||||
isDrawing={isActive && isDrawing}
|
||||
currentTool={currentTool}
|
||||
currentColor={currentColor}
|
||||
onAddAnnotation={isActive ? addAnnotation : undefined}
|
||||
/>
|
||||
)
|
||||
)}
|
||||
|
||||
{!isPlaying && !isDrawing && (
|
||||
|
||||
@@ -5,7 +5,7 @@ import { CompareVideoPane } from './compare-video-pane'
|
||||
export const videoTypeDefinition: FileTypeDefinition = {
|
||||
id: 'video',
|
||||
name: 'Video',
|
||||
match: (file) => !!file.mediaType?.startsWith('video/'),
|
||||
match: (file) => !!file.mediaType?.startsWith('video/') || !!file.mediaType?.startsWith('audio/'),
|
||||
viewer: VideoViewer,
|
||||
comparePane: CompareVideoPane,
|
||||
commentsConfig: {
|
||||
|
||||
@@ -113,6 +113,7 @@ export const VideoControlBar: React.FC<ControlBarProps> = ({
|
||||
// fullscreen). Compare keeps it in-flow. Colors stay theme-aware either way.
|
||||
const overlay = state.isFullScreen && floatOverlayInFullScreen
|
||||
|
||||
const isAudio = data.mediaType?.startsWith('audio/')
|
||||
const previewResolutions = resolutions.filter((r) => !r.isRaw)
|
||||
|
||||
const startTimecode = data.media?.metadata?.startTimecode
|
||||
@@ -304,60 +305,73 @@ export const VideoControlBar: React.FC<ControlBarProps> = ({
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
|
||||
{/* Resolution Selector */}
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<button className="flex items-center gap-1 rounded border border-border px-2 py-0.5 text-sm font-semibold hover:bg-muted transition-colors">
|
||||
<Settings className="h-3.5 w-3.5" />
|
||||
<span>{state.currentResolution}</span>
|
||||
</button>
|
||||
</DropdownMenuTrigger>
|
||||
{/* Settings / Resolution */}
|
||||
{!isAudio && previewResolutions.length > 0 && (
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<button className="flex items-center gap-1 rounded border border-border px-2 py-0.5 text-sm font-semibold hover:bg-muted transition-colors">
|
||||
<Settings className="h-3.5 w-3.5" />
|
||||
<span>{state.currentResolution}</span>
|
||||
</button>
|
||||
</DropdownMenuTrigger>
|
||||
|
||||
<DropdownMenuContent>
|
||||
<DropdownMenuLabel>Quality</DropdownMenuLabel>
|
||||
{previewResolutions.map((res) => (
|
||||
<DropdownMenuItem
|
||||
key={res.resolution}
|
||||
onClick={() => changeResolution(res)}
|
||||
className={cn(
|
||||
'flex w-full items-center justify-between',
|
||||
state.currentResolution === res.resolution
|
||||
? 'text-primary font-medium'
|
||||
: 'text-foreground',
|
||||
)}
|
||||
>
|
||||
<span>{res.resolution}</span>
|
||||
<span className="pl-5 text-xs text-muted-foreground">
|
||||
{res.width}x{res.height}
|
||||
</span>
|
||||
</DropdownMenuItem>
|
||||
))}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
<DropdownMenuContent>
|
||||
<DropdownMenuLabel>Quality</DropdownMenuLabel>
|
||||
{previewResolutions.map((res) => (
|
||||
<DropdownMenuItem
|
||||
key={res.resolution}
|
||||
onClick={() => changeResolution(res)}
|
||||
className={cn(
|
||||
'flex w-full items-center justify-between',
|
||||
state.currentResolution === res.resolution
|
||||
? 'text-primary font-medium'
|
||||
: 'text-foreground',
|
||||
)}
|
||||
>
|
||||
<span>{res.resolution}</span>
|
||||
<span className="pl-5 text-xs text-muted-foreground">
|
||||
{res.width}x{res.height}
|
||||
</span>
|
||||
</DropdownMenuItem>
|
||||
))}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
)}
|
||||
|
||||
{/* Download */}
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<button className="transition-colors hover:text-primary" title="Download">
|
||||
<Download className="h-5 w-5" />
|
||||
</button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent>
|
||||
<DropdownMenuLabel>Download</DropdownMenuLabel>
|
||||
{resolutions.map((res) => (
|
||||
<DropdownMenuItem
|
||||
key={res.resolution}
|
||||
onClick={() => handleDownload(res.key ?? '')}
|
||||
className="flex w-full items-center justify-between px-3 py-2 text-left text-sm text-foreground"
|
||||
>
|
||||
<span>{res.resolution}</span>
|
||||
<span className="text-xs text-muted-foreground">
|
||||
{res.isRaw ? data.name?.split('.').pop()?.toUpperCase() || 'RAW' : 'MP4'}
|
||||
</span>
|
||||
</DropdownMenuItem>
|
||||
))}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
{isAudio ? (
|
||||
<button
|
||||
onClick={() => handleDownload(data.media?.original?.key || '')}
|
||||
className="transition-colors hover:text-primary"
|
||||
title="Download"
|
||||
disabled={!data.media?.original?.key}
|
||||
>
|
||||
<Download className="h-5 w-5" />
|
||||
</button>
|
||||
) : (
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<button className="transition-colors hover:text-primary" title="Download">
|
||||
<Download className="h-5 w-5" />
|
||||
</button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent>
|
||||
<DropdownMenuLabel>Download</DropdownMenuLabel>
|
||||
{resolutions.map((res) => (
|
||||
<DropdownMenuItem
|
||||
key={res.resolution}
|
||||
onClick={() => handleDownload(res.key ?? '')}
|
||||
className="flex w-full items-center justify-between px-3 py-2 text-left text-sm text-foreground"
|
||||
>
|
||||
<span>{res.resolution}</span>
|
||||
<span className="text-xs text-muted-foreground">
|
||||
{res.isRaw ? data.name?.split('.').pop()?.toUpperCase() || 'RAW' : 'MP4'}
|
||||
</span>
|
||||
</DropdownMenuItem>
|
||||
))}
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
)}
|
||||
|
||||
{/* Fullscreen */}
|
||||
<button onClick={toggleFullScreen} className="transition-colors hover:text-primary">
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { client } from '@/ui/api/client'
|
||||
import { cn } from '@/ui/lib/utils'
|
||||
import { Play } from 'lucide-react'
|
||||
import { Play, AudioLines } from 'lucide-react'
|
||||
import React, { useCallback, useEffect, useRef, useState, useImperativeHandle } from 'react'
|
||||
import videojs from 'video.js'
|
||||
import type Player from 'video.js/dist/types/player'
|
||||
@@ -96,8 +96,8 @@ const VideoViewer = React.forwardRef<MediaController, FileViewerProps>(
|
||||
// Fit to screen initial / responsive resize
|
||||
useEffect(() => {
|
||||
if (containerSize.width > 0 && containerSize.height > 0) {
|
||||
const vidW = data.media?.metadata?.originalWidth ?? 1920
|
||||
const vidH = data.media?.metadata?.originalHeight ?? 1080
|
||||
const vidW = data.media?.metadata?.originalWidth || 1920
|
||||
const vidH = data.media?.metadata?.originalHeight || 1080
|
||||
const scale = Math.min(containerSize.width / vidW, containerSize.height / vidH)
|
||||
if (!hasManuallyZoomed) {
|
||||
setZoom(scale)
|
||||
@@ -541,8 +541,8 @@ const VideoViewer = React.forwardRef<MediaController, FileViewerProps>(
|
||||
}, [])
|
||||
|
||||
// Calculate center pan
|
||||
const vidW = data.media?.metadata?.originalWidth ?? 1920
|
||||
const vidH = data.media?.metadata?.originalHeight ?? 1080
|
||||
const vidW = data.media?.metadata?.originalWidth || 1920
|
||||
const vidH = data.media?.metadata?.originalHeight || 1080
|
||||
|
||||
const scale = zoom
|
||||
const panX = (containerSize.width - vidW * scale) / 2
|
||||
@@ -584,27 +584,39 @@ const VideoViewer = React.forwardRef<MediaController, FileViewerProps>(
|
||||
{/* Hidden VideoJS container */}
|
||||
<div ref={videoContainerRef} className="absolute inset-0 z-[-1]" />
|
||||
|
||||
{/* Drawing Canvas (Visible) */}
|
||||
{videoHtmlEl && containerSize.width > 0 && (
|
||||
<DrawingCanvas
|
||||
width={containerSize.width}
|
||||
height={containerSize.height}
|
||||
mediaDimensions={{
|
||||
width: vidW,
|
||||
height: vidH,
|
||||
}}
|
||||
videoElement={videoHtmlEl}
|
||||
annotations={displayAnnotations}
|
||||
scale={scale}
|
||||
offset={{ x: panX, y: panY }}
|
||||
className="absolute inset-0"
|
||||
onClick={togglePlay}
|
||||
// Drawing Props
|
||||
isDrawing={isDrawing}
|
||||
currentTool={currentTool}
|
||||
currentColor={currentColor}
|
||||
onAddAnnotation={addAnnotation}
|
||||
/>
|
||||
{data.mediaType?.startsWith('audio/') ? (
|
||||
<div className="flex flex-col items-center justify-center text-muted-foreground w-full h-full pointer-events-none select-none">
|
||||
<AudioLines
|
||||
className={cn(
|
||||
'w-16 h-16 text-foreground/75 transition-transform duration-500',
|
||||
state.isPlaying ? 'animate-pulse scale-110 text-primary' : '',
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
) : (
|
||||
/* Drawing Canvas (Visible) */
|
||||
videoHtmlEl &&
|
||||
containerSize.width > 0 && (
|
||||
<DrawingCanvas
|
||||
width={containerSize.width}
|
||||
height={containerSize.height}
|
||||
mediaDimensions={{
|
||||
width: vidW,
|
||||
height: vidH,
|
||||
}}
|
||||
videoElement={videoHtmlEl}
|
||||
annotations={displayAnnotations}
|
||||
scale={scale}
|
||||
offset={{ x: panX, y: panY }}
|
||||
className="absolute inset-0"
|
||||
onClick={togglePlay}
|
||||
// Drawing Props
|
||||
isDrawing={isDrawing}
|
||||
currentTool={currentTool}
|
||||
currentColor={currentColor}
|
||||
onAddAnnotation={addAnnotation}
|
||||
/>
|
||||
)
|
||||
)}
|
||||
|
||||
{/* Big Play Button Overlay (when paused) */}
|
||||
|
||||
Reference in New Issue
Block a user