import * as React from 'react'; import {augmentVideoFile, getMimeTypeDescription} from 'packages/web-kitchensink-reactnext/src/utils/blob'; import {formatFileSize, formatNumeral, formatSecondsDurationConcise} from 'packages/web-kitchensink-reactnext/src/utils/numeral'; import {useFileMetadata, useFileUrl, useMediaControls} from 'src/index'; import clsx from 'clsx'; import {Slider} from 'categories/number/react'; import {KeyValueTable} from 'categories/information/react'; import {useClientSide} from 'packages/react-utils'; import type {CommonPreviewProps} from '../../../../../categories/blob/react/src/components/FileSelectBox'; export type VideoFilePreviewDerivedComponent = HTMLVideoElement; export interface VideoFilePreviewProps = Partial> extends Omit, 'controls'>, CommonPreviewProps {} export const VideoFilePreview = React.forwardRef(({ file, className, style, disabled = false, enhanced: enhancedProp = false, ...etcProps }, forwardedRef) => { const { fileWithUrl } = useFileUrl({ file }); const { fileWithMetadata, error } = useFileMetadata({ file: fileWithUrl, augmentFunction: augmentVideoFile, }); const { seekRef, volumeRef, isPlaying, adjustVolume, reset, startSeek, endSeek, setSeek, updateSeekFromPlayback, refreshControls, durationDisplay = 0, currentTimeDisplay = 0, seekTimeDisplay = 0, isSeeking, isSeekTimeCountingDown, mediaControllerRef, handleAction, filenameRef, formId, } = useMediaControls({ controllerRef: forwardedRef, }); const { clientSide } = useClientSide({ clientSide: enhancedProp }); if (!fileWithMetadata) { return null; } const finalSeekTimeDisplay = isSeekTimeCountingDown ? (durationDisplay - seekTimeDisplay) : seekTimeDisplay; const finalCurrentTimeDisplay = isSeekTimeCountingDown ? (durationDisplay - currentTimeDisplay) : currentTimeDisplay; return (
{ typeof fileWithMetadata.url === 'string' && (
{clientSide && (
{formatSecondsDurationConcise(durationDisplay)}
)}
) }
{ clientSide && (
Controls
) }
); }); VideoFilePreview.displayName = 'VideoFilePreview';