1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.AudioForDevelopment = void 0;
|
4 | const jsx_runtime_1 = require("react/jsx-runtime");
|
5 | const react_1 = require("react");
|
6 | const use_media_in_timeline_1 = require("../use-media-in-timeline");
|
7 | const use_media_playback_1 = require("../use-media-playback");
|
8 | const use_media_tag_volume_1 = require("../use-media-tag-volume");
|
9 | const use_sync_volume_with_media_tag_1 = require("../use-sync-volume-with-media-tag");
|
10 | const volume_position_state_1 = require("../volume-position-state");
|
11 | const shared_audio_tags_1 = require("./shared-audio-tags");
|
12 | const use_audio_frame_1 = require("./use-audio-frame");
|
13 | const AudioForDevelopmentForwardRefFunction = (props, ref) => {
|
14 | const [initialShouldPreMountAudioElements] = (0, react_1.useState)(props.shouldPreMountAudioTags);
|
15 | if (props.shouldPreMountAudioTags !== initialShouldPreMountAudioElements) {
|
16 | throw new Error('Cannot change the behavior for pre-mounting audio tags dynamically.');
|
17 | }
|
18 | const [mediaVolume] = (0, volume_position_state_1.useMediaVolumeState)();
|
19 | const [mediaMuted] = (0, volume_position_state_1.useMediaMutedState)();
|
20 | const volumePropFrame = (0, use_audio_frame_1.useFrameForVolumeProp)();
|
21 | const { volume, muted, playbackRate, shouldPreMountAudioTags, ...nativeProps } = props;
|
22 | const propsToPass = (0, react_1.useMemo)(() => {
|
23 | return {
|
24 | muted: muted || mediaMuted,
|
25 | ...nativeProps,
|
26 | };
|
27 | }, [mediaMuted, muted, nativeProps]);
|
28 | const audioRef = (0, shared_audio_tags_1.useSharedAudio)(propsToPass).el;
|
29 | const actualVolume = (0, use_media_tag_volume_1.useMediaTagVolume)(audioRef);
|
30 | (0, use_sync_volume_with_media_tag_1.useSyncVolumeWithMediaTag)({
|
31 | volumePropFrame,
|
32 | actualVolume,
|
33 | volume,
|
34 | mediaVolume,
|
35 | mediaRef: audioRef,
|
36 | });
|
37 | (0, use_media_in_timeline_1.useMediaInTimeline)({
|
38 | volume,
|
39 | mediaVolume,
|
40 | mediaRef: audioRef,
|
41 | src: nativeProps.src,
|
42 | mediaType: 'audio',
|
43 | });
|
44 | (0, use_media_playback_1.useMediaPlayback)({
|
45 | mediaRef: audioRef,
|
46 | src: nativeProps.src,
|
47 | mediaType: 'audio',
|
48 | playbackRate: playbackRate !== null && playbackRate !== void 0 ? playbackRate : 1,
|
49 | });
|
50 | (0, react_1.useImperativeHandle)(ref, () => {
|
51 | return audioRef.current;
|
52 | });
|
53 | if (initialShouldPreMountAudioElements) {
|
54 | return null;
|
55 | }
|
56 | return (0, jsx_runtime_1.jsx)("audio", { ref: audioRef, ...propsToPass }, void 0);
|
57 | };
|
58 | exports.AudioForDevelopment = (0, react_1.forwardRef)(AudioForDevelopmentForwardRefFunction);
|