MCPcopy Create free account
hub / github.com/heygen-com/hyperframes / scheduleWebAudioForActiveClips

Function scheduleWebAudioForActiveClips

packages/core/src/runtime/init.ts:2620–2663  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2618 // same edge as the HTMLMedia path. Reused by play() and by the rate-change
2619 // handler (a rate change can't rescale a bounded source in place).
2620 const scheduleWebAudioForActiveClips = () => {
2621 if (state.nativeMediaSyncDisabled || state.webAudioMediaDisabled) return;
2622 const gen = webAudio.startGeneration();
2623 const audioEls = document.querySelectorAll("audio[data-start]");
2624 for (const rawEl of audioEls) {
2625 if (!(rawEl instanceof HTMLMediaElement) || !rawEl.isConnected) continue;
2626 const compStart = Number.parseFloat(rawEl.dataset.start ?? "");
2627 if (!Number.isFinite(compStart)) continue;
2628 const mediaStart =
2629 Number.parseFloat(rawEl.dataset.playbackStart ?? rawEl.dataset.mediaStart ?? "0") || 0;
2630 const volumeAttr = Number.parseFloat(rawEl.dataset.volume ?? "");
2631 const vol = Number.isFinite(volumeAttr) ? volumeAttr : 1;
2632 const durationAttr = Number.parseFloat(rawEl.dataset.duration ?? "");
2633 let clipDuration =
2634 Number.isFinite(durationAttr) && durationAttr > 0 ? durationAttr : Number.POSITIVE_INFINITY;
2635 const compositionRoot = rawEl.closest("[data-composition-id]");
2636 if (compositionRoot) {
2637 const inheritedStart = resolveStartForElement(compositionRoot, 0);
2638 const inheritedDuration = resolveDurationForElement(compositionRoot, {
2639 includeAuthoredTimingAttrs: true,
2640 });
2641 if (inheritedDuration != null && inheritedDuration > 0) {
2642 clipDuration = Math.min(
2643 clipDuration,
2644 Math.max(0, inheritedStart + inheritedDuration - compStart),
2645 );
2646 }
2647 }
2648 void webAudio.decodeAudioElement(rawEl).then((buffer) => {
2649 if (!buffer || !clock.isPlaying()) return;
2650 void webAudio.schedulePlayback(
2651 rawEl,
2652 buffer,
2653 compStart,
2654 mediaStart,
2655 clock.now(),
2656 vol * state.bridgeVolume,
2657 gen,
2658 state.playbackRate,
2659 clipDuration,
2660 );
2661 });
2662 }
2663 };
2664
2665 // Apply a new playback rate to the WebAudio transport. Unbounded sources are
2666 // rescaled in place; but a bounded source's window was baked into start()'s

Callers 2

applyWebAudioRateFunction · 0.85

Calls 7

resolveStartForElementFunction · 0.85
startGenerationMethod · 0.80
decodeAudioElementMethod · 0.80
schedulePlaybackMethod · 0.80
nowMethod · 0.80
isPlayingMethod · 0.65

Tested by

no test coverage detected