@@ -4945,7 +4945,11 @@ describe("initSandboxRuntimeModular", () => {
49454945 await Promise . resolve ( ) ;
49464946 }
49474947
4948- function mountAudio ( src : string , attrs : Record < string , string > = { } ) {
4948+ function mountAudio (
4949+ src : string ,
4950+ attrs : Record < string , string > = { } ,
4951+ tag : "audio" | "video" = "audio" ,
4952+ ) {
49494953 const root = document . createElement ( "div" ) ;
49504954 root . setAttribute ( "data-composition-id" , "main" ) ;
49514955 root . setAttribute ( "data-root" , "true" ) ;
@@ -4955,7 +4959,7 @@ describe("initSandboxRuntimeModular", () => {
49554959 root . setAttribute ( "data-height" , "1080" ) ;
49564960 document . body . appendChild ( root ) ;
49574961
4958- const audio = document . createElement ( "audio" ) ;
4962+ const audio = document . createElement ( tag ) ;
49594963 audio . setAttribute ( "data-start" , "0" ) ;
49604964 audio . setAttribute ( "data-duration" , "10" ) ;
49614965 audio . setAttribute ( "src" , src ) ;
@@ -5042,7 +5046,7 @@ describe("initSandboxRuntimeModular", () => {
50425046 expect ( String ( line ?. [ 0 ] ) ) . toContain ( "fx-chain" ) ;
50435047 } ) ;
50445048
5045- it ( "says nothing about a cross-origin <video>, which never routes through Web Audio" , ( ) => {
5049+ it ( "says nothing about a cross-origin <video> at unity , which never routes through Web Audio" , ( ) => {
50465050 const root = document . createElement ( "div" ) ;
50475051 root . setAttribute ( "data-composition-id" , "main" ) ;
50485052 root . setAttribute ( "data-root" , "true" ) ;
@@ -5128,6 +5132,82 @@ describe("initSandboxRuntimeModular", () => {
51285132 } ) ;
51295133 } ) ;
51305134
5135+ // `el.volume` stops at 1, so a video's authored boost can only be carried by a Web Audio gain.
5136+ describe ( "a video's sound above unity" , ( ) => {
5137+ const ctx = useMockAudioContext ( ) ;
5138+
5139+ it ( "plays a video at data-volume 1.5 through a Web Audio gain of 1.5" , async ( ) => {
5140+ const video = mountAudio ( "/assets/broll.mp4" , { "data-volume" : "1.5" } , "video" ) ;
5141+ const captureSpy = vi . spyOn ( WebAudioTransport . prototype , "scheduleMediaElementPlayback" ) ;
5142+
5143+ await startPlayback ( ) ;
5144+ const scheduled = await captureSpy . mock . results [ 0 ] ?. value ;
5145+
5146+ expect ( captureSpy . mock . calls [ 0 ] ?. [ 0 ] ) . toBe ( video ) ;
5147+ expect ( ctx . mediaElementSources ) . toBe ( 1 ) ;
5148+ expect ( scheduled ?. gainNode . gain . value ) . toBe ( 1.5 ) ;
5149+ expect ( video . volume ) . toBe ( 1 ) ;
5150+ expect ( video . muted ) . toBe ( false ) ;
5151+ } ) ;
5152+
5153+ it ( "leaves a video at unity on its native output" , async ( ) => {
5154+ mountAudio ( "/assets/broll.mp4" , { "data-volume" : "1" } , "video" ) ;
5155+ const captureSpy = vi . spyOn ( WebAudioTransport . prototype , "scheduleMediaElementPlayback" ) ;
5156+
5157+ await startPlayback ( ) ;
5158+
5159+ expect ( captureSpy ) . not . toHaveBeenCalled ( ) ;
5160+ expect ( ctx . mediaElementSources ) . toBe ( 0 ) ;
5161+ } ) ;
5162+
5163+ it ( "silences a captured video hidden after its volume drops to 1" , async ( ) => {
5164+ const raf = createManualRaf ( ) ;
5165+ vi . spyOn ( performance , "now" ) . mockImplementation ( ( ) => raf . now ( ) ) ;
5166+ window . requestAnimationFrame =
5167+ raf . requestAnimationFrame as typeof window . requestAnimationFrame ;
5168+ window . cancelAnimationFrame = raf . cancelAnimationFrame as typeof window . cancelAnimationFrame ;
5169+ const video = mountAudio ( "/assets/broll.mp4" , { "data-volume" : "1.5" } , "video" ) ;
5170+ Object . defineProperty ( video , "paused" , { value : false , configurable : true } ) ;
5171+ Object . defineProperty ( video , "readyState" , { value : 4 , configurable : true } ) ;
5172+ const captureSpy = vi . spyOn ( WebAudioTransport . prototype , "scheduleMediaElementPlayback" ) ;
5173+ const step = async ( ) => {
5174+ for ( let frame = 0 ; frame < 5 ; frame ++ ) {
5175+ ctx . time += 1 / 60 ;
5176+ raf . step ( 1000 / 60 ) ;
5177+ await Promise . resolve ( ) ;
5178+ }
5179+ } ;
5180+
5181+ await startPlayback ( ) ;
5182+ await captureSpy . mock . results [ 0 ] ?. value ;
5183+ const transport = captureSpy . mock . contexts [ 0 ] as WebAudioTransport ;
5184+ await step ( ) ;
5185+ video . setAttribute ( "data-volume" , "1" ) ;
5186+ await step ( ) ;
5187+ video . setAttribute ( "data-hidden" , "" ) ;
5188+ await step ( ) ;
5189+
5190+ expect ( transport . routesElement ( video ) ) . toBe ( false ) ;
5191+ expect ( video . volume ) . toBe ( 0 ) ;
5192+ } ) ;
5193+
5194+ it ( "keeps a cross-origin boosted video native and never decodes it" , async ( ) => {
5195+ const video = mountAudio (
5196+ "https://cdn.example.com/broll.mp4" ,
5197+ { "data-volume" : "1.5" } ,
5198+ "video" ,
5199+ ) ;
5200+ vi . spyOn ( console , "info" ) . mockImplementation ( ( ) => { } ) ;
5201+ const decodeSpy = vi . spyOn ( WebAudioTransport . prototype , "decodeAudioElement" ) ;
5202+
5203+ await startPlayback ( ) ;
5204+
5205+ expect ( ctx . mediaElementSources ) . toBe ( 0 ) ;
5206+ expect ( decodeSpy ) . not . toHaveBeenCalled ( ) ;
5207+ expect ( video . muted ) . toBe ( false ) ;
5208+ } ) ;
5209+ } ) ;
5210+
51315211 describe ( "a voiceover routed through Web Audio" , ( ) => {
51325212 const ctx = useMockAudioContext ( ) ;
51335213
0 commit comments