@@ -97,7 +97,7 @@ type OptionalRenderMediaOnWebOptions<Schema extends AnyZodObject> = {
9797 schema : Schema | undefined ;
9898 mediaCacheSizeInBytes : number | null ;
9999 videoCodec : WebRendererVideoCodec ;
100- audioCodec : WebRendererAudioCodec ;
100+ audioCodec : WebRendererAudioCodec | null ;
101101 audioBitrate : number | WebRendererQuality ;
102102 container : WebRendererContainer ;
103103 signal : AbortSignal | null ;
@@ -126,12 +126,9 @@ type InternalRenderMediaOnWebOptions<
126126 Props extends Record < string , unknown > ,
127127> = MandatoryRenderMediaOnWebOptions < Schema , Props > &
128128 OptionalRenderMediaOnWebOptions < Schema > &
129- InputPropsIfHasProps < Schema , Props > & {
130- userSpecifiedAudioCodec : boolean ;
131- } ;
129+ InputPropsIfHasProps < Schema , Props > ;
132130
133131// TODO: More containers
134- // TODO: Audio
135132// TODO: Metadata
136133// TODO: Validating inputs
137134// TODO: Apply defaultCodec
@@ -147,9 +144,8 @@ const internalRenderMediaOnWeb = async <
147144 mediaCacheSizeInBytes,
148145 schema,
149146 videoCodec : codec ,
150- audioCodec,
147+ audioCodec : unresolvedAudioCodec ,
151148 audioBitrate,
152- userSpecifiedAudioCodec,
153149 container,
154150 signal,
155151 onProgress,
@@ -190,6 +186,10 @@ const internalRenderMediaOnWeb = async <
190186 ) ;
191187 }
192188
189+ const audioCodec =
190+ unresolvedAudioCodec ?? getDefaultAudioCodecForContainer ( container ) ;
191+ const userSpecifiedAudioCodec = unresolvedAudioCodec !== undefined ;
192+
193193 const resolved = await Internals . resolveVideoConfig ( {
194194 calculateMetadata :
195195 ( composition . calculateMetadata as CalculateMetadataFunction <
@@ -323,11 +323,19 @@ const internalRenderMediaOnWeb = async <
323323
324324 if ( ! canEncode ) {
325325 if ( userSpecifiedAudioCodec ) {
326- return Promise . reject (
327- new Error (
328- `Audio codec "${ audioCodec } " cannot be encoded by this browser. This is common for AAC on Firefox. Try using "opus" instead.` ,
329- ) ,
330- ) ;
326+ let errorMessage = `Audio codec "${ audioCodec } " cannot be encoded by this browser.` ;
327+ const isFirefox =
328+ typeof navigator !== 'undefined' &&
329+ / f i r e f o x / i. test ( navigator . userAgent ) ;
330+ if ( audioCodec === 'aac' && isFirefox ) {
331+ errorMessage +=
332+ ' AAC encoding is not supported in Firefox. Try using "opus" instead.' ;
333+ } else {
334+ errorMessage +=
335+ ' This is common for AAC on Firefox. Try using "opus" instead.' ;
336+ }
337+
338+ return Promise . reject ( new Error ( errorMessage ) ) ;
331339 }
332340
333341 let fallbackCodec : WebRendererAudioCodec | null = null ;
@@ -544,9 +552,6 @@ export const renderMediaOnWeb = <
544552 const container = options . container ?? 'mp4' ;
545553 const codec =
546554 options . videoCodec ?? getDefaultVideoCodecForContainer ( container ) ;
547- const userSpecifiedAudioCodec = options . audioCodec !== undefined ;
548- const audioCodec =
549- options . audioCodec ?? getDefaultAudioCodecForContainer ( container ) ;
550555
551556 onlyOneRenderAtATimeQueue . ref = onlyOneRenderAtATimeQueue . ref
552557 . catch ( ( ) => Promise . resolve ( ) )
@@ -560,9 +565,8 @@ export const renderMediaOnWeb = <
560565 schema : options . schema ?? undefined ,
561566 mediaCacheSizeInBytes : options . mediaCacheSizeInBytes ?? null ,
562567 videoCodec : codec ,
563- audioCodec,
568+ audioCodec : options . audioCodec ?? null ,
564569 audioBitrate : options . audioBitrate ?? 'medium' ,
565- userSpecifiedAudioCodec,
566570 container,
567571 signal : options . signal ?? null ,
568572 onProgress : options . onProgress ?? null ,
0 commit comments