Add .gitignore to exclude all node packages and lock files
This commit is contained in:
+56
@@ -0,0 +1,56 @@
|
||||
import React from 'react';
|
||||
import type { RemotionMainAudioProps } from './props.js';
|
||||
/**
|
||||
* @description With this component, you can add audio to your video. All audio formats which are supported by Chromium are supported by the component.
|
||||
* @see [Documentation](https://remotion.dev/docs/html5-audio)
|
||||
*/
|
||||
export declare const Html5Audio: React.ForwardRefExoticComponent<Omit<import("./props.js").NativeAudioProps & {
|
||||
name?: string;
|
||||
volume?: import("../volume-prop.js").VolumeProp;
|
||||
playbackRate?: number;
|
||||
acceptableTimeShiftInSeconds?: number;
|
||||
allowAmplificationDuringRender?: boolean;
|
||||
_remotionInternalNeedsDurationCalculation?: boolean;
|
||||
_remotionInternalNativeLoopPassed?: boolean;
|
||||
toneFrequency?: number;
|
||||
useWebAudioApi?: boolean;
|
||||
pauseWhenBuffering?: boolean;
|
||||
showInTimeline?: boolean;
|
||||
delayRenderTimeoutInMilliseconds?: number;
|
||||
delayRenderRetries?: number;
|
||||
loopVolumeCurveBehavior?: import("./use-audio-frame.js").LoopVolumeCurveBehavior;
|
||||
onError?: (err: Error) => void;
|
||||
audioStreamIndex?: number;
|
||||
} & RemotionMainAudioProps & {
|
||||
/**
|
||||
* @deprecated For internal use only
|
||||
*/
|
||||
readonly stack?: string;
|
||||
}, "ref"> & React.RefAttributes<HTMLAudioElement>>;
|
||||
/**
|
||||
* @deprecated This component has been renamed to `Html5Audio`.
|
||||
* @see [Documentation](https://remotion.dev/docs/mediabunny/new-video)
|
||||
*/
|
||||
export declare const Audio: React.ForwardRefExoticComponent<Omit<import("./props.js").NativeAudioProps & {
|
||||
name?: string;
|
||||
volume?: import("../volume-prop.js").VolumeProp;
|
||||
playbackRate?: number;
|
||||
acceptableTimeShiftInSeconds?: number;
|
||||
allowAmplificationDuringRender?: boolean;
|
||||
_remotionInternalNeedsDurationCalculation?: boolean;
|
||||
_remotionInternalNativeLoopPassed?: boolean;
|
||||
toneFrequency?: number;
|
||||
useWebAudioApi?: boolean;
|
||||
pauseWhenBuffering?: boolean;
|
||||
showInTimeline?: boolean;
|
||||
delayRenderTimeoutInMilliseconds?: number;
|
||||
delayRenderRetries?: number;
|
||||
loopVolumeCurveBehavior?: import("./use-audio-frame.js").LoopVolumeCurveBehavior;
|
||||
onError?: (err: Error) => void;
|
||||
audioStreamIndex?: number;
|
||||
} & RemotionMainAudioProps & {
|
||||
/**
|
||||
* @deprecated For internal use only
|
||||
*/
|
||||
readonly stack?: string;
|
||||
}, "ref"> & React.RefAttributes<HTMLAudioElement>>;
|
||||
+101
@@ -0,0 +1,101 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Audio = exports.Html5Audio = void 0;
|
||||
const jsx_runtime_1 = require("react/jsx-runtime");
|
||||
/* eslint-disable @typescript-eslint/no-use-before-define */
|
||||
const react_1 = require("react");
|
||||
const Sequence_js_1 = require("../Sequence.js");
|
||||
const absolute_src_js_1 = require("../absolute-src.js");
|
||||
const calculate_media_duration_js_1 = require("../calculate-media-duration.js");
|
||||
const cancel_render_js_1 = require("../cancel-render.js");
|
||||
const enable_sequence_stack_traces_js_1 = require("../enable-sequence-stack-traces.js");
|
||||
const index_js_1 = require("../loop/index.js");
|
||||
const prefetch_js_1 = require("../prefetch.js");
|
||||
const use_remotion_environment_js_1 = require("../use-remotion-environment.js");
|
||||
const use_video_config_js_1 = require("../use-video-config.js");
|
||||
const validate_media_props_js_1 = require("../validate-media-props.js");
|
||||
const validate_start_from_props_js_1 = require("../validate-start-from-props.js");
|
||||
const duration_state_js_1 = require("../video/duration-state.js");
|
||||
const AudioForPreview_js_1 = require("./AudioForPreview.js");
|
||||
const AudioForRendering_js_1 = require("./AudioForRendering.js");
|
||||
const shared_audio_tags_js_1 = require("./shared-audio-tags.js");
|
||||
const AudioRefForwardingFunction = (props, ref) => {
|
||||
var _a, _b, _c;
|
||||
const audioContext = (0, react_1.useContext)(shared_audio_tags_js_1.SharedAudioContext);
|
||||
const { startFrom, endAt, trimBefore, trimAfter, name, stack, pauseWhenBuffering, showInTimeline, onError: onRemotionError, ...otherProps } = props;
|
||||
const { loop, ...propsOtherThanLoop } = props;
|
||||
const { fps } = (0, use_video_config_js_1.useVideoConfig)();
|
||||
const environment = (0, use_remotion_environment_js_1.useRemotionEnvironment)();
|
||||
if (environment.isClientSideRendering) {
|
||||
throw new Error('<Html5Audio> is not supported in @remotion/web-renderer. Use <Audio> from @remotion/media instead. See https://remotion.dev/docs/client-side-rendering/limitations');
|
||||
}
|
||||
const { durations, setDurations } = (0, react_1.useContext)(duration_state_js_1.DurationsContext);
|
||||
if (typeof props.src !== 'string') {
|
||||
throw new TypeError(`The \`<Html5Audio>\` tag requires a string for \`src\`, but got ${JSON.stringify(props.src)} instead.`);
|
||||
}
|
||||
const preloadedSrc = (0, prefetch_js_1.usePreload)(props.src);
|
||||
const onError = (0, react_1.useCallback)((e) => {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(e.currentTarget.error);
|
||||
// If there is no `loop` property, we don't need to get the duration
|
||||
// and this does not need to be a fatal error
|
||||
const errMessage = `Could not play audio with src ${preloadedSrc}: ${e.currentTarget.error}. See https://remotion.dev/docs/media-playback-error for help.`;
|
||||
if (loop) {
|
||||
if (onRemotionError) {
|
||||
onRemotionError(new Error(errMessage));
|
||||
return;
|
||||
}
|
||||
(0, cancel_render_js_1.cancelRender)(new Error(errMessage));
|
||||
}
|
||||
else {
|
||||
onRemotionError === null || onRemotionError === void 0 ? void 0 : onRemotionError(new Error(errMessage));
|
||||
// eslint-disable-next-line no-console
|
||||
console.warn(errMessage);
|
||||
}
|
||||
}, [loop, onRemotionError, preloadedSrc]);
|
||||
const onDuration = (0, react_1.useCallback)((src, durationInSeconds) => {
|
||||
setDurations({ type: 'got-duration', durationInSeconds, src });
|
||||
}, [setDurations]);
|
||||
const durationFetched = (_a = durations[(0, absolute_src_js_1.getAbsoluteSrc)(preloadedSrc)]) !== null && _a !== void 0 ? _a : durations[(0, absolute_src_js_1.getAbsoluteSrc)(props.src)];
|
||||
(0, validate_start_from_props_js_1.validateMediaTrimProps)({ startFrom, endAt, trimBefore, trimAfter });
|
||||
const { trimBeforeValue, trimAfterValue } = (0, validate_start_from_props_js_1.resolveTrimProps)({
|
||||
startFrom,
|
||||
endAt,
|
||||
trimBefore,
|
||||
trimAfter,
|
||||
});
|
||||
if (loop && durationFetched !== undefined) {
|
||||
if (!Number.isFinite(durationFetched)) {
|
||||
return ((0, jsx_runtime_1.jsx)(exports.Html5Audio, { ...propsOtherThanLoop, ref: ref, _remotionInternalNativeLoopPassed: true }));
|
||||
}
|
||||
const duration = durationFetched * fps;
|
||||
return ((0, jsx_runtime_1.jsx)(index_js_1.Loop, { layout: "none", durationInFrames: (0, calculate_media_duration_js_1.calculateMediaDuration)({
|
||||
trimAfter: trimAfterValue,
|
||||
mediaDurationInFrames: duration,
|
||||
playbackRate: (_b = props.playbackRate) !== null && _b !== void 0 ? _b : 1,
|
||||
trimBefore: trimBeforeValue,
|
||||
}), children: (0, jsx_runtime_1.jsx)(exports.Html5Audio, { ...propsOtherThanLoop, ref: ref, _remotionInternalNativeLoopPassed: true }) }));
|
||||
}
|
||||
if (typeof trimBeforeValue !== 'undefined' ||
|
||||
typeof trimAfterValue !== 'undefined') {
|
||||
return ((0, jsx_runtime_1.jsx)(Sequence_js_1.Sequence, { layout: "none", from: 0 - (trimBeforeValue !== null && trimBeforeValue !== void 0 ? trimBeforeValue : 0), showInTimeline: false, durationInFrames: trimAfterValue, name: name, children: (0, jsx_runtime_1.jsx)(exports.Html5Audio, { _remotionInternalNeedsDurationCalculation: Boolean(loop), pauseWhenBuffering: pauseWhenBuffering !== null && pauseWhenBuffering !== void 0 ? pauseWhenBuffering : false, ...otherProps, ref: ref }) }));
|
||||
}
|
||||
(0, validate_media_props_js_1.validateMediaProps)({ playbackRate: props.playbackRate, volume: props.volume }, 'Html5Audio');
|
||||
if (environment.isRendering) {
|
||||
return ((0, jsx_runtime_1.jsx)(AudioForRendering_js_1.AudioForRendering, { onDuration: onDuration, ...props, ref: ref, onNativeError: onError, _remotionInternalNeedsDurationCalculation: Boolean(loop) }));
|
||||
}
|
||||
return ((0, jsx_runtime_1.jsx)(AudioForPreview_js_1.AudioForPreview, { _remotionInternalNativeLoopPassed: (_c = props._remotionInternalNativeLoopPassed) !== null && _c !== void 0 ? _c : false, _remotionInternalStack: stack !== null && stack !== void 0 ? stack : null, shouldPreMountAudioTags: audioContext !== null && audioContext.numberOfAudioTags > 0, ...props, ref: ref, onNativeError: onError, onDuration: onDuration,
|
||||
// Proposal: Make this default to true in v5
|
||||
pauseWhenBuffering: pauseWhenBuffering !== null && pauseWhenBuffering !== void 0 ? pauseWhenBuffering : false, _remotionInternalNeedsDurationCalculation: Boolean(loop), showInTimeline: showInTimeline !== null && showInTimeline !== void 0 ? showInTimeline : true }));
|
||||
};
|
||||
/**
|
||||
* @description With this component, you can add audio to your video. All audio formats which are supported by Chromium are supported by the component.
|
||||
* @see [Documentation](https://remotion.dev/docs/html5-audio)
|
||||
*/
|
||||
exports.Html5Audio = (0, react_1.forwardRef)(AudioRefForwardingFunction);
|
||||
(0, enable_sequence_stack_traces_js_1.addSequenceStackTraces)(exports.Html5Audio);
|
||||
/**
|
||||
* @deprecated This component has been renamed to `Html5Audio`.
|
||||
* @see [Documentation](https://remotion.dev/docs/mediabunny/new-video)
|
||||
*/
|
||||
exports.Audio = exports.Html5Audio;
|
||||
Generated
Vendored
+14
@@ -0,0 +1,14 @@
|
||||
import React from 'react';
|
||||
import type { RemotionAudioProps } from './props.js';
|
||||
type AudioForPreviewProps = RemotionAudioProps & {
|
||||
readonly shouldPreMountAudioTags: boolean;
|
||||
readonly onDuration: (src: string, durationInSeconds: number) => void;
|
||||
readonly pauseWhenBuffering: boolean;
|
||||
readonly _remotionInternalNativeLoopPassed: boolean;
|
||||
readonly _remotionInternalStack: string | null;
|
||||
readonly showInTimeline: boolean;
|
||||
readonly stack?: string | undefined;
|
||||
readonly onNativeError: React.ReactEventHandler<HTMLAudioElement>;
|
||||
};
|
||||
export declare const AudioForPreview: React.ForwardRefExoticComponent<Omit<AudioForPreviewProps, "ref"> & React.RefAttributes<HTMLAudioElement>>;
|
||||
export {};
|
||||
Generated
Vendored
+215
@@ -0,0 +1,215 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || (function () {
|
||||
var ownKeys = function(o) {
|
||||
ownKeys = Object.getOwnPropertyNames || function (o) {
|
||||
var ar = [];
|
||||
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
||||
return ar;
|
||||
};
|
||||
return ownKeys(o);
|
||||
};
|
||||
return function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.AudioForPreview = void 0;
|
||||
const jsx_runtime_1 = require("react/jsx-runtime");
|
||||
const react_1 = __importStar(require("react"));
|
||||
const SequenceContext_js_1 = require("../SequenceContext.js");
|
||||
const SequenceManager_js_1 = require("../SequenceManager.js");
|
||||
const get_cross_origin_value_js_1 = require("../get-cross-origin-value.js");
|
||||
const log_level_context_js_1 = require("../log-level-context.js");
|
||||
const prefetch_js_1 = require("../prefetch.js");
|
||||
const random_js_1 = require("../random.js");
|
||||
const use_amplification_js_1 = require("../use-amplification.js");
|
||||
const use_media_in_timeline_js_1 = require("../use-media-in-timeline.js");
|
||||
const use_media_playback_js_1 = require("../use-media-playback.js");
|
||||
const use_media_tag_js_1 = require("../use-media-tag.js");
|
||||
const volume_position_state_js_1 = require("../volume-position-state.js");
|
||||
const volume_prop_js_1 = require("../volume-prop.js");
|
||||
const volume_safeguard_js_1 = require("../volume-safeguard.js");
|
||||
const shared_audio_tags_js_1 = require("./shared-audio-tags.js");
|
||||
const use_audio_frame_js_1 = require("./use-audio-frame.js");
|
||||
const AudioForDevelopmentForwardRefFunction = (props, ref) => {
|
||||
var _a, _b, _c, _d;
|
||||
const [initialShouldPreMountAudioElements] = (0, react_1.useState)(props.shouldPreMountAudioTags);
|
||||
if (props.shouldPreMountAudioTags !== initialShouldPreMountAudioElements) {
|
||||
throw new Error('Cannot change the behavior for pre-mounting audio tags dynamically.');
|
||||
}
|
||||
const logLevel = (0, log_level_context_js_1.useLogLevel)();
|
||||
const { volume, muted, playbackRate, shouldPreMountAudioTags, src, onDuration, acceptableTimeShiftInSeconds, _remotionInternalNeedsDurationCalculation, _remotionInternalNativeLoopPassed, _remotionInternalStack, allowAmplificationDuringRender, name, pauseWhenBuffering, showInTimeline, loopVolumeCurveBehavior, stack, crossOrigin, delayRenderRetries, delayRenderTimeoutInMilliseconds, toneFrequency, useWebAudioApi, onError, onNativeError, audioStreamIndex, ...nativeProps } = props;
|
||||
// Typecheck that we are not accidentially passing unrecognized props
|
||||
// to the DOM
|
||||
const _propsValid = true;
|
||||
if (!_propsValid) {
|
||||
throw new Error('typecheck error');
|
||||
}
|
||||
const [mediaVolume] = (0, volume_position_state_js_1.useMediaVolumeState)();
|
||||
const [mediaMuted] = (0, volume_position_state_js_1.useMediaMutedState)();
|
||||
const volumePropFrame = (0, use_audio_frame_js_1.useFrameForVolumeProp)(loopVolumeCurveBehavior !== null && loopVolumeCurveBehavior !== void 0 ? loopVolumeCurveBehavior : 'repeat');
|
||||
const { hidden } = (0, react_1.useContext)(SequenceManager_js_1.SequenceVisibilityToggleContext);
|
||||
if (!src) {
|
||||
throw new TypeError("No 'src' was passed to <Html5Audio>.");
|
||||
}
|
||||
const preloadedSrc = (0, prefetch_js_1.usePreload)(src);
|
||||
const sequenceContext = (0, react_1.useContext)(SequenceContext_js_1.SequenceContext);
|
||||
const [timelineId] = (0, react_1.useState)(() => String(Math.random()));
|
||||
const isSequenceHidden = (_a = hidden[timelineId]) !== null && _a !== void 0 ? _a : false;
|
||||
const userPreferredVolume = (0, volume_prop_js_1.evaluateVolume)({
|
||||
frame: volumePropFrame,
|
||||
volume,
|
||||
mediaVolume,
|
||||
});
|
||||
(0, volume_safeguard_js_1.warnAboutTooHighVolume)(userPreferredVolume);
|
||||
const crossOriginValue = (0, get_cross_origin_value_js_1.getCrossOriginValue)({
|
||||
crossOrigin,
|
||||
requestsVideoFrame: false,
|
||||
isClientSideRendering: false,
|
||||
});
|
||||
const propsToPass = (0, react_1.useMemo)(() => {
|
||||
return {
|
||||
muted: muted || mediaMuted || isSequenceHidden || userPreferredVolume <= 0,
|
||||
src: preloadedSrc,
|
||||
loop: _remotionInternalNativeLoopPassed,
|
||||
crossOrigin: crossOriginValue,
|
||||
...nativeProps,
|
||||
};
|
||||
}, [
|
||||
_remotionInternalNativeLoopPassed,
|
||||
isSequenceHidden,
|
||||
mediaMuted,
|
||||
muted,
|
||||
nativeProps,
|
||||
preloadedSrc,
|
||||
userPreferredVolume,
|
||||
crossOriginValue,
|
||||
]);
|
||||
// Generate a string that's as unique as possible for this asset
|
||||
// but at the same time deterministic. We use it to combat strict mode issues.
|
||||
const id = (0, react_1.useMemo)(() => `audio-${(0, random_js_1.random)(src !== null && src !== void 0 ? src : '')}-${sequenceContext === null || sequenceContext === void 0 ? void 0 : sequenceContext.relativeFrom}-${sequenceContext === null || sequenceContext === void 0 ? void 0 : sequenceContext.cumulatedFrom}-${sequenceContext === null || sequenceContext === void 0 ? void 0 : sequenceContext.durationInFrames}-muted:${props.muted}-loop:${props.loop}`, [
|
||||
src,
|
||||
sequenceContext === null || sequenceContext === void 0 ? void 0 : sequenceContext.relativeFrom,
|
||||
sequenceContext === null || sequenceContext === void 0 ? void 0 : sequenceContext.cumulatedFrom,
|
||||
sequenceContext === null || sequenceContext === void 0 ? void 0 : sequenceContext.durationInFrames,
|
||||
props.muted,
|
||||
props.loop,
|
||||
]);
|
||||
const { el: audioRef, mediaElementSourceNode, cleanupOnMediaTagUnmount, } = (0, shared_audio_tags_js_1.useSharedAudio)({
|
||||
aud: propsToPass,
|
||||
audioId: id,
|
||||
premounting: Boolean(sequenceContext === null || sequenceContext === void 0 ? void 0 : sequenceContext.premounting),
|
||||
postmounting: Boolean(sequenceContext === null || sequenceContext === void 0 ? void 0 : sequenceContext.postmounting),
|
||||
});
|
||||
(0, use_media_in_timeline_js_1.useMediaInTimeline)({
|
||||
volume,
|
||||
mediaVolume,
|
||||
src,
|
||||
mediaType: 'audio',
|
||||
playbackRate: playbackRate !== null && playbackRate !== void 0 ? playbackRate : 1,
|
||||
displayName: name !== null && name !== void 0 ? name : null,
|
||||
id: timelineId,
|
||||
stack: _remotionInternalStack,
|
||||
showInTimeline,
|
||||
premountDisplay: (_b = sequenceContext === null || sequenceContext === void 0 ? void 0 : sequenceContext.premountDisplay) !== null && _b !== void 0 ? _b : null,
|
||||
postmountDisplay: (_c = sequenceContext === null || sequenceContext === void 0 ? void 0 : sequenceContext.postmountDisplay) !== null && _c !== void 0 ? _c : null,
|
||||
loopDisplay: undefined,
|
||||
});
|
||||
// putting playback before useVolume
|
||||
// because volume looks at playbackrate
|
||||
(0, use_media_playback_js_1.useMediaPlayback)({
|
||||
mediaRef: audioRef,
|
||||
src,
|
||||
mediaType: 'audio',
|
||||
playbackRate: playbackRate !== null && playbackRate !== void 0 ? playbackRate : 1,
|
||||
onlyWarnForMediaSeekingError: false,
|
||||
acceptableTimeshift: acceptableTimeShiftInSeconds !== null && acceptableTimeShiftInSeconds !== void 0 ? acceptableTimeShiftInSeconds : null,
|
||||
isPremounting: Boolean(sequenceContext === null || sequenceContext === void 0 ? void 0 : sequenceContext.premounting),
|
||||
isPostmounting: Boolean(sequenceContext === null || sequenceContext === void 0 ? void 0 : sequenceContext.postmounting),
|
||||
pauseWhenBuffering,
|
||||
onAutoPlayError: null,
|
||||
});
|
||||
(0, use_media_tag_js_1.useMediaTag)({
|
||||
id: timelineId,
|
||||
isPostmounting: Boolean(sequenceContext === null || sequenceContext === void 0 ? void 0 : sequenceContext.postmounting),
|
||||
isPremounting: Boolean(sequenceContext === null || sequenceContext === void 0 ? void 0 : sequenceContext.premounting),
|
||||
mediaRef: audioRef,
|
||||
mediaType: 'audio',
|
||||
onAutoPlayError: null,
|
||||
});
|
||||
(0, use_amplification_js_1.useVolume)({
|
||||
logLevel,
|
||||
mediaRef: audioRef,
|
||||
source: mediaElementSourceNode,
|
||||
volume: userPreferredVolume,
|
||||
shouldUseWebAudioApi: useWebAudioApi !== null && useWebAudioApi !== void 0 ? useWebAudioApi : false,
|
||||
});
|
||||
/**
|
||||
* Effects in React 18 fire twice, and we are looking for a way to only fire it once.
|
||||
* - useInsertionEffect only fires once. If it's available we are in React 18.
|
||||
* - useLayoutEffect only fires once in React 17.
|
||||
*
|
||||
* Need to import it from React to fix React 17 ESM support.
|
||||
*/
|
||||
const effectToUse = (_d = react_1.default.useInsertionEffect) !== null && _d !== void 0 ? _d : react_1.default.useLayoutEffect;
|
||||
// Disconnecting the SharedElementSourceNodes if the Audio tag unmounts to prevent leak.
|
||||
// https://github.com/remotion-dev/remotion/issues/6285
|
||||
// But useInsertionEffect will fire before other effects, meaning the
|
||||
// nodes might still be used. Using rAF to ensure it's after other effects.
|
||||
effectToUse(() => {
|
||||
return () => {
|
||||
requestAnimationFrame(() => {
|
||||
cleanupOnMediaTagUnmount();
|
||||
});
|
||||
};
|
||||
}, [cleanupOnMediaTagUnmount]);
|
||||
(0, react_1.useImperativeHandle)(ref, () => {
|
||||
return audioRef.current;
|
||||
}, [audioRef]);
|
||||
const currentOnDurationCallback = (0, react_1.useRef)(onDuration);
|
||||
currentOnDurationCallback.current = onDuration;
|
||||
(0, react_1.useEffect)(() => {
|
||||
var _a;
|
||||
const { current } = audioRef;
|
||||
if (!current) {
|
||||
return;
|
||||
}
|
||||
if (current.duration) {
|
||||
(_a = currentOnDurationCallback.current) === null || _a === void 0 ? void 0 : _a.call(currentOnDurationCallback, current.src, current.duration);
|
||||
return;
|
||||
}
|
||||
const onLoadedMetadata = () => {
|
||||
var _a;
|
||||
(_a = currentOnDurationCallback.current) === null || _a === void 0 ? void 0 : _a.call(currentOnDurationCallback, current.src, current.duration);
|
||||
};
|
||||
current.addEventListener('loadedmetadata', onLoadedMetadata);
|
||||
return () => {
|
||||
current.removeEventListener('loadedmetadata', onLoadedMetadata);
|
||||
};
|
||||
}, [audioRef, src]);
|
||||
if (initialShouldPreMountAudioElements) {
|
||||
return null;
|
||||
}
|
||||
return ((0, jsx_runtime_1.jsx)("audio", { ref: audioRef, preload: "metadata", crossOrigin: crossOriginValue, ...propsToPass }));
|
||||
};
|
||||
exports.AudioForPreview = (0, react_1.forwardRef)(AudioForDevelopmentForwardRefFunction);
|
||||
Generated
Vendored
+9
@@ -0,0 +1,9 @@
|
||||
import type { ForwardRefExoticComponent, RefAttributes } from 'react';
|
||||
import React from 'react';
|
||||
import type { RemotionAudioProps } from './props.js';
|
||||
type AudioForRenderingProps = RemotionAudioProps & {
|
||||
readonly onDuration: (src: string, durationInSeconds: number) => void;
|
||||
readonly onNativeError: React.ReactEventHandler<HTMLAudioElement>;
|
||||
};
|
||||
export declare const AudioForRendering: ForwardRefExoticComponent<AudioForRenderingProps & RefAttributes<HTMLAudioElement>>;
|
||||
export {};
|
||||
Generated
Vendored
+138
@@ -0,0 +1,138 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.AudioForRendering = void 0;
|
||||
const jsx_runtime_1 = require("react/jsx-runtime");
|
||||
const react_1 = require("react");
|
||||
const RenderAssetManager_js_1 = require("../RenderAssetManager.js");
|
||||
const SequenceContext_js_1 = require("../SequenceContext.js");
|
||||
const absolute_src_js_1 = require("../absolute-src.js");
|
||||
const random_js_1 = require("../random.js");
|
||||
const timeline_position_state_js_1 = require("../timeline-position-state.js");
|
||||
const use_current_frame_js_1 = require("../use-current-frame.js");
|
||||
const use_delay_render_js_1 = require("../use-delay-render.js");
|
||||
const volume_prop_js_1 = require("../volume-prop.js");
|
||||
const volume_safeguard_js_1 = require("../volume-safeguard.js");
|
||||
const use_audio_frame_js_1 = require("./use-audio-frame.js");
|
||||
const AudioForRenderingRefForwardingFunction = (props, ref) => {
|
||||
const audioRef = (0, react_1.useRef)(null);
|
||||
const { volume: volumeProp, playbackRate, allowAmplificationDuringRender, onDuration, toneFrequency, _remotionInternalNeedsDurationCalculation, _remotionInternalNativeLoopPassed, acceptableTimeShiftInSeconds, name, onNativeError, delayRenderRetries, delayRenderTimeoutInMilliseconds, loopVolumeCurveBehavior, pauseWhenBuffering, audioStreamIndex, ...nativeProps } = props;
|
||||
const absoluteFrame = (0, timeline_position_state_js_1.useTimelinePosition)();
|
||||
const volumePropFrame = (0, use_audio_frame_js_1.useFrameForVolumeProp)(loopVolumeCurveBehavior !== null && loopVolumeCurveBehavior !== void 0 ? loopVolumeCurveBehavior : 'repeat');
|
||||
const frame = (0, use_current_frame_js_1.useCurrentFrame)();
|
||||
const sequenceContext = (0, react_1.useContext)(SequenceContext_js_1.SequenceContext);
|
||||
const { registerRenderAsset, unregisterRenderAsset } = (0, react_1.useContext)(RenderAssetManager_js_1.RenderAssetManager);
|
||||
const { delayRender, continueRender } = (0, use_delay_render_js_1.useDelayRender)();
|
||||
// Generate a string that's as unique as possible for this asset
|
||||
// but at the same time the same on all threads
|
||||
const id = (0, react_1.useMemo)(() => {
|
||||
var _a;
|
||||
return `audio-${(0, random_js_1.random)((_a = props.src) !== null && _a !== void 0 ? _a : '')}-${sequenceContext === null || sequenceContext === void 0 ? void 0 : sequenceContext.relativeFrom}-${sequenceContext === null || sequenceContext === void 0 ? void 0 : sequenceContext.cumulatedFrom}-${sequenceContext === null || sequenceContext === void 0 ? void 0 : sequenceContext.durationInFrames}`;
|
||||
}, [
|
||||
props.src,
|
||||
sequenceContext === null || sequenceContext === void 0 ? void 0 : sequenceContext.relativeFrom,
|
||||
sequenceContext === null || sequenceContext === void 0 ? void 0 : sequenceContext.cumulatedFrom,
|
||||
sequenceContext === null || sequenceContext === void 0 ? void 0 : sequenceContext.durationInFrames,
|
||||
]);
|
||||
const volume = (0, volume_prop_js_1.evaluateVolume)({
|
||||
volume: volumeProp,
|
||||
frame: volumePropFrame,
|
||||
mediaVolume: 1,
|
||||
});
|
||||
(0, volume_safeguard_js_1.warnAboutTooHighVolume)(volume);
|
||||
(0, react_1.useImperativeHandle)(ref, () => {
|
||||
return audioRef.current;
|
||||
}, []);
|
||||
(0, react_1.useEffect)(() => {
|
||||
var _a, _b;
|
||||
if (!props.src) {
|
||||
throw new Error('No src passed');
|
||||
}
|
||||
if (!window.remotion_audioEnabled) {
|
||||
return;
|
||||
}
|
||||
if (props.muted) {
|
||||
return;
|
||||
}
|
||||
if (volume <= 0) {
|
||||
return;
|
||||
}
|
||||
registerRenderAsset({
|
||||
type: 'audio',
|
||||
src: (0, absolute_src_js_1.getAbsoluteSrc)(props.src),
|
||||
id,
|
||||
frame: absoluteFrame,
|
||||
volume,
|
||||
mediaFrame: frame,
|
||||
playbackRate: (_a = props.playbackRate) !== null && _a !== void 0 ? _a : 1,
|
||||
toneFrequency: toneFrequency !== null && toneFrequency !== void 0 ? toneFrequency : 1,
|
||||
audioStartFrame: Math.max(0, -((_b = sequenceContext === null || sequenceContext === void 0 ? void 0 : sequenceContext.relativeFrom) !== null && _b !== void 0 ? _b : 0)),
|
||||
audioStreamIndex: audioStreamIndex !== null && audioStreamIndex !== void 0 ? audioStreamIndex : 0,
|
||||
});
|
||||
return () => unregisterRenderAsset(id);
|
||||
}, [
|
||||
props.muted,
|
||||
props.src,
|
||||
registerRenderAsset,
|
||||
absoluteFrame,
|
||||
id,
|
||||
unregisterRenderAsset,
|
||||
volume,
|
||||
volumePropFrame,
|
||||
frame,
|
||||
playbackRate,
|
||||
props.playbackRate,
|
||||
toneFrequency,
|
||||
sequenceContext === null || sequenceContext === void 0 ? void 0 : sequenceContext.relativeFrom,
|
||||
audioStreamIndex,
|
||||
]);
|
||||
const { src } = props;
|
||||
// The <audio> tag is only rendered if the duration needs to be calculated for the `loop`
|
||||
// attribute to work, or if the user assigns a ref to it.
|
||||
const needsToRenderAudioTag = ref || _remotionInternalNeedsDurationCalculation;
|
||||
// If audio source switches, make new handle
|
||||
(0, react_1.useLayoutEffect)(() => {
|
||||
var _a, _b;
|
||||
if (((_b = (_a = window.process) === null || _a === void 0 ? void 0 : _a.env) === null || _b === void 0 ? void 0 : _b.NODE_ENV) === 'test') {
|
||||
return;
|
||||
}
|
||||
if (!needsToRenderAudioTag) {
|
||||
return;
|
||||
}
|
||||
const newHandle = delayRender('Loading <Html5Audio> duration with src=' + src, {
|
||||
retries: delayRenderRetries !== null && delayRenderRetries !== void 0 ? delayRenderRetries : undefined,
|
||||
timeoutInMilliseconds: delayRenderTimeoutInMilliseconds !== null && delayRenderTimeoutInMilliseconds !== void 0 ? delayRenderTimeoutInMilliseconds : undefined,
|
||||
});
|
||||
const { current } = audioRef;
|
||||
const didLoad = () => {
|
||||
if (current === null || current === void 0 ? void 0 : current.duration) {
|
||||
onDuration(current.src, current.duration);
|
||||
}
|
||||
continueRender(newHandle);
|
||||
};
|
||||
if (current === null || current === void 0 ? void 0 : current.duration) {
|
||||
onDuration(current.src, current.duration);
|
||||
continueRender(newHandle);
|
||||
}
|
||||
else {
|
||||
current === null || current === void 0 ? void 0 : current.addEventListener('loadedmetadata', didLoad, { once: true });
|
||||
}
|
||||
// If tag gets unmounted, clear pending handles because video metadata is not going to load
|
||||
return () => {
|
||||
current === null || current === void 0 ? void 0 : current.removeEventListener('loadedmetadata', didLoad);
|
||||
continueRender(newHandle);
|
||||
};
|
||||
}, [
|
||||
src,
|
||||
onDuration,
|
||||
needsToRenderAudioTag,
|
||||
delayRenderRetries,
|
||||
delayRenderTimeoutInMilliseconds,
|
||||
continueRender,
|
||||
delayRender,
|
||||
]);
|
||||
if (!needsToRenderAudioTag) {
|
||||
return null;
|
||||
}
|
||||
return (0, jsx_runtime_1.jsx)("audio", { ref: audioRef, ...nativeProps, onError: onNativeError });
|
||||
};
|
||||
exports.AudioForRendering = (0, react_1.forwardRef)(AudioForRenderingRefForwardingFunction);
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
export { Audio, Html5Audio } from './Audio.js';
|
||||
export * from './props.js';
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
||||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.Html5Audio = exports.Audio = void 0;
|
||||
var Audio_js_1 = require("./Audio.js");
|
||||
Object.defineProperty(exports, "Audio", { enumerable: true, get: function () { return Audio_js_1.Audio; } });
|
||||
Object.defineProperty(exports, "Html5Audio", { enumerable: true, get: function () { return Audio_js_1.Html5Audio; } });
|
||||
__exportStar(require("./props.js"), exports);
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
import type { VolumeProp } from '../volume-prop.js';
|
||||
import type { LoopVolumeCurveBehavior } from './use-audio-frame.js';
|
||||
export type RemotionMainAudioProps = {
|
||||
/**
|
||||
* @deprecated `startFrom` was renamed to `trimBefore`
|
||||
*/
|
||||
startFrom?: number;
|
||||
/**
|
||||
* @deprecated `endAt` was renamed to `trimAfter`
|
||||
*/
|
||||
endAt?: number;
|
||||
/**
|
||||
* Trim of the audio from the left (start) in frames.
|
||||
*/
|
||||
trimBefore?: number;
|
||||
/**
|
||||
* Trim of the audio from the right (end) in frames.
|
||||
*/
|
||||
trimAfter?: number;
|
||||
};
|
||||
export type NativeAudioProps = Omit<React.DetailedHTMLProps<React.AudioHTMLAttributes<HTMLAudioElement>, HTMLAudioElement>, 'autoPlay' | 'controls' | 'onEnded' | 'nonce' | 'onResize' | 'onResizeCapture' | 'onError'>;
|
||||
export type RemotionAudioProps = NativeAudioProps & {
|
||||
name?: string;
|
||||
volume?: VolumeProp;
|
||||
playbackRate?: number;
|
||||
acceptableTimeShiftInSeconds?: number;
|
||||
/**
|
||||
* @deprecated Amplification is now always enabled. To prevent amplification, set `volume` to a value less than 1.
|
||||
*/
|
||||
allowAmplificationDuringRender?: boolean;
|
||||
_remotionInternalNeedsDurationCalculation?: boolean;
|
||||
_remotionInternalNativeLoopPassed?: boolean;
|
||||
toneFrequency?: number;
|
||||
useWebAudioApi?: boolean;
|
||||
pauseWhenBuffering?: boolean;
|
||||
showInTimeline?: boolean;
|
||||
delayRenderTimeoutInMilliseconds?: number;
|
||||
delayRenderRetries?: number;
|
||||
loopVolumeCurveBehavior?: LoopVolumeCurveBehavior;
|
||||
onError?: (err: Error) => void;
|
||||
audioStreamIndex?: number;
|
||||
};
|
||||
type IsNever<T> = [T] extends [never] ? true : false;
|
||||
export type IsExact<T, U> = (<G>() => G extends T ? 1 : 2) extends <G>() => G extends U ? 1 : 2 ? IsNever<Exclude<keyof T, keyof U>> extends true ? IsNever<Exclude<keyof U, keyof T>> extends true ? true : false : false : false;
|
||||
export {};
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
Generated
Vendored
+58
@@ -0,0 +1,58 @@
|
||||
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;
|
||||
};
|
||||
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;
|
||||
};
|
||||
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 {};
|
||||
Generated
Vendored
+330
@@ -0,0 +1,330 @@
|
||||
"use strict";
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || (function () {
|
||||
var ownKeys = function(o) {
|
||||
ownKeys = Object.getOwnPropertyNames || function (o) {
|
||||
var ar = [];
|
||||
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
||||
return ar;
|
||||
};
|
||||
return ownKeys(o);
|
||||
};
|
||||
return function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.useSharedAudio = exports.SharedAudioContextProvider = exports.SharedAudioContext = void 0;
|
||||
const jsx_runtime_1 = require("react/jsx-runtime");
|
||||
const react_1 = __importStar(require("react"));
|
||||
const log_level_context_js_1 = require("../log-level-context.js");
|
||||
const play_and_handle_not_allowed_error_js_1 = require("../play-and-handle-not-allowed-error.js");
|
||||
const use_remotion_environment_js_1 = require("../use-remotion-environment.js");
|
||||
const shared_element_source_node_js_1 = require("./shared-element-source-node.js");
|
||||
const use_audio_context_js_1 = require("./use-audio-context.js");
|
||||
const EMPTY_AUDIO = 'data:audio/mp3;base64,/+MYxAAJcAV8AAgAABn//////+/gQ5BAMA+D4Pg+BAQBAEAwD4Pg+D4EBAEAQDAPg++hYBH///hUFQVBUFREDQNHmf///////+MYxBUGkAGIMAAAAP/29Xt6lUxBTUUzLjEwMFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV/+MYxDUAAANIAAAAAFVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV';
|
||||
const compareProps = (obj1, obj2) => {
|
||||
const keysA = Object.keys(obj1).sort();
|
||||
const keysB = Object.keys(obj2).sort();
|
||||
if (keysA.length !== keysB.length) {
|
||||
return false;
|
||||
}
|
||||
for (let i = 0; i < keysA.length; i++) {
|
||||
// Not the same keys
|
||||
if (keysA[i] !== keysB[i]) {
|
||||
return false;
|
||||
}
|
||||
// Not the same values
|
||||
if (obj1[keysA[i]] !== obj2[keysB[i]]) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
const didPropChange = (key, newProp, prevProp) => {
|
||||
// /music.mp3 and http://localhost:3000/music.mp3 are the same
|
||||
if (key === 'src' &&
|
||||
!prevProp.startsWith('data:') &&
|
||||
!newProp.startsWith('data:')) {
|
||||
return (new URL(prevProp, window.origin).toString() !==
|
||||
new URL(newProp, window.origin).toString());
|
||||
}
|
||||
if (prevProp === newProp) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
exports.SharedAudioContext = (0, react_1.createContext)(null);
|
||||
const SharedAudioContextProvider = ({ children, numberOfAudioTags, audioLatencyHint, audioEnabled }) => {
|
||||
var _a;
|
||||
const audios = (0, react_1.useRef)([]);
|
||||
const [initialNumberOfAudioTags] = (0, react_1.useState)(numberOfAudioTags);
|
||||
if (numberOfAudioTags !== initialNumberOfAudioTags) {
|
||||
throw new Error('The number of shared audio tags has changed dynamically. Once you have set this property, you cannot change it afterwards.');
|
||||
}
|
||||
const logLevel = (0, log_level_context_js_1.useLogLevel)();
|
||||
const audioContext = (0, use_audio_context_js_1.useSingletonAudioContext)({
|
||||
logLevel,
|
||||
latencyHint: audioLatencyHint,
|
||||
audioEnabled,
|
||||
});
|
||||
const refs = (0, react_1.useMemo)(() => {
|
||||
return new Array(numberOfAudioTags).fill(true).map(() => {
|
||||
const ref = (0, react_1.createRef)();
|
||||
return {
|
||||
id: Math.random(),
|
||||
ref,
|
||||
mediaElementSourceNode: audioContext
|
||||
? (0, shared_element_source_node_js_1.makeSharedElementSourceNode)({
|
||||
audioContext,
|
||||
ref,
|
||||
})
|
||||
: null,
|
||||
};
|
||||
});
|
||||
}, [audioContext, numberOfAudioTags]);
|
||||
/**
|
||||
* Effects in React 18 fire twice, and we are looking for a way to only fire it once.
|
||||
* - useInsertionEffect only fires once. If it's available we are in React 18.
|
||||
* - useLayoutEffect only fires once in React 17.
|
||||
*
|
||||
* Need to import it from React to fix React 17 ESM support.
|
||||
*/
|
||||
const effectToUse = (_a = react_1.default.useInsertionEffect) !== null && _a !== void 0 ? _a : react_1.default.useLayoutEffect;
|
||||
// Disconnecting the SharedElementSourceNodes if the Player unmounts to prevent leak.
|
||||
// https://github.com/remotion-dev/remotion/issues/6285
|
||||
// But useInsertionEffect will fire before other effects, meaning the
|
||||
// nodes might still be used. Using rAF to ensure it's after other effects.
|
||||
effectToUse(() => {
|
||||
return () => {
|
||||
requestAnimationFrame(() => {
|
||||
refs.forEach(({ mediaElementSourceNode }) => {
|
||||
mediaElementSourceNode === null || mediaElementSourceNode === void 0 ? void 0 : mediaElementSourceNode.cleanup();
|
||||
});
|
||||
});
|
||||
};
|
||||
}, [refs]);
|
||||
const takenAudios = (0, react_1.useRef)(new Array(numberOfAudioTags).fill(false));
|
||||
const rerenderAudios = (0, react_1.useCallback)(() => {
|
||||
refs.forEach(({ ref, id }) => {
|
||||
var _a;
|
||||
const data = (_a = audios.current) === null || _a === void 0 ? void 0 : _a.find((a) => a.id === id);
|
||||
const { current } = ref;
|
||||
if (!current) {
|
||||
// Whole player has been unmounted, the refs don't exist anymore.
|
||||
// It is not an error anymore though
|
||||
return;
|
||||
}
|
||||
if (data === undefined) {
|
||||
current.src = EMPTY_AUDIO;
|
||||
return;
|
||||
}
|
||||
if (!data) {
|
||||
throw new TypeError('Expected audio data to be there');
|
||||
}
|
||||
Object.keys(data.props).forEach((key) => {
|
||||
// @ts-expect-error
|
||||
if (didPropChange(key, data.props[key], current[key])) {
|
||||
// @ts-expect-error
|
||||
current[key] = data.props[key];
|
||||
}
|
||||
});
|
||||
});
|
||||
}, [refs]);
|
||||
const registerAudio = (0, react_1.useCallback)((options) => {
|
||||
var _a, _b;
|
||||
const { aud, audioId, premounting, postmounting } = options;
|
||||
const found = (_a = audios.current) === null || _a === void 0 ? void 0 : _a.find((a) => a.audioId === audioId);
|
||||
if (found) {
|
||||
return found;
|
||||
}
|
||||
const firstFreeAudio = takenAudios.current.findIndex((a) => a === false);
|
||||
if (firstFreeAudio === -1) {
|
||||
throw new Error(`Tried to simultaneously mount ${numberOfAudioTags + 1} <Html5Audio /> tags at the same time. With the current settings, the maximum amount of <Html5Audio /> tags is limited to ${numberOfAudioTags} at the same time. Remotion pre-mounts silent audio tags to help avoid browser autoplay restrictions. See https://remotion.dev/docs/player/autoplay#using-the-numberofsharedaudiotags-prop for more information on how to increase this limit.`);
|
||||
}
|
||||
const { id, ref, mediaElementSourceNode } = refs[firstFreeAudio];
|
||||
const cloned = [...takenAudios.current];
|
||||
cloned[firstFreeAudio] = id;
|
||||
takenAudios.current = cloned;
|
||||
const newElem = {
|
||||
props: aud,
|
||||
id,
|
||||
el: ref,
|
||||
audioId,
|
||||
mediaElementSourceNode,
|
||||
premounting,
|
||||
audioMounted: Boolean(ref.current),
|
||||
postmounting,
|
||||
cleanupOnMediaTagUnmount: () => {
|
||||
// Don't disconnect here, only when the Player unmounts.
|
||||
},
|
||||
};
|
||||
(_b = audios.current) === null || _b === void 0 ? void 0 : _b.push(newElem);
|
||||
rerenderAudios();
|
||||
return newElem;
|
||||
}, [numberOfAudioTags, refs, rerenderAudios]);
|
||||
const unregisterAudio = (0, react_1.useCallback)((id) => {
|
||||
var _a;
|
||||
const cloned = [...takenAudios.current];
|
||||
const index = refs.findIndex((r) => r.id === id);
|
||||
if (index === -1) {
|
||||
throw new TypeError('Error occured in ');
|
||||
}
|
||||
cloned[index] = false;
|
||||
takenAudios.current = cloned;
|
||||
audios.current = (_a = audios.current) === null || _a === void 0 ? void 0 : _a.filter((a) => a.id !== id);
|
||||
rerenderAudios();
|
||||
}, [refs, rerenderAudios]);
|
||||
const updateAudio = (0, react_1.useCallback)(({ aud, audioId, id, premounting, postmounting, }) => {
|
||||
var _a;
|
||||
let changed = false;
|
||||
audios.current = (_a = audios.current) === null || _a === void 0 ? void 0 : _a.map((prevA) => {
|
||||
const audioMounted = Boolean(prevA.el.current);
|
||||
if (prevA.audioMounted !== audioMounted) {
|
||||
changed = true;
|
||||
}
|
||||
if (prevA.id === id) {
|
||||
const isTheSame = compareProps(aud, prevA.props) &&
|
||||
prevA.premounting === premounting &&
|
||||
prevA.postmounting === postmounting;
|
||||
if (isTheSame) {
|
||||
return prevA;
|
||||
}
|
||||
changed = true;
|
||||
return {
|
||||
...prevA,
|
||||
props: aud,
|
||||
premounting,
|
||||
postmounting,
|
||||
audioId,
|
||||
audioMounted,
|
||||
};
|
||||
}
|
||||
return prevA;
|
||||
});
|
||||
if (changed) {
|
||||
rerenderAudios();
|
||||
}
|
||||
}, [rerenderAudios]);
|
||||
const mountTime = (0, log_level_context_js_1.useMountTime)();
|
||||
const env = (0, use_remotion_environment_js_1.useRemotionEnvironment)();
|
||||
const playAllAudios = (0, react_1.useCallback)(() => {
|
||||
refs.forEach((ref) => {
|
||||
const audio = audios.current.find((a) => a.el === ref.ref);
|
||||
if (audio === null || audio === void 0 ? void 0 : audio.premounting) {
|
||||
return;
|
||||
}
|
||||
(0, play_and_handle_not_allowed_error_js_1.playAndHandleNotAllowedError)({
|
||||
mediaRef: ref.ref,
|
||||
mediaType: 'audio',
|
||||
onAutoPlayError: null,
|
||||
logLevel,
|
||||
mountTime,
|
||||
reason: 'playing all audios',
|
||||
isPlayer: env.isPlayer,
|
||||
});
|
||||
});
|
||||
audioContext === null || audioContext === void 0 ? void 0 : audioContext.resume();
|
||||
}, [audioContext, logLevel, mountTime, refs, env.isPlayer]);
|
||||
const value = (0, react_1.useMemo)(() => {
|
||||
return {
|
||||
registerAudio,
|
||||
unregisterAudio,
|
||||
updateAudio,
|
||||
playAllAudios,
|
||||
numberOfAudioTags,
|
||||
audioContext,
|
||||
};
|
||||
}, [
|
||||
numberOfAudioTags,
|
||||
playAllAudios,
|
||||
registerAudio,
|
||||
unregisterAudio,
|
||||
updateAudio,
|
||||
audioContext,
|
||||
]);
|
||||
return ((0, jsx_runtime_1.jsxs)(exports.SharedAudioContext.Provider, { value: value, children: [refs.map(({ id, ref }) => {
|
||||
return (
|
||||
// Without preload="metadata", iOS will seek the time internally
|
||||
// but not actually with sound. Adding `preload="metadata"` helps here.
|
||||
// https://discord.com/channels/809501355504959528/817306414069710848/1130519583367888906
|
||||
(0, jsx_runtime_1.jsx)("audio", { ref: ref, preload: "metadata", src: EMPTY_AUDIO }, id));
|
||||
}), children] }));
|
||||
};
|
||||
exports.SharedAudioContextProvider = SharedAudioContextProvider;
|
||||
const useSharedAudio = ({ aud, audioId, premounting, postmounting, }) => {
|
||||
var _a;
|
||||
const ctx = (0, react_1.useContext)(exports.SharedAudioContext);
|
||||
/**
|
||||
* We work around this in React 18 so an audio tag will only register itself once
|
||||
*/
|
||||
const [elem] = (0, react_1.useState)(() => {
|
||||
if (ctx && ctx.numberOfAudioTags > 0) {
|
||||
return ctx.registerAudio({ aud, audioId, premounting, postmounting });
|
||||
}
|
||||
// numberOfSharedAudioTags is 0
|
||||
const el = react_1.default.createRef();
|
||||
const mediaElementSourceNode = (ctx === null || ctx === void 0 ? void 0 : ctx.audioContext)
|
||||
? (0, shared_element_source_node_js_1.makeSharedElementSourceNode)({
|
||||
audioContext: ctx.audioContext,
|
||||
ref: el,
|
||||
})
|
||||
: null;
|
||||
return {
|
||||
el,
|
||||
id: Math.random(),
|
||||
props: aud,
|
||||
audioId,
|
||||
mediaElementSourceNode,
|
||||
premounting,
|
||||
audioMounted: Boolean(el.current),
|
||||
postmounting,
|
||||
cleanupOnMediaTagUnmount: () => {
|
||||
mediaElementSourceNode === null || mediaElementSourceNode === void 0 ? void 0 : mediaElementSourceNode.cleanup();
|
||||
},
|
||||
};
|
||||
});
|
||||
/**
|
||||
* Effects in React 18 fire twice, and we are looking for a way to only fire it once.
|
||||
* - useInsertionEffect only fires once. If it's available we are in React 18.
|
||||
* - useLayoutEffect only fires once in React 17.
|
||||
*
|
||||
* Need to import it from React to fix React 17 ESM support.
|
||||
*/
|
||||
const effectToUse = (_a = react_1.default.useInsertionEffect) !== null && _a !== void 0 ? _a : react_1.default.useLayoutEffect;
|
||||
if (typeof document !== 'undefined') {
|
||||
effectToUse(() => {
|
||||
if (ctx && ctx.numberOfAudioTags > 0) {
|
||||
ctx.updateAudio({ id: elem.id, aud, audioId, premounting, postmounting });
|
||||
}
|
||||
}, [aud, ctx, elem.id, audioId, premounting, postmounting]);
|
||||
effectToUse(() => {
|
||||
return () => {
|
||||
if (ctx && ctx.numberOfAudioTags > 0) {
|
||||
ctx.unregisterAudio(elem.id);
|
||||
}
|
||||
};
|
||||
}, [ctx, elem.id]);
|
||||
}
|
||||
return elem;
|
||||
};
|
||||
exports.useSharedAudio = useSharedAudio;
|
||||
Generated
Vendored
+9
@@ -0,0 +1,9 @@
|
||||
export declare const makeSharedElementSourceNode: ({ audioContext, ref, }: {
|
||||
audioContext: AudioContext;
|
||||
ref: React.RefObject<HTMLAudioElement | null>;
|
||||
}) => {
|
||||
attemptToConnect: () => void;
|
||||
get: () => MediaElementAudioSourceNode;
|
||||
cleanup: () => void;
|
||||
};
|
||||
export type SharedElementSourceNode = ReturnType<typeof makeSharedElementSourceNode>;
|
||||
Generated
Vendored
+33
@@ -0,0 +1,33 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.makeSharedElementSourceNode = void 0;
|
||||
const makeSharedElementSourceNode = ({ audioContext, ref, }) => {
|
||||
let connected = null;
|
||||
let disposed = false;
|
||||
// We must allow this to cleanup and create a new one due to strict mode.
|
||||
return {
|
||||
attemptToConnect: () => {
|
||||
if (disposed) {
|
||||
throw new Error('SharedElementSourceNode has been disposed');
|
||||
}
|
||||
if (!connected && ref.current) {
|
||||
const mediaElementSourceNode = audioContext.createMediaElementSource(ref.current);
|
||||
connected = mediaElementSourceNode;
|
||||
}
|
||||
},
|
||||
get: () => {
|
||||
if (!connected) {
|
||||
throw new Error('Audio element not connected');
|
||||
}
|
||||
return connected;
|
||||
},
|
||||
cleanup: () => {
|
||||
if (connected) {
|
||||
connected.disconnect();
|
||||
connected = null;
|
||||
}
|
||||
disposed = true;
|
||||
},
|
||||
};
|
||||
};
|
||||
exports.makeSharedElementSourceNode = makeSharedElementSourceNode;
|
||||
Generated
Vendored
+6
@@ -0,0 +1,6 @@
|
||||
import type { LogLevel } from '../log';
|
||||
export declare const useSingletonAudioContext: ({ logLevel, latencyHint, audioEnabled, }: {
|
||||
logLevel: LogLevel;
|
||||
latencyHint: AudioContextLatencyCategory;
|
||||
audioEnabled: boolean;
|
||||
}) => AudioContext | null;
|
||||
Generated
Vendored
+41
@@ -0,0 +1,41 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.useSingletonAudioContext = void 0;
|
||||
const react_1 = require("react");
|
||||
const log_1 = require("../log");
|
||||
const use_remotion_environment_1 = require("../use-remotion-environment");
|
||||
let warned = false;
|
||||
const warnOnce = (logLevel) => {
|
||||
if (warned) {
|
||||
return;
|
||||
}
|
||||
warned = true;
|
||||
// Don't pullute logs if in SSR
|
||||
if (typeof window !== 'undefined') {
|
||||
log_1.Log.warn({ logLevel, tag: null }, 'AudioContext is not supported in this browser');
|
||||
}
|
||||
};
|
||||
const useSingletonAudioContext = ({ logLevel, latencyHint, audioEnabled, }) => {
|
||||
const env = (0, use_remotion_environment_1.useRemotionEnvironment)();
|
||||
const audioContext = (0, react_1.useMemo)(() => {
|
||||
if (env.isRendering) {
|
||||
return null;
|
||||
}
|
||||
if (!audioEnabled) {
|
||||
return null;
|
||||
}
|
||||
if (typeof AudioContext === 'undefined') {
|
||||
warnOnce(logLevel);
|
||||
return null;
|
||||
}
|
||||
return new AudioContext({
|
||||
latencyHint,
|
||||
// By default, this can end up being 44100Hz.
|
||||
// Playing a 48000Hz file in a 44100Hz context, such as https://remotion.media/video.mp4 in a @remotion/media tag
|
||||
// we observe some issues that seem to go away when we set the sample rate to 48000 with Sony LinkBuds Bluetooth headphones.
|
||||
sampleRate: 48000,
|
||||
});
|
||||
}, [logLevel, latencyHint, env.isRendering, audioEnabled]);
|
||||
return audioContext;
|
||||
};
|
||||
exports.useSingletonAudioContext = useSingletonAudioContext;
|
||||
Generated
Vendored
+7
@@ -0,0 +1,7 @@
|
||||
export declare const useMediaStartsAt: () => number;
|
||||
export type LoopVolumeCurveBehavior = 'repeat' | 'extend';
|
||||
/**
|
||||
* When passing a function as the prop for `volume`,
|
||||
* we calculate the way more intuitive value for currentFrame
|
||||
*/
|
||||
export declare const useFrameForVolumeProp: (behavior: LoopVolumeCurveBehavior) => number;
|
||||
Generated
Vendored
+28
@@ -0,0 +1,28 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.useFrameForVolumeProp = exports.useMediaStartsAt = void 0;
|
||||
const react_1 = require("react");
|
||||
const SequenceContext_js_1 = require("../SequenceContext.js");
|
||||
const index_js_1 = require("../loop/index.js");
|
||||
const use_current_frame_js_1 = require("../use-current-frame.js");
|
||||
const useMediaStartsAt = () => {
|
||||
var _a;
|
||||
const parentSequence = (0, react_1.useContext)(SequenceContext_js_1.SequenceContext);
|
||||
const startsAt = Math.min(0, (_a = parentSequence === null || parentSequence === void 0 ? void 0 : parentSequence.relativeFrom) !== null && _a !== void 0 ? _a : 0);
|
||||
return startsAt;
|
||||
};
|
||||
exports.useMediaStartsAt = useMediaStartsAt;
|
||||
/**
|
||||
* When passing a function as the prop for `volume`,
|
||||
* we calculate the way more intuitive value for currentFrame
|
||||
*/
|
||||
const useFrameForVolumeProp = (behavior) => {
|
||||
const loop = index_js_1.Loop.useLoop();
|
||||
const frame = (0, use_current_frame_js_1.useCurrentFrame)();
|
||||
const startsAt = (0, exports.useMediaStartsAt)();
|
||||
if (behavior === 'repeat' || loop === null) {
|
||||
return frame + startsAt;
|
||||
}
|
||||
return frame + startsAt + loop.durationInFrames * loop.iteration;
|
||||
};
|
||||
exports.useFrameForVolumeProp = useFrameForVolumeProp;
|
||||
Reference in New Issue
Block a user