1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.Audio = void 0;
|
4 | const jsx_runtime_1 = require("react/jsx-runtime");
|
5 | const react_1 = require("react");
|
6 | const get_environment_1 = require("../get-environment");
|
7 | const sequencing_1 = require("../sequencing");
|
8 | const validate_media_props_1 = require("../validate-media-props");
|
9 | const validate_start_from_props_1 = require("../validate-start-from-props");
|
10 | const AudioForDevelopment_1 = require("./AudioForDevelopment");
|
11 | const AudioForRendering_1 = require("./AudioForRendering");
|
12 | const shared_audio_tags_1 = require("./shared-audio-tags");
|
13 | const AudioRefForwardingFunction = (props, ref) => {
|
14 | const audioContext = (0, react_1.useContext)(shared_audio_tags_1.SharedAudioContext);
|
15 | const { startFrom, endAt, ...otherProps } = props;
|
16 | const onError = (0, react_1.useCallback)((e) => {
|
17 | console.log(e.currentTarget.error);
|
18 | throw new Error(`Could not play audio with src ${otherProps.src}: ${e.currentTarget.error}`);
|
19 | }, [otherProps.src]);
|
20 | if (typeof startFrom !== 'undefined' || typeof endAt !== 'undefined') {
|
21 | (0, validate_start_from_props_1.validateStartFromProps)(startFrom, endAt);
|
22 | const startFromFrameNo = startFrom !== null && startFrom !== void 0 ? startFrom : 0;
|
23 | const endAtFrameNo = endAt !== null && endAt !== void 0 ? endAt : Infinity;
|
24 | return ((0, jsx_runtime_1.jsx)(sequencing_1.Sequence, { layout: "none", from: 0 - startFromFrameNo, showInTimeline: false, durationInFrames: endAtFrameNo, children: (0, jsx_runtime_1.jsx)(exports.Audio, { ...otherProps, ref: ref }, void 0) }, void 0));
|
25 | }
|
26 | (0, validate_media_props_1.validateMediaProps)(props, 'Audio');
|
27 | if ((0, get_environment_1.getRemotionEnvironment)() === 'rendering') {
|
28 | return (0, jsx_runtime_1.jsx)(AudioForRendering_1.AudioForRendering, { ...props, ref: ref, onError: onError }, void 0);
|
29 | }
|
30 | return ((0, jsx_runtime_1.jsx)(AudioForDevelopment_1.AudioForDevelopment, { shouldPreMountAudioTags: audioContext !== null && audioContext.numberOfAudioTags > 0, ...props, ref: ref, onError: onError }, void 0));
|
31 | };
|
32 | exports.Audio = (0, react_1.forwardRef)(AudioRefForwardingFunction);
|