remotion
Version:
Make videos programmatically
78 lines (77 loc) • 2.77 kB
TypeScript
import { type AudioHTMLAttributes } from 'react';
import React from 'react';
import type { SharedElementSourceNode } from './shared-element-source-node.js';
/**
* This functionality of Remotion will keep a certain amount
* of <audio> tags pre-mounted and by default filled with an empty audio track.
* If the user interacts, the empty audio will be played.
* If one of Remotions <Html5Audio /> tags get mounted, the audio will not be rendered at this location, but into one of the prerendered audio tags.
*
* This helps with autoplay issues on iOS Safari and soon other browsers,
* which only allow audio playback upon user interaction.
*
* The behavior can be disabled by passing `0` as the number of shared audio tracks.
*/
type AudioElem = {
id: number;
props: AudioHTMLAttributes<HTMLAudioElement>;
el: React.RefObject<HTMLAudioElement | null>;
audioId: string;
mediaElementSourceNode: SharedElementSourceNode | null;
premounting: boolean;
postmounting: boolean;
audioMounted: boolean;
cleanupOnMediaTagUnmount: () => void;
};
export type ScheduleAudioNodeResult = {
type: 'started';
scheduledTime: number;
} | {
type: 'not-started';
};
export type ScheduleAudioNodeOptions = {
readonly node: AudioBufferSourceNode;
readonly targetTime: number;
readonly mediaTimestamp: number;
readonly currentTime: number;
readonly sequenceEndTime: number;
readonly sequenceStartTime: number;
readonly debugAudioScheduling: boolean;
};
type SharedContext = {
registerAudio: (options: {
aud: AudioHTMLAttributes<HTMLAudioElement>;
audioId: string;
premounting: boolean;
postmounting: boolean;
}) => AudioElem;
unregisterAudio: (id: number) => void;
updateAudio: (options: {
id: number;
aud: AudioHTMLAttributes<HTMLAudioElement>;
audioId: string;
premounting: boolean;
postmounting: boolean;
}) => void;
playAllAudios: () => void;
numberOfAudioTags: number;
audioContext: AudioContext | null;
audioSyncAnchor: {
value: number;
};
scheduleAudioNode: (options: ScheduleAudioNodeOptions) => ScheduleAudioNodeResult;
};
export declare const SharedAudioContext: React.Context<SharedContext | null>;
export declare const SharedAudioContextProvider: React.FC<{
readonly numberOfAudioTags: number;
readonly children: React.ReactNode;
readonly audioLatencyHint: AudioContextLatencyCategory;
readonly audioEnabled: boolean;
}>;
export declare const useSharedAudio: ({ aud, audioId, premounting, postmounting, }: {
aud: AudioHTMLAttributes<HTMLAudioElement>;
audioId: string;
premounting: boolean;
postmounting: boolean;
}) => AudioElem;
export {};