@@ -16,6 +16,7 @@ import { useShortcuts } from "@/contexts/ShortcutsContext";
1616import { INITIAL_EDITOR_STATE , useEditorHistory } from "@/hooks/useEditorHistory" ;
1717import { type Locale , SUPPORTED_LOCALES } from "@/i18n/config" ;
1818import { getLocaleName } from "@/i18n/loader" ;
19+ import { getAssetPath } from "@/lib/assetPath" ;
1920import {
2021 calculateOutputDimensions ,
2122 type ExportFormat ,
@@ -28,7 +29,6 @@ import {
2829 type GifSizePreset ,
2930 VideoExporter ,
3031} from "@/lib/exporter" ;
31- import { getAssetPath } from "@/lib/assetPath" ;
3232import { computeFrameStepTime } from "@/lib/frameStep" ;
3333import type { ProjectMedia } from "@/lib/recordingSession" ;
3434import { matchesShortcut } from "@/lib/shortcuts" ;
@@ -54,11 +54,10 @@ import {
5454import { SettingsPanel } from "./SettingsPanel" ;
5555import TimelineEditor from "./timeline/TimelineEditor" ;
5656import {
57- type AudioHookType ,
5857 type AnnotationRegion ,
58+ type AudioHookType ,
5959 type BlurData ,
6060 type CursorTelemetryPoint ,
61- type HookRegion ,
6261 clampFocusToDepth ,
6362 DEFAULT_ANNOTATION_POSITION ,
6463 DEFAULT_ANNOTATION_SIZE ,
@@ -68,6 +67,7 @@ import {
6867 DEFAULT_PLAYBACK_SPEED ,
6968 DEFAULT_ZOOM_DEPTH ,
7069 type FigureData ,
70+ type HookRegion ,
7171 type PlaybackSpeed ,
7272 type SpeedRegion ,
7373 type TrimRegion ,
@@ -204,14 +204,34 @@ export default function VideoEditor() {
204204 [ annotationRegions ] ,
205205 ) ;
206206
207- const resolveAudioSourceUrl = useCallback ( ( value : string | null | undefined ) : string | undefined => {
208- if ( ! value ) {
209- return undefined ;
207+ const resolveAudioSourceUrl = useCallback (
208+ ( value : string | null | undefined ) : string | undefined => {
209+ if ( ! value ) {
210+ return undefined ;
211+ }
212+ if ( / ^ ( f i l e | h t t p s ? ) : \/ \/ / i. test ( value ) || value . startsWith ( "/" ) ) {
213+ return value ;
214+ }
215+ return toFileUrl ( value ) ;
216+ } ,
217+ [ ] ,
218+ ) ;
219+
220+ const resolveLibraryTrackUrl = useCallback ( async ( trackUrl : string ) : Promise < string > => {
221+ if ( / ^ ( f i l e | h t t p s ? ) : \/ \/ / i. test ( trackUrl ) ) {
222+ return trackUrl ;
210223 }
211- if ( / ^ ( f i l e | h t t p s ? ) : \/ \/ / i. test ( value ) || value . startsWith ( "/" ) ) {
212- return value ;
224+
225+ if ( trackUrl . startsWith ( "/audio/" ) ) {
226+ return trackUrl ;
213227 }
214- return toFileUrl ( value ) ;
228+
229+ if ( trackUrl . startsWith ( "/" ) ) {
230+ const relativePath = trackUrl . replace ( / ^ \/ + / , "" ) ;
231+ return getAssetPath ( relativePath ) ;
232+ }
233+
234+ return trackUrl ;
215235 } , [ ] ) ;
216236
217237 const currentProjectMedia = useMemo < ProjectMedia | null > ( ( ) => {
@@ -393,7 +413,6 @@ export default function VideoEditor() {
393413 aspectRatio ,
394414 webcamLayoutPreset ,
395415 webcamMaskShape ,
396- webcamSizePreset ,
397416 webcamPosition ,
398417 exportQuality ,
399418 exportFormat ,
@@ -796,8 +815,7 @@ export default function VideoEditor() {
796815 const handleMusicTrackSelect = useCallback (
797816 async ( trackUrl : string ) => {
798817 try {
799- const relativePath = trackUrl . replace ( / ^ \/ + / , "" ) ;
800- const resolvedAssetPath = await getAssetPath ( relativePath ) ;
818+ const resolvedAssetPath = await resolveLibraryTrackUrl ( trackUrl ) ;
801819 const fullDurationMs = Math . max ( 1000 , Math . round ( durationRef . current * 1000 ) ) ;
802820 pushState ( ( prev ) => ( {
803821 backgroundMusicPath : resolvedAssetPath ,
@@ -810,25 +828,21 @@ export default function VideoEditor() {
810828 startMs : 0 ,
811829 endMs : fullDurationMs ,
812830 } ,
813- ] ,
831+ ] ,
814832 } ) ) ;
815833 } catch {
816834 toast . error ( "Failed to load bundled track" ) ;
817835 }
818836 } ,
819- [ pushState ] ,
837+ [ pushState , resolveLibraryTrackUrl ] ,
820838 ) ;
821839
822- const resolveHookTrackSourceUrl = useCallback ( async ( trackUrl : string ) => {
823- if ( / ^ ( f i l e | h t t p s ? ) : \/ \/ / i. test ( trackUrl ) ) {
824- return trackUrl ;
825- }
826- if ( trackUrl . startsWith ( "/" ) ) {
827- const relativePath = trackUrl . replace ( / ^ \/ + / , "" ) ;
828- return getAssetPath ( relativePath ) ;
829- }
830- return trackUrl ;
831- } , [ ] ) ;
840+ const resolveHookTrackSourceUrl = useCallback (
841+ async ( trackUrl : string ) => {
842+ return resolveLibraryTrackUrl ( trackUrl ) ;
843+ } ,
844+ [ resolveLibraryTrackUrl ] ,
845+ ) ;
832846
833847 const resolveAudioDurationMs = useCallback ( async ( audioUrl : string ) : Promise < number > => {
834848 return await new Promise ( ( resolve ) => {
@@ -862,8 +876,7 @@ export default function VideoEditor() {
862876 const handleHookTrackAdd = useCallback (
863877 async ( hook : AudioHookType , trackUrl : string ) => {
864878 try {
865- const relativePath = trackUrl . replace ( / ^ \/ + / , "" ) ;
866- const resolvedAssetPath = await getAssetPath ( relativePath ) ;
879+ const resolvedAssetPath = await resolveLibraryTrackUrl ( trackUrl ) ;
867880 setHookSoundLayers ( ( prev ) => {
868881 const existing = prev [ hook ] ?? [ ] ;
869882 if ( existing . includes ( resolvedAssetPath ) ) {
@@ -878,7 +891,7 @@ export default function VideoEditor() {
878891 toast . error ( "Failed to add hook sound" ) ;
879892 }
880893 } ,
881- [ ] ,
894+ [ resolveLibraryTrackUrl ] ,
882895 ) ;
883896
884897 const handleHookTrackRemove = useCallback ( ( hook : AudioHookType , trackUrl : string ) => {
@@ -932,10 +945,10 @@ export default function VideoEditor() {
932945 hookRegions : prev . hookRegions . map ( ( region ) =>
933946 region . id === id
934947 ? {
935- ...region ,
936- startMs : Math . round ( span . start ) ,
937- endMs : Math . round ( span . end ) ,
938- }
948+ ...region ,
949+ startMs : Math . round ( span . start ) ,
950+ endMs : Math . round ( span . end ) ,
951+ }
939952 : region ,
940953 ) ,
941954 } ) ) ;
@@ -2451,9 +2464,7 @@ export default function VideoEditor() {
24512464 onBlurDataChange = { handleBlurDataPreviewChange }
24522465 onBlurDataCommit = { commitState }
24532466 cursorTelemetry = { cursorTelemetry }
2454- backgroundMusicPath = {
2455- resolveAudioSourceUrl ( backgroundMusicPath )
2456- }
2467+ backgroundMusicPath = { resolveAudioSourceUrl ( backgroundMusicPath ) }
24572468 backgroundMusicRegions = { backgroundMusicRegions }
24582469 backgroundMusicVolume = { backgroundMusicVolume }
24592470 />
0 commit comments