@remotion/player 4.0.540 → 4.0.542
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/calculate-next-frame.js +9 -0
- package/dist/cjs/index.d.ts +30 -0
- package/dist/cjs/index.js +2 -0
- package/dist/cjs/use-playback.js +23 -7
- package/dist/esm/index.mjs +1786 -1758
- package/package.json +4 -4
package/dist/esm/index.mjs
CHANGED
|
@@ -505,14 +505,139 @@ var PlayerEmitterProvider = ({ children, currentPlaybackRate }) => {
|
|
|
505
505
|
});
|
|
506
506
|
};
|
|
507
507
|
|
|
508
|
-
// src/
|
|
509
|
-
import
|
|
510
|
-
|
|
508
|
+
// src/PlayerControls.tsx
|
|
509
|
+
import { useCallback as useCallback7, useEffect as useEffect7, useMemo as useMemo9, useRef as useRef5, useState as useState9 } from "react";
|
|
510
|
+
|
|
511
|
+
// src/DefaultPlayPauseButton.tsx
|
|
512
|
+
import { jsx as jsx4 } from "react/jsx-runtime";
|
|
513
|
+
var DefaultPlayPauseButton = ({ playing, buffering }) => {
|
|
514
|
+
if (playing && buffering) {
|
|
515
|
+
return /* @__PURE__ */ jsx4(BufferingIndicator, {
|
|
516
|
+
type: "player"
|
|
517
|
+
});
|
|
518
|
+
}
|
|
519
|
+
if (playing) {
|
|
520
|
+
return /* @__PURE__ */ jsx4(PauseIcon, {});
|
|
521
|
+
}
|
|
522
|
+
return /* @__PURE__ */ jsx4(PlayIcon, {});
|
|
523
|
+
};
|
|
524
|
+
|
|
525
|
+
// src/MediaVolumeSlider.tsx
|
|
526
|
+
import { useCallback as useCallback2, useMemo as useMemo2, useRef, useState as useState4 } from "react";
|
|
527
|
+
import { Internals as Internals3 } from "remotion";
|
|
528
|
+
|
|
529
|
+
// src/render-volume-slider.tsx
|
|
530
|
+
import React3, { useCallback, useMemo, useState as useState2 } from "react";
|
|
531
|
+
import { random } from "remotion";
|
|
532
|
+
import { jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
533
|
+
var KNOB_SIZE = 12;
|
|
534
|
+
var BAR_HEIGHT = 5;
|
|
535
|
+
var DefaultVolumeSlider = ({
|
|
536
|
+
volume,
|
|
537
|
+
isVertical,
|
|
538
|
+
onBlur,
|
|
539
|
+
inputRef,
|
|
540
|
+
setVolume
|
|
541
|
+
}) => {
|
|
542
|
+
const sliderContainer = useMemo(() => {
|
|
543
|
+
const paddingLeft = 5;
|
|
544
|
+
const common = {
|
|
545
|
+
paddingLeft,
|
|
546
|
+
height: ICON_SIZE,
|
|
547
|
+
width: VOLUME_SLIDER_WIDTH,
|
|
548
|
+
display: "inline-flex",
|
|
549
|
+
alignItems: "center"
|
|
550
|
+
};
|
|
551
|
+
if (isVertical) {
|
|
552
|
+
return {
|
|
553
|
+
...common,
|
|
554
|
+
position: "absolute",
|
|
555
|
+
transform: `rotate(-90deg) translateX(${VOLUME_SLIDER_WIDTH / 2 + ICON_SIZE / 2}px)`
|
|
556
|
+
};
|
|
557
|
+
}
|
|
558
|
+
return {
|
|
559
|
+
...common
|
|
560
|
+
};
|
|
561
|
+
}, [isVertical]);
|
|
562
|
+
const randomId = typeof React3.useId === "undefined" ? "volume-slider" : React3.useId();
|
|
563
|
+
const [randomClass] = useState2(() => `__remotion-volume-slider-${random(randomId)}`.replace(".", ""));
|
|
564
|
+
const onVolumeChange = useCallback((e) => {
|
|
565
|
+
setVolume(parseFloat(e.target.value));
|
|
566
|
+
}, [setVolume]);
|
|
567
|
+
const inputStyle = useMemo(() => {
|
|
568
|
+
const commonStyle = {
|
|
569
|
+
WebkitAppearance: "none",
|
|
570
|
+
backgroundColor: "rgba(255, 255, 255, 0.5)",
|
|
571
|
+
borderRadius: BAR_HEIGHT / 2,
|
|
572
|
+
cursor: "pointer",
|
|
573
|
+
height: BAR_HEIGHT,
|
|
574
|
+
width: VOLUME_SLIDER_WIDTH,
|
|
575
|
+
backgroundImage: `linear-gradient(
|
|
576
|
+
to right,
|
|
577
|
+
white ${volume * 100}%, rgba(255, 255, 255, 0) ${volume * 100}%
|
|
578
|
+
)`
|
|
579
|
+
};
|
|
580
|
+
if (isVertical) {
|
|
581
|
+
return {
|
|
582
|
+
...commonStyle,
|
|
583
|
+
bottom: ICON_SIZE + VOLUME_SLIDER_WIDTH / 2
|
|
584
|
+
};
|
|
585
|
+
}
|
|
586
|
+
return commonStyle;
|
|
587
|
+
}, [isVertical, volume]);
|
|
588
|
+
const sliderStyle = `
|
|
589
|
+
.${randomClass}::-webkit-slider-thumb {
|
|
590
|
+
-webkit-appearance: none;
|
|
591
|
+
background-color: white;
|
|
592
|
+
border-radius: ${KNOB_SIZE / 2}px;
|
|
593
|
+
box-shadow: 0 0 2px black;
|
|
594
|
+
height: ${KNOB_SIZE}px;
|
|
595
|
+
width: ${KNOB_SIZE}px;
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
.${randomClass}::-moz-range-thumb {
|
|
599
|
+
-webkit-appearance: none;
|
|
600
|
+
background-color: white;
|
|
601
|
+
border-radius: ${KNOB_SIZE / 2}px;
|
|
602
|
+
box-shadow: 0 0 2px black;
|
|
603
|
+
height: ${KNOB_SIZE}px;
|
|
604
|
+
width: ${KNOB_SIZE}px;
|
|
605
|
+
}
|
|
606
|
+
`;
|
|
607
|
+
return /* @__PURE__ */ jsxs3("div", {
|
|
608
|
+
style: sliderContainer,
|
|
609
|
+
children: [
|
|
610
|
+
/* @__PURE__ */ jsx5("style", {
|
|
611
|
+
dangerouslySetInnerHTML: {
|
|
612
|
+
__html: sliderStyle
|
|
613
|
+
}
|
|
614
|
+
}),
|
|
615
|
+
/* @__PURE__ */ jsx5("input", {
|
|
616
|
+
ref: inputRef,
|
|
617
|
+
"aria-label": "Change volume",
|
|
618
|
+
className: randomClass,
|
|
619
|
+
max: 1,
|
|
620
|
+
min: 0,
|
|
621
|
+
onBlur,
|
|
622
|
+
onChange: onVolumeChange,
|
|
623
|
+
step: 0.01,
|
|
624
|
+
type: "range",
|
|
625
|
+
value: volume,
|
|
626
|
+
style: inputStyle
|
|
627
|
+
})
|
|
628
|
+
]
|
|
629
|
+
});
|
|
630
|
+
};
|
|
631
|
+
var renderDefaultVolumeSlider = (props) => {
|
|
632
|
+
return /* @__PURE__ */ jsx5(DefaultVolumeSlider, {
|
|
633
|
+
...props
|
|
634
|
+
});
|
|
635
|
+
};
|
|
511
636
|
|
|
512
637
|
// src/use-hover-state.ts
|
|
513
|
-
import { useEffect as useEffect2, useState as
|
|
638
|
+
import { useEffect as useEffect2, useState as useState3 } from "react";
|
|
514
639
|
var useHoverState = (ref, hideControlsWhenPointerDoesntMove) => {
|
|
515
|
-
const [hovered, setHovered] =
|
|
640
|
+
const [hovered, setHovered] = useState3(false);
|
|
516
641
|
useEffect2(() => {
|
|
517
642
|
const { current } = ref;
|
|
518
643
|
if (!current) {
|
|
@@ -552,747 +677,574 @@ var useHoverState = (ref, hideControlsWhenPointerDoesntMove) => {
|
|
|
552
677
|
return hovered;
|
|
553
678
|
};
|
|
554
679
|
|
|
555
|
-
// src/
|
|
556
|
-
import {
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
const {
|
|
570
|
-
setPlaying,
|
|
571
|
-
frameRef,
|
|
572
|
-
audioAndVideoTags,
|
|
573
|
-
isPlaying: readIsPlaying,
|
|
574
|
-
isBuffering
|
|
575
|
-
} = useContext2(Internals3.SetTimelineContext);
|
|
576
|
-
const audioContext = useContext2(Internals3.SharedAudioContext);
|
|
577
|
-
const audioTagsContext = useContext2(Internals3.SharedAudioTagsContext);
|
|
578
|
-
const { playerMuted, mediaVolume } = useContext2(Internals3.MediaVolumeContext);
|
|
579
|
-
const muted = playerMuted || mediaVolume === 0;
|
|
580
|
-
const environment = useRemotionEnvironment();
|
|
581
|
-
const video = Internals3.useVideo();
|
|
582
|
-
const videoId = video?.id ?? null;
|
|
583
|
-
const videoDurationInFrames = video?.durationInFrames ?? null;
|
|
584
|
-
const config = Internals3.useUnsafeVideoConfig();
|
|
585
|
-
const emitter = useContext2(PlayerEventEmitterContext);
|
|
586
|
-
const playStart = useRef(0);
|
|
587
|
-
const fallbackFrame = useRef(null);
|
|
588
|
-
const nextPlayIsAutoPlayAttempt = useRef(false);
|
|
589
|
-
if (!emitter) {
|
|
590
|
-
throw new TypeError("Expected Player event emitter context");
|
|
591
|
-
}
|
|
592
|
-
const getCurrentFrame = useCallback(() => {
|
|
593
|
-
if (videoId === null || videoDurationInFrames === null) {
|
|
594
|
-
return fallbackFrame.current ?? (typeof window === "undefined" ? 0 : window.remotion_initialFrame ?? 0);
|
|
595
|
-
}
|
|
596
|
-
const unclamped = frameRef.current[videoId] ?? (environment.isPlayer ? 0 : Internals3.Timeline.getFrameForComposition(videoId));
|
|
597
|
-
return Internals3.Timeline.clampFrameToCompositionRange(unclamped, videoDurationInFrames);
|
|
598
|
-
}, [environment.isPlayer, frameRef, videoId, videoDurationInFrames]);
|
|
599
|
-
const seek = useCallback((newFrame) => {
|
|
600
|
-
const frameToSeekTo = config ? Internals3.TimelinePosition.clampFrameToCompositionRange(newFrame, config.durationInFrames) : Math.max(0, newFrame);
|
|
601
|
-
fallbackFrame.current = frameToSeekTo;
|
|
602
|
-
if (video?.id) {
|
|
603
|
-
seekFrame((currentFrames) => currentFrames[video.id] === frameToSeekTo ? currentFrames : { ...currentFrames, [video.id]: frameToSeekTo });
|
|
604
|
-
if (frameRef.current[video.id] !== frameToSeekTo) {
|
|
605
|
-
frameRef.current = {
|
|
606
|
-
...frameRef.current,
|
|
607
|
-
[video.id]: frameToSeekTo
|
|
608
|
-
};
|
|
680
|
+
// src/MediaVolumeSlider.tsx
|
|
681
|
+
import { jsx as jsx6, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
682
|
+
var VOLUME_SLIDER_WIDTH = 100;
|
|
683
|
+
var MediaVolumeSlider = ({ displayVerticalVolumeSlider, renderMuteButton, renderVolumeSlider }) => {
|
|
684
|
+
const [playerMuted, setPlayerMuted] = Internals3.usePlayerMutedState();
|
|
685
|
+
const [mediaVolume, setMediaVolume] = Internals3.useMediaVolumeState();
|
|
686
|
+
const [focused, setFocused] = useState4(false);
|
|
687
|
+
const parentDivRef = useRef(null);
|
|
688
|
+
const inputRef = useRef(null);
|
|
689
|
+
const hover = useHoverState(parentDivRef, false);
|
|
690
|
+
const onBlur = useCallback2(() => {
|
|
691
|
+
setTimeout(() => {
|
|
692
|
+
if (inputRef.current && document.activeElement !== inputRef.current) {
|
|
693
|
+
setFocused(false);
|
|
609
694
|
}
|
|
610
|
-
}
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
const
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
695
|
+
}, 10);
|
|
696
|
+
}, []);
|
|
697
|
+
const isVolume0 = mediaVolume === 0;
|
|
698
|
+
const onClick = useCallback2(() => {
|
|
699
|
+
if (isVolume0) {
|
|
700
|
+
setMediaVolume(1);
|
|
701
|
+
setPlayerMuted(false);
|
|
617
702
|
return;
|
|
618
703
|
}
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
704
|
+
setPlayerMuted((mute) => !mute);
|
|
705
|
+
}, [isVolume0, setPlayerMuted, setMediaVolume]);
|
|
706
|
+
const parentDivStyle = useMemo2(() => {
|
|
707
|
+
return {
|
|
708
|
+
display: "inline-flex",
|
|
709
|
+
background: "none",
|
|
710
|
+
border: "none",
|
|
711
|
+
justifyContent: "center",
|
|
712
|
+
alignItems: "center",
|
|
713
|
+
touchAction: "none",
|
|
714
|
+
...displayVerticalVolumeSlider && { position: "relative" }
|
|
715
|
+
};
|
|
716
|
+
}, [displayVerticalVolumeSlider]);
|
|
717
|
+
const volumeContainer = useMemo2(() => {
|
|
718
|
+
return {
|
|
719
|
+
display: "inline",
|
|
720
|
+
width: ICON_SIZE,
|
|
721
|
+
height: ICON_SIZE,
|
|
722
|
+
cursor: "pointer",
|
|
723
|
+
appearance: "none",
|
|
724
|
+
background: "none",
|
|
725
|
+
border: "none",
|
|
726
|
+
padding: 0
|
|
727
|
+
};
|
|
728
|
+
}, []);
|
|
729
|
+
const renderDefaultMuteButton = useCallback2(({ muted, volume }) => {
|
|
730
|
+
const isMutedOrZero = muted || volume === 0;
|
|
731
|
+
return /* @__PURE__ */ jsx6("button", {
|
|
732
|
+
"aria-label": isMutedOrZero ? "Unmute sound" : "Mute sound",
|
|
733
|
+
title: isMutedOrZero ? "Unmute sound" : "Mute sound",
|
|
734
|
+
onClick,
|
|
735
|
+
onBlur,
|
|
736
|
+
onFocus: () => setFocused(true),
|
|
737
|
+
style: volumeContainer,
|
|
738
|
+
type: "button",
|
|
739
|
+
children: isMutedOrZero ? /* @__PURE__ */ jsx6(VolumeOffIcon, {}) : /* @__PURE__ */ jsx6(VolumeOnIcon, {})
|
|
740
|
+
});
|
|
741
|
+
}, [onBlur, onClick, volumeContainer]);
|
|
742
|
+
const muteButton = useMemo2(() => {
|
|
743
|
+
return renderMuteButton ? renderMuteButton({ muted: playerMuted, volume: mediaVolume }) : renderDefaultMuteButton({ muted: playerMuted, volume: mediaVolume });
|
|
744
|
+
}, [playerMuted, mediaVolume, renderDefaultMuteButton, renderMuteButton]);
|
|
745
|
+
const volumeSlider = useMemo2(() => {
|
|
746
|
+
return (focused || hover) && !playerMuted && !Internals3.isIosSafari() ? (renderVolumeSlider ?? renderDefaultVolumeSlider)({
|
|
747
|
+
isVertical: displayVerticalVolumeSlider,
|
|
748
|
+
volume: mediaVolume,
|
|
749
|
+
onBlur: () => setFocused(false),
|
|
750
|
+
inputRef,
|
|
751
|
+
setVolume: setMediaVolume
|
|
752
|
+
}) : null;
|
|
637
753
|
}, [
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
readIsPlaying,
|
|
646
|
-
seek,
|
|
647
|
-
setPlaying
|
|
754
|
+
displayVerticalVolumeSlider,
|
|
755
|
+
focused,
|
|
756
|
+
hover,
|
|
757
|
+
playerMuted,
|
|
758
|
+
mediaVolume,
|
|
759
|
+
renderVolumeSlider,
|
|
760
|
+
setMediaVolume
|
|
648
761
|
]);
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
};
|
|
673
|
-
emitter.dispatchPause();
|
|
762
|
+
return /* @__PURE__ */ jsxs4("div", {
|
|
763
|
+
ref: parentDivRef,
|
|
764
|
+
style: parentDivStyle,
|
|
765
|
+
children: [
|
|
766
|
+
muteButton,
|
|
767
|
+
volumeSlider
|
|
768
|
+
]
|
|
769
|
+
});
|
|
770
|
+
};
|
|
771
|
+
|
|
772
|
+
// src/PlaybackrateControl.tsx
|
|
773
|
+
import { useCallback as useCallback3, useEffect as useEffect4, useMemo as useMemo3, useState as useState6 } from "react";
|
|
774
|
+
import { Internals as Internals4 } from "remotion";
|
|
775
|
+
|
|
776
|
+
// src/utils/use-component-visible.ts
|
|
777
|
+
import { useEffect as useEffect3, useRef as useRef2, useState as useState5 } from "react";
|
|
778
|
+
function useComponentVisible(initialIsVisible) {
|
|
779
|
+
const [isComponentVisible, setIsComponentVisible] = useState5(initialIsVisible);
|
|
780
|
+
const ref = useRef2(null);
|
|
781
|
+
useEffect3(() => {
|
|
782
|
+
const handleClickOutside = (event) => {
|
|
783
|
+
if (ref.current && !ref.current.contains(event.target)) {
|
|
784
|
+
setIsComponentVisible(false);
|
|
674
785
|
}
|
|
675
|
-
}
|
|
676
|
-
}, [config, emitter, frameRef, readIsPlaying, setPlaying, seekFrame]);
|
|
677
|
-
const lastFrame = (config?.durationInFrames ?? 1) - 1;
|
|
678
|
-
const frameBack = useCallback((frames) => {
|
|
679
|
-
if (!videoId) {
|
|
680
|
-
return null;
|
|
681
|
-
}
|
|
682
|
-
if (readIsPlaying()) {
|
|
683
|
-
return;
|
|
684
|
-
}
|
|
685
|
-
const previousFrame = frameRef.current[videoId] ?? window.remotion_initialFrame ?? 0;
|
|
686
|
-
const newFrame = Math.max(0, previousFrame - frames);
|
|
687
|
-
if (previousFrame === newFrame) {
|
|
688
|
-
return;
|
|
689
|
-
}
|
|
690
|
-
seekFrame((currentFrames) => currentFrames[videoId] === newFrame ? currentFrames : { ...currentFrames, [videoId]: newFrame });
|
|
691
|
-
frameRef.current = {
|
|
692
|
-
...frameRef.current,
|
|
693
|
-
[videoId]: newFrame
|
|
694
786
|
};
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
return null;
|
|
699
|
-
}
|
|
700
|
-
if (readIsPlaying()) {
|
|
701
|
-
return;
|
|
702
|
-
}
|
|
703
|
-
const previousFrame = frameRef.current[videoId] ?? window.remotion_initialFrame ?? 0;
|
|
704
|
-
const newFrame = Math.min(lastFrame, previousFrame + frames);
|
|
705
|
-
if (previousFrame === newFrame) {
|
|
706
|
-
return;
|
|
707
|
-
}
|
|
708
|
-
seekFrame((currentFrames) => currentFrames[videoId] === newFrame ? currentFrames : { ...currentFrames, [videoId]: newFrame });
|
|
709
|
-
frameRef.current = {
|
|
710
|
-
...frameRef.current,
|
|
711
|
-
[videoId]: newFrame
|
|
787
|
+
document.addEventListener("pointerup", handleClickOutside, true);
|
|
788
|
+
return () => {
|
|
789
|
+
document.removeEventListener("pointerup", handleClickOutside, true);
|
|
712
790
|
};
|
|
713
|
-
}, [
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
791
|
+
}, []);
|
|
792
|
+
return { ref, isComponentVisible, setIsComponentVisible };
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
// src/PlaybackrateControl.tsx
|
|
796
|
+
import { jsx as jsx7, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
797
|
+
var BOTTOM = 35;
|
|
798
|
+
var THRESHOLD = 70;
|
|
799
|
+
var rateDiv = {
|
|
800
|
+
height: 30,
|
|
801
|
+
paddingRight: 15,
|
|
802
|
+
paddingLeft: 12,
|
|
803
|
+
display: "flex",
|
|
804
|
+
flexDirection: "row",
|
|
805
|
+
alignItems: "center"
|
|
806
|
+
};
|
|
807
|
+
var checkmarkContainer = {
|
|
808
|
+
width: 22,
|
|
809
|
+
display: "flex",
|
|
810
|
+
alignItems: "center"
|
|
811
|
+
};
|
|
812
|
+
var checkmarkStyle = {
|
|
813
|
+
width: 14,
|
|
814
|
+
height: 14,
|
|
815
|
+
color: "black"
|
|
816
|
+
};
|
|
817
|
+
var Checkmark = () => /* @__PURE__ */ jsx7("svg", {
|
|
818
|
+
viewBox: "0 0 512 512",
|
|
819
|
+
style: checkmarkStyle,
|
|
820
|
+
children: /* @__PURE__ */ jsx7("path", {
|
|
821
|
+
fill: "currentColor",
|
|
822
|
+
d: "M435.848 83.466L172.804 346.51l-96.652-96.652c-4.686-4.686-12.284-4.686-16.971 0l-28.284 28.284c-4.686 4.686-4.686 12.284 0 16.971l133.421 133.421c4.686 4.686 12.284 4.686 16.971 0l299.813-299.813c4.686-4.686 4.686-12.284 0-16.971l-28.284-28.284c-4.686-4.686-12.284-4.686-16.97 0z"
|
|
823
|
+
})
|
|
824
|
+
});
|
|
825
|
+
var formatPlaybackRate = (rate) => {
|
|
826
|
+
const str = rate.toString();
|
|
827
|
+
return str.includes(".") ? str : str + ".0";
|
|
828
|
+
};
|
|
829
|
+
var PlaybackrateOption = ({ rate, onSelect, selectedRate, keyboardSelectedRate }) => {
|
|
830
|
+
const onClick = useCallback3((e) => {
|
|
831
|
+
e.stopPropagation();
|
|
832
|
+
e.preventDefault();
|
|
833
|
+
onSelect(rate);
|
|
834
|
+
}, [onSelect, rate]);
|
|
835
|
+
const [hovered, setHovered] = useState6(false);
|
|
836
|
+
const onMouseEnter = useCallback3(() => {
|
|
837
|
+
setHovered(true);
|
|
838
|
+
}, []);
|
|
839
|
+
const onMouseLeave = useCallback3(() => {
|
|
840
|
+
setHovered(false);
|
|
841
|
+
}, []);
|
|
842
|
+
const isFocused = keyboardSelectedRate === rate;
|
|
843
|
+
const actualStyle = useMemo3(() => {
|
|
722
844
|
return {
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
emitter,
|
|
726
|
-
play,
|
|
727
|
-
playAsAutoPlay,
|
|
728
|
-
pause,
|
|
729
|
-
seek,
|
|
730
|
-
getCurrentFrame,
|
|
731
|
-
isPlaying: readIsPlaying,
|
|
732
|
-
isBuffering,
|
|
733
|
-
pauseAndReturnToPlayStart,
|
|
734
|
-
toggle
|
|
845
|
+
...rateDiv,
|
|
846
|
+
backgroundColor: hovered || isFocused ? "#eee" : "transparent"
|
|
735
847
|
};
|
|
736
|
-
}, [
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
848
|
+
}, [hovered, isFocused]);
|
|
849
|
+
return /* @__PURE__ */ jsxs5("div", {
|
|
850
|
+
onPointerEnter: onMouseEnter,
|
|
851
|
+
onPointerLeave: onMouseLeave,
|
|
852
|
+
tabIndex: 0,
|
|
853
|
+
style: actualStyle,
|
|
854
|
+
onClick,
|
|
855
|
+
children: [
|
|
856
|
+
/* @__PURE__ */ jsx7("div", {
|
|
857
|
+
style: checkmarkContainer,
|
|
858
|
+
children: rate === selectedRate ? /* @__PURE__ */ jsx7(Checkmark, {}) : null
|
|
859
|
+
}),
|
|
860
|
+
formatPlaybackRate(rate),
|
|
861
|
+
"x"
|
|
862
|
+
]
|
|
863
|
+
}, rate);
|
|
750
864
|
};
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
}) => {
|
|
758
|
-
const playing = Internals4.usePlaying();
|
|
759
|
-
const { pause, play, emitter, getCurrentFrame, seek } = usePlayerMethods();
|
|
760
|
-
const hasEverPlayed = useRef2(false);
|
|
761
|
-
useEffect3(() => {
|
|
762
|
-
if (playing) {
|
|
763
|
-
hasEverPlayed.current = true;
|
|
764
|
-
}
|
|
765
|
-
if (!navigator.mediaSession) {
|
|
766
|
-
return;
|
|
767
|
-
}
|
|
768
|
-
if (browserMediaControlsBehavior.mode === "do-nothing") {
|
|
769
|
-
return;
|
|
770
|
-
}
|
|
771
|
-
if (playing) {
|
|
772
|
-
navigator.mediaSession.playbackState = "playing";
|
|
773
|
-
} else if (hasEverPlayed.current) {
|
|
774
|
-
navigator.mediaSession.playbackState = "paused";
|
|
775
|
-
}
|
|
776
|
-
}, [browserMediaControlsBehavior.mode, playing]);
|
|
777
|
-
useEffect3(() => {
|
|
778
|
-
if (!navigator.mediaSession) {
|
|
779
|
-
return;
|
|
780
|
-
}
|
|
781
|
-
if (browserMediaControlsBehavior.mode === "do-nothing") {
|
|
782
|
-
return;
|
|
783
|
-
}
|
|
784
|
-
const onTimeUpdate = () => {
|
|
785
|
-
if (!videoConfig) {
|
|
865
|
+
var PlaybackPopup = ({ setIsComponentVisible, playbackRates, canvasSize }) => {
|
|
866
|
+
const { setPlaybackRate, playbackRate } = Internals4.usePlaybackRate();
|
|
867
|
+
const [keyboardSelectedRate, setKeyboardSelectedRate] = useState6(playbackRate);
|
|
868
|
+
useEffect4(() => {
|
|
869
|
+
const listener = (e) => {
|
|
870
|
+
if (e.ctrlKey || e.metaKey || e.altKey) {
|
|
786
871
|
return;
|
|
787
872
|
}
|
|
788
|
-
if (
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
}
|
|
873
|
+
if (e.key === "ArrowUp") {
|
|
874
|
+
e.preventDefault();
|
|
875
|
+
const currentIndex = playbackRates.findIndex((rate) => rate === keyboardSelectedRate);
|
|
876
|
+
if (currentIndex === 0) {
|
|
877
|
+
return;
|
|
878
|
+
}
|
|
879
|
+
if (currentIndex === -1) {
|
|
880
|
+
setKeyboardSelectedRate(playbackRates[0]);
|
|
881
|
+
} else {
|
|
882
|
+
setKeyboardSelectedRate(playbackRates[currentIndex - 1]);
|
|
883
|
+
}
|
|
884
|
+
} else if (e.key === "ArrowDown") {
|
|
885
|
+
e.preventDefault();
|
|
886
|
+
const currentIndex = playbackRates.findIndex((rate) => rate === keyboardSelectedRate);
|
|
887
|
+
if (currentIndex === playbackRates.length - 1) {
|
|
888
|
+
return;
|
|
889
|
+
}
|
|
890
|
+
if (currentIndex === -1) {
|
|
891
|
+
setKeyboardSelectedRate(playbackRates[playbackRates.length - 1]);
|
|
892
|
+
} else {
|
|
893
|
+
setKeyboardSelectedRate(playbackRates[currentIndex + 1]);
|
|
894
|
+
}
|
|
895
|
+
} else if (e.key === "Enter") {
|
|
896
|
+
e.preventDefault();
|
|
897
|
+
setPlaybackRate(keyboardSelectedRate);
|
|
898
|
+
setIsComponentVisible(false);
|
|
899
|
+
} else if (e.key === "Escape") {
|
|
900
|
+
e.preventDefault();
|
|
901
|
+
setIsComponentVisible(false);
|
|
902
|
+
} else if (e.key === "Tab") {
|
|
903
|
+
setIsComponentVisible(false);
|
|
794
904
|
}
|
|
795
905
|
};
|
|
796
|
-
|
|
906
|
+
window.addEventListener("keydown", listener);
|
|
797
907
|
return () => {
|
|
798
|
-
|
|
908
|
+
window.removeEventListener("keydown", listener);
|
|
799
909
|
};
|
|
800
910
|
}, [
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
videoConfig
|
|
911
|
+
playbackRates,
|
|
912
|
+
keyboardSelectedRate,
|
|
913
|
+
setPlaybackRate,
|
|
914
|
+
setIsComponentVisible
|
|
806
915
|
]);
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
});
|
|
824
|
-
navigator.mediaSession.setActionHandler("seekto", (event) => {
|
|
825
|
-
if (browserMediaControlsBehavior.mode === "register-media-session" && event.seekTime !== undefined && videoConfig) {
|
|
826
|
-
seek(Math.round(event.seekTime * videoConfig.fps));
|
|
827
|
-
}
|
|
828
|
-
});
|
|
829
|
-
navigator.mediaSession.setActionHandler("seekbackward", () => {
|
|
830
|
-
if (browserMediaControlsBehavior.mode === "register-media-session" && videoConfig) {
|
|
831
|
-
seek(Math.max(0, Math.round(getCurrentFrame() - 10 * videoConfig.fps)));
|
|
832
|
-
}
|
|
833
|
-
});
|
|
834
|
-
navigator.mediaSession.setActionHandler("seekforward", () => {
|
|
835
|
-
if (browserMediaControlsBehavior.mode === "register-media-session" && videoConfig) {
|
|
836
|
-
seek(Math.min(videoConfig.durationInFrames - 1, Math.round(getCurrentFrame() + 10 * videoConfig.fps)));
|
|
837
|
-
}
|
|
838
|
-
});
|
|
839
|
-
navigator.mediaSession.setActionHandler("previoustrack", () => {
|
|
840
|
-
if (browserMediaControlsBehavior.mode === "register-media-session") {
|
|
841
|
-
seek(0);
|
|
842
|
-
}
|
|
843
|
-
});
|
|
844
|
-
return () => {
|
|
845
|
-
navigator.mediaSession.metadata = null;
|
|
846
|
-
navigator.mediaSession.setActionHandler("play", null);
|
|
847
|
-
navigator.mediaSession.setActionHandler("pause", null);
|
|
848
|
-
navigator.mediaSession.setActionHandler("seekto", null);
|
|
849
|
-
navigator.mediaSession.setActionHandler("seekbackward", null);
|
|
850
|
-
navigator.mediaSession.setActionHandler("seekforward", null);
|
|
851
|
-
navigator.mediaSession.setActionHandler("previoustrack", null);
|
|
916
|
+
const onSelect = useCallback3((rate) => {
|
|
917
|
+
setPlaybackRate(rate);
|
|
918
|
+
setIsComponentVisible(false);
|
|
919
|
+
}, [setIsComponentVisible, setPlaybackRate]);
|
|
920
|
+
const playbackPopup = useMemo3(() => {
|
|
921
|
+
return {
|
|
922
|
+
position: "absolute",
|
|
923
|
+
right: 0,
|
|
924
|
+
width: 125,
|
|
925
|
+
maxHeight: canvasSize.height - THRESHOLD - BOTTOM,
|
|
926
|
+
bottom: 35,
|
|
927
|
+
background: "#fff",
|
|
928
|
+
borderRadius: 4,
|
|
929
|
+
overflow: "auto",
|
|
930
|
+
color: "black",
|
|
931
|
+
textAlign: "left"
|
|
852
932
|
};
|
|
853
|
-
}, [
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
933
|
+
}, [canvasSize.height]);
|
|
934
|
+
return /* @__PURE__ */ jsx7("div", {
|
|
935
|
+
style: playbackPopup,
|
|
936
|
+
children: playbackRates.map((rate) => {
|
|
937
|
+
return /* @__PURE__ */ jsx7(PlaybackrateOption, {
|
|
938
|
+
selectedRate: playbackRate,
|
|
939
|
+
onSelect,
|
|
940
|
+
rate,
|
|
941
|
+
keyboardSelectedRate
|
|
942
|
+
}, rate);
|
|
943
|
+
})
|
|
944
|
+
});
|
|
861
945
|
};
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
shouldLoop
|
|
873
|
-
}) => {
|
|
874
|
-
const op = playbackSpeed < 0 ? Math.ceil : Math.floor;
|
|
875
|
-
const framesToAdvance = op(time * playbackSpeed / (1000 / fps)) - framesAdvanced;
|
|
876
|
-
const nextFrame = framesToAdvance + startFrame;
|
|
877
|
-
const isCurrentFrameOutside = startFrame > actualLastFrame || startFrame < actualFirstFrame;
|
|
878
|
-
const isNextFrameOutside = nextFrame > actualLastFrame || nextFrame < actualFirstFrame;
|
|
879
|
-
const hasEnded = !shouldLoop && isNextFrameOutside && !isCurrentFrameOutside;
|
|
880
|
-
if (playbackSpeed > 0) {
|
|
881
|
-
if (isNextFrameOutside) {
|
|
882
|
-
return {
|
|
883
|
-
nextFrame: actualFirstFrame,
|
|
884
|
-
framesToAdvance,
|
|
885
|
-
hasEnded
|
|
886
|
-
};
|
|
887
|
-
}
|
|
888
|
-
return { nextFrame, framesToAdvance, hasEnded };
|
|
889
|
-
}
|
|
890
|
-
if (isNextFrameOutside) {
|
|
891
|
-
return { nextFrame: actualLastFrame, framesToAdvance, hasEnded };
|
|
892
|
-
}
|
|
893
|
-
return { nextFrame, framesToAdvance, hasEnded };
|
|
946
|
+
var label = {
|
|
947
|
+
fontSize: 13,
|
|
948
|
+
fontWeight: "bold",
|
|
949
|
+
color: "white",
|
|
950
|
+
border: "2px solid white",
|
|
951
|
+
borderRadius: 20,
|
|
952
|
+
paddingLeft: 8,
|
|
953
|
+
paddingRight: 8,
|
|
954
|
+
paddingTop: 2,
|
|
955
|
+
paddingBottom: 2
|
|
894
956
|
};
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
957
|
+
var playerButtonStyle = {
|
|
958
|
+
appearance: "none",
|
|
959
|
+
backgroundColor: "transparent",
|
|
960
|
+
border: "none",
|
|
961
|
+
cursor: "pointer",
|
|
962
|
+
paddingLeft: 0,
|
|
963
|
+
paddingRight: 0,
|
|
964
|
+
paddingTop: 6,
|
|
965
|
+
paddingBottom: 6,
|
|
966
|
+
height: 37,
|
|
967
|
+
display: "inline-flex",
|
|
968
|
+
marginBottom: 0,
|
|
969
|
+
marginTop: 0,
|
|
970
|
+
alignItems: "center"
|
|
903
971
|
};
|
|
904
|
-
var
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
const onVisibilityChange = () => {
|
|
908
|
-
isBackgrounded.current = getIsBackgrounded();
|
|
909
|
-
};
|
|
910
|
-
document.addEventListener("visibilitychange", onVisibilityChange);
|
|
911
|
-
return () => {
|
|
912
|
-
document.removeEventListener("visibilitychange", onVisibilityChange);
|
|
913
|
-
};
|
|
914
|
-
}, []);
|
|
915
|
-
return isBackgrounded;
|
|
972
|
+
var button = {
|
|
973
|
+
...playerButtonStyle,
|
|
974
|
+
position: "relative"
|
|
916
975
|
};
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
976
|
+
var PlaybackrateControl = ({ playbackRates, canvasSize }) => {
|
|
977
|
+
const { ref, isComponentVisible, setIsComponentVisible } = useComponentVisible(false);
|
|
978
|
+
const { playbackRate } = Internals4.usePlaybackRate();
|
|
979
|
+
const onClick = useCallback3((e) => {
|
|
980
|
+
e.stopPropagation();
|
|
981
|
+
e.preventDefault();
|
|
982
|
+
setIsComponentVisible((prevIsComponentVisible) => !prevIsComponentVisible);
|
|
983
|
+
}, [setIsComponentVisible]);
|
|
984
|
+
return /* @__PURE__ */ jsx7("div", {
|
|
985
|
+
ref,
|
|
986
|
+
children: /* @__PURE__ */ jsxs5("button", {
|
|
987
|
+
type: "button",
|
|
988
|
+
"aria-label": "Change playback rate",
|
|
989
|
+
style: button,
|
|
990
|
+
onClick,
|
|
991
|
+
children: [
|
|
992
|
+
/* @__PURE__ */ jsxs5("div", {
|
|
993
|
+
style: label,
|
|
994
|
+
children: [
|
|
995
|
+
playbackRate,
|
|
996
|
+
"x"
|
|
997
|
+
]
|
|
998
|
+
}),
|
|
999
|
+
isComponentVisible && /* @__PURE__ */ jsx7(PlaybackPopup, {
|
|
1000
|
+
canvasSize,
|
|
1001
|
+
playbackRates,
|
|
1002
|
+
setIsComponentVisible
|
|
1003
|
+
})
|
|
1004
|
+
]
|
|
1005
|
+
})
|
|
1006
|
+
});
|
|
940
1007
|
};
|
|
941
1008
|
|
|
942
|
-
// src/
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
1009
|
+
// src/PlayerSeekBar.tsx
|
|
1010
|
+
import { useCallback as useCallback6, useEffect as useEffect6, useMemo as useMemo6, useRef as useRef4, useState as useState8 } from "react";
|
|
1011
|
+
import { Internals as Internals6, interpolate } from "remotion";
|
|
1012
|
+
|
|
1013
|
+
// src/use-player-methods.ts
|
|
1014
|
+
import { useCallback as useCallback4, useContext as useContext2, useMemo as useMemo4, useRef as useRef3 } from "react";
|
|
1015
|
+
import { Internals as Internals5, useRemotionEnvironment } from "remotion";
|
|
1016
|
+
var usePlayerMethods = () => {
|
|
1017
|
+
const seekFrame = Internals5.Timeline.useTimelineSeekFrame();
|
|
1018
|
+
const {
|
|
1019
|
+
setPlaying,
|
|
1020
|
+
frameRef,
|
|
1021
|
+
audioAndVideoTags,
|
|
1022
|
+
isPlaying: readIsPlaying,
|
|
1023
|
+
isBuffering
|
|
1024
|
+
} = useContext2(Internals5.SetTimelineContext);
|
|
1025
|
+
const audioContext = useContext2(Internals5.SharedAudioContext);
|
|
1026
|
+
const audioTagsContext = useContext2(Internals5.SharedAudioTagsContext);
|
|
1027
|
+
const { playerMuted, mediaVolume } = useContext2(Internals5.MediaVolumeContext);
|
|
1028
|
+
const muted = playerMuted || mediaVolume === 0;
|
|
1029
|
+
const environment = useRemotionEnvironment();
|
|
1030
|
+
const video = Internals5.useVideo();
|
|
1031
|
+
const videoId = video?.id ?? null;
|
|
1032
|
+
const videoDurationInFrames = video?.durationInFrames ?? null;
|
|
1033
|
+
const config = Internals5.useUnsafeVideoConfig();
|
|
1034
|
+
const emitter = useContext2(PlayerEventEmitterContext);
|
|
1035
|
+
const playStart = useRef3(0);
|
|
1036
|
+
const fallbackFrame = useRef3(null);
|
|
1037
|
+
const nextPlayIsAutoPlayAttempt = useRef3(false);
|
|
1038
|
+
if (!emitter) {
|
|
1039
|
+
throw new TypeError("Expected Player event emitter context");
|
|
949
1040
|
}
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
loop,
|
|
954
|
-
playbackRate,
|
|
955
|
-
moveToBeginningWhenEnded,
|
|
956
|
-
inFrame,
|
|
957
|
-
outFrame,
|
|
958
|
-
browserMediaControlsBehavior,
|
|
959
|
-
getCurrentFrame,
|
|
960
|
-
muted
|
|
961
|
-
}) => {
|
|
962
|
-
const config = Internals6.useUnsafeVideoConfig();
|
|
963
|
-
const fps = config?.fps ?? null;
|
|
964
|
-
const durationInFrames = config?.durationInFrames ?? null;
|
|
965
|
-
const compositionId = config?.id ?? null;
|
|
966
|
-
const frame = Internals6.Timeline.useTimelinePosition();
|
|
967
|
-
const playing = Internals6.usePlaying();
|
|
968
|
-
const { pause, emitter, isPlaying } = usePlayerMethods();
|
|
969
|
-
const setFrameFromPlayback = Internals6.Timeline.useTimelineSetFrameWithoutSeek();
|
|
970
|
-
const sharedAudioContext = useContext3(Internals6.SharedAudioContext);
|
|
971
|
-
const { setPlayerMuted } = useContext3(Internals6.SetMediaVolumeContext);
|
|
972
|
-
const { isBuffering, subscribeBuffering, seek } = useContext3(Internals6.SetTimelineContext);
|
|
973
|
-
const logLevel = Internals6.useLogLevel();
|
|
974
|
-
const isBackgroundedRef = useIsBackgrounded();
|
|
975
|
-
const lastTimeUpdateTimestamp = useRef4(0);
|
|
976
|
-
const playbackClockRef = useRef4(null);
|
|
977
|
-
const previousMutedRef = useRef4(muted);
|
|
978
|
-
const anchoredAudioContextRef = useRef4(null);
|
|
979
|
-
useBrowserMediaSession({
|
|
980
|
-
browserMediaControlsBehavior,
|
|
981
|
-
playbackRate,
|
|
982
|
-
videoConfig: config
|
|
983
|
-
});
|
|
984
|
-
useLayoutEffect2(() => {
|
|
985
|
-
if (!sharedAudioContext) {
|
|
986
|
-
return;
|
|
1041
|
+
const getCurrentFrame = useCallback4(() => {
|
|
1042
|
+
if (videoId === null || videoDurationInFrames === null) {
|
|
1043
|
+
return fallbackFrame.current ?? (typeof window === "undefined" ? 0 : window.remotion_initialFrame ?? 0);
|
|
987
1044
|
}
|
|
988
|
-
|
|
989
|
-
|
|
1045
|
+
const unclamped = frameRef.current[videoId] ?? (environment.isPlayer ? 0 : Internals5.Timeline.getFrameForComposition(videoId));
|
|
1046
|
+
return Internals5.Timeline.clampFrameToCompositionRange(unclamped, videoDurationInFrames);
|
|
1047
|
+
}, [environment.isPlayer, frameRef, videoId, videoDurationInFrames]);
|
|
1048
|
+
const seek = useCallback4((newFrame) => {
|
|
1049
|
+
const frameToSeekTo = config ? Internals5.TimelinePosition.clampFrameToCompositionRange(newFrame, config.durationInFrames) : Math.max(0, newFrame);
|
|
1050
|
+
fallbackFrame.current = frameToSeekTo;
|
|
1051
|
+
if (video?.id) {
|
|
1052
|
+
seekFrame((currentFrames) => currentFrames[video.id] === frameToSeekTo ? currentFrames : { ...currentFrames, [video.id]: frameToSeekTo });
|
|
1053
|
+
if (frameRef.current[video.id] !== frameToSeekTo) {
|
|
1054
|
+
frameRef.current = {
|
|
1055
|
+
...frameRef.current,
|
|
1056
|
+
[video.id]: frameToSeekTo
|
|
1057
|
+
};
|
|
1058
|
+
}
|
|
990
1059
|
}
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
1060
|
+
emitter.dispatchSeek(frameToSeekTo);
|
|
1061
|
+
}, [config, emitter, frameRef, seekFrame, video?.id]);
|
|
1062
|
+
const play = useCallback4((e) => {
|
|
1063
|
+
const isAutoPlayAttempt = nextPlayIsAutoPlayAttempt.current;
|
|
1064
|
+
nextPlayIsAutoPlayAttempt.current = false;
|
|
1065
|
+
if (readIsPlaying()) {
|
|
995
1066
|
return;
|
|
996
1067
|
}
|
|
997
|
-
const
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
absoluteTimeInSeconds: frame / fps,
|
|
1001
|
-
globalPlaybackRate: playbackRate,
|
|
1002
|
-
logLevel,
|
|
1003
|
-
force: false
|
|
1004
|
-
});
|
|
1005
|
-
if (changed) {
|
|
1006
|
-
sharedAudioContext.audioSyncAnchorEmitter.dispatch("changed");
|
|
1068
|
+
const lastFrameForPlayback = (config?.durationInFrames ?? 1) - 1;
|
|
1069
|
+
if (getCurrentFrame() === lastFrameForPlayback) {
|
|
1070
|
+
seek(0);
|
|
1007
1071
|
}
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1072
|
+
if (!muted) {
|
|
1073
|
+
if (isAutoPlayAttempt) {
|
|
1074
|
+
audioContext?.resumeAsAutoPlay();
|
|
1075
|
+
} else {
|
|
1076
|
+
audioContext?.resume();
|
|
1077
|
+
}
|
|
1078
|
+
if (audioTagsContext && audioTagsContext.numberOfAudioTags > 0 && e) {
|
|
1079
|
+
audioTagsContext.playAllAudios();
|
|
1080
|
+
}
|
|
1013
1081
|
}
|
|
1014
|
-
|
|
1082
|
+
audioAndVideoTags.current.forEach((tag) => tag.play("player play() was called and playing audio from a click"));
|
|
1083
|
+
setPlaying(true);
|
|
1084
|
+
playStart.current = getCurrentFrame();
|
|
1085
|
+
emitter.dispatchPlay();
|
|
1086
|
+
}, [
|
|
1087
|
+
audioAndVideoTags,
|
|
1088
|
+
audioContext,
|
|
1089
|
+
audioTagsContext,
|
|
1090
|
+
config?.durationInFrames,
|
|
1091
|
+
emitter,
|
|
1092
|
+
getCurrentFrame,
|
|
1093
|
+
muted,
|
|
1094
|
+
readIsPlaying,
|
|
1095
|
+
seek,
|
|
1096
|
+
setPlaying
|
|
1097
|
+
]);
|
|
1098
|
+
const playAsAutoPlay = useCallback4(() => {
|
|
1099
|
+
nextPlayIsAutoPlayAttempt.current = true;
|
|
1100
|
+
play();
|
|
1101
|
+
}, [play]);
|
|
1102
|
+
const pause = useCallback4(() => {
|
|
1103
|
+
if (readIsPlaying()) {
|
|
1104
|
+
setPlaying(false);
|
|
1105
|
+
emitter.dispatchPause();
|
|
1106
|
+
audioContext?.suspend();
|
|
1107
|
+
}
|
|
1108
|
+
}, [audioContext, emitter, readIsPlaying, setPlaying]);
|
|
1109
|
+
const pauseAndReturnToPlayStart = useCallback4(() => {
|
|
1110
|
+
if (readIsPlaying()) {
|
|
1111
|
+
setPlaying(false);
|
|
1112
|
+
fallbackFrame.current = playStart.current;
|
|
1113
|
+
if (config) {
|
|
1114
|
+
seekFrame((currentFrames) => ({
|
|
1115
|
+
...currentFrames,
|
|
1116
|
+
[config.id]: playStart.current
|
|
1117
|
+
}));
|
|
1118
|
+
frameRef.current = {
|
|
1119
|
+
...frameRef.current,
|
|
1120
|
+
[config.id]: playStart.current
|
|
1121
|
+
};
|
|
1122
|
+
emitter.dispatchPause();
|
|
1123
|
+
}
|
|
1124
|
+
}
|
|
1125
|
+
}, [config, emitter, frameRef, readIsPlaying, setPlaying, seekFrame]);
|
|
1126
|
+
const lastFrame = (config?.durationInFrames ?? 1) - 1;
|
|
1127
|
+
const frameBack = useCallback4((frames) => {
|
|
1128
|
+
if (!videoId) {
|
|
1129
|
+
return null;
|
|
1130
|
+
}
|
|
1131
|
+
if (readIsPlaying()) {
|
|
1015
1132
|
return;
|
|
1016
1133
|
}
|
|
1017
|
-
|
|
1134
|
+
const previousFrame = frameRef.current[videoId] ?? window.remotion_initialFrame ?? 0;
|
|
1135
|
+
const newFrame = Math.max(0, previousFrame - frames);
|
|
1136
|
+
if (previousFrame === newFrame) {
|
|
1018
1137
|
return;
|
|
1019
1138
|
}
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
audioContext,
|
|
1025
|
-
audioSyncAnchor: sharedAudioContext.audioSyncAnchor,
|
|
1026
|
-
absoluteTimeInSeconds: getCurrentFrame() / fps,
|
|
1027
|
-
globalPlaybackRate: playbackRate,
|
|
1028
|
-
logLevel,
|
|
1029
|
-
force: true
|
|
1030
|
-
});
|
|
1031
|
-
if (changed) {
|
|
1032
|
-
sharedAudioContext.audioSyncAnchorEmitter.dispatch("changed");
|
|
1033
|
-
}
|
|
1034
|
-
}
|
|
1035
|
-
};
|
|
1036
|
-
audioContext?.addEventListener("statechange", callback);
|
|
1037
|
-
return () => {
|
|
1038
|
-
audioContext?.removeEventListener("statechange", callback);
|
|
1139
|
+
seekFrame((currentFrames) => currentFrames[videoId] === newFrame ? currentFrames : { ...currentFrames, [videoId]: newFrame });
|
|
1140
|
+
frameRef.current = {
|
|
1141
|
+
...frameRef.current,
|
|
1142
|
+
[videoId]: newFrame
|
|
1039
1143
|
};
|
|
1040
|
-
}, [
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1144
|
+
}, [frameRef, readIsPlaying, seekFrame, videoId]);
|
|
1145
|
+
const frameForward = useCallback4((frames) => {
|
|
1146
|
+
if (!videoId) {
|
|
1147
|
+
return null;
|
|
1148
|
+
}
|
|
1149
|
+
if (readIsPlaying()) {
|
|
1046
1150
|
return;
|
|
1047
1151
|
}
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1152
|
+
const previousFrame = frameRef.current[videoId] ?? window.remotion_initialFrame ?? 0;
|
|
1153
|
+
const newFrame = Math.min(lastFrame, previousFrame + frames);
|
|
1154
|
+
if (previousFrame === newFrame) {
|
|
1051
1155
|
return;
|
|
1052
1156
|
}
|
|
1053
|
-
|
|
1054
|
-
|
|
1157
|
+
seekFrame((currentFrames) => currentFrames[videoId] === newFrame ? currentFrames : { ...currentFrames, [videoId]: newFrame });
|
|
1158
|
+
frameRef.current = {
|
|
1159
|
+
...frameRef.current,
|
|
1160
|
+
[videoId]: newFrame
|
|
1161
|
+
};
|
|
1162
|
+
}, [frameRef, lastFrame, readIsPlaying, seekFrame, videoId]);
|
|
1163
|
+
const toggle = useCallback4((e) => {
|
|
1164
|
+
if (readIsPlaying()) {
|
|
1165
|
+
pause();
|
|
1166
|
+
} else {
|
|
1167
|
+
play(e);
|
|
1055
1168
|
}
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1169
|
+
}, [pause, play, readIsPlaying]);
|
|
1170
|
+
return useMemo4(() => {
|
|
1171
|
+
return {
|
|
1172
|
+
frameBack,
|
|
1173
|
+
frameForward,
|
|
1174
|
+
emitter,
|
|
1175
|
+
play,
|
|
1176
|
+
playAsAutoPlay,
|
|
1177
|
+
pause,
|
|
1178
|
+
seek,
|
|
1179
|
+
getCurrentFrame,
|
|
1180
|
+
isPlaying: readIsPlaying,
|
|
1181
|
+
isBuffering,
|
|
1182
|
+
pauseAndReturnToPlayStart,
|
|
1183
|
+
toggle
|
|
1184
|
+
};
|
|
1185
|
+
}, [
|
|
1186
|
+
emitter,
|
|
1187
|
+
frameBack,
|
|
1188
|
+
frameForward,
|
|
1189
|
+
getCurrentFrame,
|
|
1190
|
+
readIsPlaying,
|
|
1191
|
+
pause,
|
|
1192
|
+
pauseAndReturnToPlayStart,
|
|
1193
|
+
play,
|
|
1194
|
+
playAsAutoPlay,
|
|
1195
|
+
isBuffering,
|
|
1196
|
+
seek,
|
|
1197
|
+
toggle
|
|
1198
|
+
]);
|
|
1199
|
+
};
|
|
1200
|
+
|
|
1201
|
+
// src/utils/use-element-size.ts
|
|
1202
|
+
import { useCallback as useCallback5, useEffect as useEffect5, useMemo as useMemo5, useState as useState7 } from "react";
|
|
1203
|
+
var elementSizeHooks = [];
|
|
1204
|
+
var updateAllElementsSizes = () => {
|
|
1205
|
+
for (const listener of elementSizeHooks) {
|
|
1206
|
+
listener();
|
|
1207
|
+
}
|
|
1208
|
+
};
|
|
1209
|
+
var getElement = (source) => {
|
|
1210
|
+
if (!source) {
|
|
1211
|
+
return null;
|
|
1212
|
+
}
|
|
1213
|
+
if ("current" in source) {
|
|
1214
|
+
return source.current;
|
|
1215
|
+
}
|
|
1216
|
+
return source;
|
|
1217
|
+
};
|
|
1218
|
+
var useElementSize = (source, options) => {
|
|
1219
|
+
const [size, setSize] = useState7(() => {
|
|
1220
|
+
const element = getElement(source);
|
|
1221
|
+
if (!element) {
|
|
1222
|
+
return null;
|
|
1082
1223
|
}
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1224
|
+
const rect = element.getClientRects();
|
|
1225
|
+
if (!rect[0]) {
|
|
1226
|
+
return null;
|
|
1227
|
+
}
|
|
1228
|
+
return {
|
|
1229
|
+
width: rect[0].width,
|
|
1230
|
+
height: rect[0].height,
|
|
1231
|
+
left: rect[0].x,
|
|
1232
|
+
top: rect[0].y,
|
|
1233
|
+
windowSize: {
|
|
1234
|
+
height: window.innerHeight,
|
|
1235
|
+
width: window.innerWidth
|
|
1095
1236
|
}
|
|
1096
1237
|
};
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
if (!
|
|
1106
|
-
|
|
1107
|
-
return;
|
|
1108
|
-
}
|
|
1109
|
-
if (!muted && !audioContextFailed && !isBuffering()) {
|
|
1110
|
-
sharedAudioContext?.resume?.();
|
|
1111
|
-
}
|
|
1112
|
-
const time = performance.now() - clock.startedTime;
|
|
1113
|
-
const actualLastFrame = outFrame ?? durationInFrames - 1;
|
|
1114
|
-
const actualFirstFrame = inFrame ?? 0;
|
|
1115
|
-
const seekRevision = seek?.revision.current ?? null;
|
|
1116
|
-
if (seekRevision !== lastSeekRevision) {
|
|
1117
|
-
playbackFrame = getCurrentFrame();
|
|
1118
|
-
lastSeekRevision = seekRevision;
|
|
1119
|
-
}
|
|
1120
|
-
const currentFrame = playbackFrame;
|
|
1121
|
-
const { nextFrame, framesToAdvance, hasEnded } = calculateNextFrame({
|
|
1122
|
-
time,
|
|
1123
|
-
currentFrame,
|
|
1124
|
-
playbackSpeed: playbackRate,
|
|
1125
|
-
fps,
|
|
1126
|
-
actualFirstFrame,
|
|
1127
|
-
actualLastFrame,
|
|
1128
|
-
framesAdvanced: clock.framesAdvanced,
|
|
1129
|
-
shouldLoop: loop
|
|
1130
|
-
});
|
|
1131
|
-
clock.framesAdvanced += framesToAdvance;
|
|
1132
|
-
const frameToDisplay = hasEnded && !moveToBeginningWhenEnded ? playbackRate > 0 ? actualLastFrame : actualFirstFrame : nextFrame;
|
|
1133
|
-
if (frameToDisplay !== currentFrame && !isBuffering()) {
|
|
1134
|
-
playbackFrame = frameToDisplay;
|
|
1135
|
-
setFrameFromPlayback((c) => ({ ...c, [compositionId]: frameToDisplay }));
|
|
1136
|
-
}
|
|
1137
|
-
if (hasEnded) {
|
|
1138
|
-
stop();
|
|
1139
|
-
pause();
|
|
1140
|
-
emitter.dispatchEnded();
|
|
1141
|
-
return;
|
|
1142
|
-
}
|
|
1143
|
-
queueNextFrame();
|
|
1144
|
-
};
|
|
1145
|
-
const queueNextFrame = () => {
|
|
1146
|
-
if (hasBeenStopped) {
|
|
1147
|
-
return;
|
|
1148
|
-
}
|
|
1149
|
-
const getIsResumingAudioContext = audioContextFailed ? null : sharedAudioContext?.getIsResumingAudioContext?.() ?? null;
|
|
1150
|
-
if (getIsResumingAudioContext !== null && !muted) {
|
|
1151
|
-
getIsResumingAudioContext.then((result) => {
|
|
1152
|
-
if (hasBeenStopped) {
|
|
1153
|
-
return;
|
|
1154
|
-
}
|
|
1155
|
-
if (result === "failed") {
|
|
1156
|
-
audioContextFailed = true;
|
|
1157
|
-
sharedAudioContext?.suspend();
|
|
1158
|
-
setPlayerMuted(true);
|
|
1159
|
-
}
|
|
1160
|
-
clock.startedTime = performance.now();
|
|
1161
|
-
clock.framesAdvanced = 0;
|
|
1162
|
-
queueNextFrame();
|
|
1163
|
-
});
|
|
1164
|
-
return;
|
|
1165
|
-
}
|
|
1166
|
-
if (isBuffering()) {
|
|
1167
|
-
if (!muted && !audioContextFailed) {
|
|
1168
|
-
sharedAudioContext?.suspend?.();
|
|
1169
|
-
}
|
|
1170
|
-
const unsubscribe = subscribeBuffering((state) => {
|
|
1171
|
-
if (state.buffering) {
|
|
1172
|
-
return;
|
|
1173
|
-
}
|
|
1174
|
-
unsubscribe();
|
|
1175
|
-
if (!muted && !audioContextFailed && sharedAudioContext?._experimentalKeepAudioContextAlive) {
|
|
1176
|
-
sharedAudioContext.resume();
|
|
1177
|
-
}
|
|
1178
|
-
clock.startedTime = performance.now();
|
|
1179
|
-
clock.framesAdvanced = 0;
|
|
1180
|
-
queueNextFrame();
|
|
1181
|
-
});
|
|
1182
|
-
return;
|
|
1183
|
-
}
|
|
1184
|
-
if (isBackgroundedRef.current) {
|
|
1185
|
-
reqAnimFrameCall = {
|
|
1186
|
-
type: "timeout",
|
|
1187
|
-
id: setTimeout(callback, 1000 / fps)
|
|
1188
|
-
};
|
|
1189
|
-
return;
|
|
1190
|
-
}
|
|
1191
|
-
reqAnimFrameCall = { type: "raf", id: requestAnimationFrame(callback) };
|
|
1192
|
-
};
|
|
1193
|
-
queueNextFrame();
|
|
1194
|
-
const onVisibilityChange = () => {
|
|
1195
|
-
if (document.visibilityState === "visible") {
|
|
1196
|
-
return;
|
|
1197
|
-
}
|
|
1198
|
-
cancelQueuedFrame();
|
|
1199
|
-
callback();
|
|
1200
|
-
};
|
|
1201
|
-
window.addEventListener("visibilitychange", onVisibilityChange);
|
|
1202
|
-
return () => {
|
|
1203
|
-
window.removeEventListener("visibilitychange", onVisibilityChange);
|
|
1204
|
-
stop();
|
|
1205
|
-
};
|
|
1206
|
-
}, [
|
|
1207
|
-
compositionId,
|
|
1208
|
-
durationInFrames,
|
|
1209
|
-
fps,
|
|
1210
|
-
loop,
|
|
1211
|
-
pause,
|
|
1212
|
-
playing,
|
|
1213
|
-
setFrameFromPlayback,
|
|
1214
|
-
emitter,
|
|
1215
|
-
playbackRate,
|
|
1216
|
-
inFrame,
|
|
1217
|
-
outFrame,
|
|
1218
|
-
moveToBeginningWhenEnded,
|
|
1219
|
-
isBackgroundedRef,
|
|
1220
|
-
getCurrentFrame,
|
|
1221
|
-
isBuffering,
|
|
1222
|
-
isPlaying,
|
|
1223
|
-
sharedAudioContext,
|
|
1224
|
-
setPlayerMuted,
|
|
1225
|
-
subscribeBuffering,
|
|
1226
|
-
seek,
|
|
1227
|
-
logLevel,
|
|
1228
|
-
muted
|
|
1229
|
-
]);
|
|
1230
|
-
useEffect5(() => {
|
|
1231
|
-
const now = performance.now();
|
|
1232
|
-
const timeSinceLastUpdate = now - lastTimeUpdateTimestamp.current;
|
|
1233
|
-
if (timeSinceLastUpdate >= 250) {
|
|
1234
|
-
emitter.dispatchTimeUpdate({ frame });
|
|
1235
|
-
lastTimeUpdateTimestamp.current = now;
|
|
1236
|
-
return;
|
|
1237
|
-
}
|
|
1238
|
-
const timeoutId = setTimeout(() => {
|
|
1239
|
-
emitter.dispatchTimeUpdate({ frame });
|
|
1240
|
-
lastTimeUpdateTimestamp.current = performance.now();
|
|
1241
|
-
}, 250 - timeSinceLastUpdate);
|
|
1242
|
-
return () => clearTimeout(timeoutId);
|
|
1243
|
-
}, [emitter, frame]);
|
|
1244
|
-
useEffect5(() => {
|
|
1245
|
-
emitter.dispatchFrameUpdate({ frame });
|
|
1246
|
-
}, [emitter, frame]);
|
|
1247
|
-
};
|
|
1248
|
-
|
|
1249
|
-
// src/utils/use-element-size.ts
|
|
1250
|
-
import { useCallback as useCallback2, useEffect as useEffect6, useMemo as useMemo2, useState as useState3 } from "react";
|
|
1251
|
-
var elementSizeHooks = [];
|
|
1252
|
-
var updateAllElementsSizes = () => {
|
|
1253
|
-
for (const listener of elementSizeHooks) {
|
|
1254
|
-
listener();
|
|
1255
|
-
}
|
|
1256
|
-
};
|
|
1257
|
-
var getElement = (source) => {
|
|
1258
|
-
if (!source) {
|
|
1259
|
-
return null;
|
|
1260
|
-
}
|
|
1261
|
-
if ("current" in source) {
|
|
1262
|
-
return source.current;
|
|
1263
|
-
}
|
|
1264
|
-
return source;
|
|
1265
|
-
};
|
|
1266
|
-
var useElementSize = (source, options) => {
|
|
1267
|
-
const [size, setSize] = useState3(() => {
|
|
1268
|
-
const element = getElement(source);
|
|
1269
|
-
if (!element) {
|
|
1270
|
-
return null;
|
|
1271
|
-
}
|
|
1272
|
-
const rect = element.getClientRects();
|
|
1273
|
-
if (!rect[0]) {
|
|
1274
|
-
return null;
|
|
1275
|
-
}
|
|
1276
|
-
return {
|
|
1277
|
-
width: rect[0].width,
|
|
1278
|
-
height: rect[0].height,
|
|
1279
|
-
left: rect[0].x,
|
|
1280
|
-
top: rect[0].y,
|
|
1281
|
-
windowSize: {
|
|
1282
|
-
height: window.innerHeight,
|
|
1283
|
-
width: window.innerWidth
|
|
1284
|
-
}
|
|
1285
|
-
};
|
|
1286
|
-
});
|
|
1287
|
-
const observer = useMemo2(() => {
|
|
1288
|
-
if (typeof ResizeObserver === "undefined") {
|
|
1289
|
-
return null;
|
|
1290
|
-
}
|
|
1291
|
-
return new ResizeObserver((entries) => {
|
|
1292
|
-
const { contentRect, target } = entries[0];
|
|
1293
|
-
const newSize = target.getClientRects();
|
|
1294
|
-
if (!newSize?.[0]) {
|
|
1295
|
-
setSize(null);
|
|
1238
|
+
});
|
|
1239
|
+
const observer = useMemo5(() => {
|
|
1240
|
+
if (typeof ResizeObserver === "undefined") {
|
|
1241
|
+
return null;
|
|
1242
|
+
}
|
|
1243
|
+
return new ResizeObserver((entries) => {
|
|
1244
|
+
const { contentRect, target } = entries[0];
|
|
1245
|
+
const newSize = target.getClientRects();
|
|
1246
|
+
if (!newSize?.[0]) {
|
|
1247
|
+
setSize(null);
|
|
1296
1248
|
return;
|
|
1297
1249
|
}
|
|
1298
1250
|
const probableCssParentScaleX = contentRect.width === 0 ? 1 : newSize[0].width / contentRect.width;
|
|
@@ -1317,7 +1269,7 @@ var useElementSize = (source, options) => {
|
|
|
1317
1269
|
});
|
|
1318
1270
|
});
|
|
1319
1271
|
}, [options.shouldApplyCssTransforms]);
|
|
1320
|
-
const updateSize =
|
|
1272
|
+
const updateSize = useCallback5(() => {
|
|
1321
1273
|
const element = getElement(source);
|
|
1322
1274
|
if (!element) {
|
|
1323
1275
|
return;
|
|
@@ -1344,10 +1296,10 @@ var useElementSize = (source, options) => {
|
|
|
1344
1296
|
};
|
|
1345
1297
|
});
|
|
1346
1298
|
}, [source]);
|
|
1347
|
-
|
|
1299
|
+
useEffect5(() => {
|
|
1348
1300
|
updateSize();
|
|
1349
1301
|
}, [updateSize]);
|
|
1350
|
-
|
|
1302
|
+
useEffect5(() => {
|
|
1351
1303
|
if (!observer) {
|
|
1352
1304
|
return;
|
|
1353
1305
|
}
|
|
@@ -1361,7 +1313,7 @@ var useElementSize = (source, options) => {
|
|
|
1361
1313
|
}
|
|
1362
1314
|
};
|
|
1363
1315
|
}, [observer, source]);
|
|
1364
|
-
|
|
1316
|
+
useEffect5(() => {
|
|
1365
1317
|
if (!options.triggerOnWindowResize) {
|
|
1366
1318
|
return;
|
|
1367
1319
|
}
|
|
@@ -1370,13 +1322,13 @@ var useElementSize = (source, options) => {
|
|
|
1370
1322
|
window.removeEventListener("resize", updateSize);
|
|
1371
1323
|
};
|
|
1372
1324
|
}, [options.triggerOnWindowResize, updateSize]);
|
|
1373
|
-
|
|
1325
|
+
useEffect5(() => {
|
|
1374
1326
|
elementSizeHooks.push(updateSize);
|
|
1375
1327
|
return () => {
|
|
1376
1328
|
elementSizeHooks = elementSizeHooks.filter((e) => e !== updateSize);
|
|
1377
1329
|
};
|
|
1378
1330
|
}, [updateSize]);
|
|
1379
|
-
return
|
|
1331
|
+
return useMemo5(() => {
|
|
1380
1332
|
if (!size) {
|
|
1381
1333
|
return null;
|
|
1382
1334
|
}
|
|
@@ -1384,1134 +1336,1209 @@ var useElementSize = (source, options) => {
|
|
|
1384
1336
|
}, [size, updateSize]);
|
|
1385
1337
|
};
|
|
1386
1338
|
|
|
1387
|
-
// src/
|
|
1388
|
-
import
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
useState as useState12
|
|
1397
|
-
} from "react";
|
|
1398
|
-
import { Composition, Internals as Internals15 } from "remotion";
|
|
1399
|
-
import { NoReactInternals as NoReactInternals2 } from "remotion/no-react";
|
|
1400
|
-
|
|
1401
|
-
// src/player-css-classname.ts
|
|
1402
|
-
var playerCssClassname = (override) => {
|
|
1403
|
-
return override ?? "__remotion-player";
|
|
1339
|
+
// src/PlayerSeekBar.tsx
|
|
1340
|
+
import { jsx as jsx8, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
1341
|
+
var getFrameFromX = (clientX, durationInFrames, width) => {
|
|
1342
|
+
const pos = clientX;
|
|
1343
|
+
const frame = Math.round(interpolate(pos, [0, width], [0, durationInFrames - 1], {
|
|
1344
|
+
extrapolateLeft: "clamp",
|
|
1345
|
+
extrapolateRight: "clamp"
|
|
1346
|
+
}));
|
|
1347
|
+
return frame;
|
|
1404
1348
|
};
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
} from "react";
|
|
1418
|
-
import { Internals as Internals11 } from "remotion";
|
|
1419
|
-
|
|
1420
|
-
// src/error-boundary.tsx
|
|
1421
|
-
import React4 from "react";
|
|
1422
|
-
import { jsx as jsx4 } from "react/jsx-runtime";
|
|
1423
|
-
var errorStyle = {
|
|
1424
|
-
display: "flex",
|
|
1425
|
-
justifyContent: "center",
|
|
1426
|
-
alignItems: "center",
|
|
1427
|
-
flex: 1,
|
|
1428
|
-
height: "100%",
|
|
1429
|
-
width: "100%"
|
|
1349
|
+
var BAR_HEIGHT2 = 5;
|
|
1350
|
+
var KNOB_SIZE2 = 12;
|
|
1351
|
+
var VERTICAL_PADDING = 4;
|
|
1352
|
+
var containerStyle = {
|
|
1353
|
+
userSelect: "none",
|
|
1354
|
+
WebkitUserSelect: "none",
|
|
1355
|
+
paddingTop: VERTICAL_PADDING,
|
|
1356
|
+
paddingBottom: VERTICAL_PADDING,
|
|
1357
|
+
boxSizing: "border-box",
|
|
1358
|
+
cursor: "pointer",
|
|
1359
|
+
position: "relative",
|
|
1360
|
+
touchAction: "none"
|
|
1430
1361
|
};
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
}
|
|
1437
|
-
componentDidCatch(error) {
|
|
1438
|
-
this.props.onError(error);
|
|
1439
|
-
}
|
|
1440
|
-
render() {
|
|
1441
|
-
if (this.state.hasError) {
|
|
1442
|
-
return /* @__PURE__ */ jsx4("div", {
|
|
1443
|
-
style: errorStyle,
|
|
1444
|
-
children: this.props.errorFallback({
|
|
1445
|
-
error: this.state.hasError
|
|
1446
|
-
})
|
|
1447
|
-
});
|
|
1448
|
-
}
|
|
1449
|
-
return this.props.children;
|
|
1450
|
-
}
|
|
1451
|
-
}
|
|
1452
|
-
|
|
1453
|
-
// src/license-blacklist.tsx
|
|
1454
|
-
import React5, { useEffect as useEffect7 } from "react";
|
|
1455
|
-
import { jsx as jsx5 } from "react/jsx-runtime";
|
|
1456
|
-
var getHashOfDomain = async () => {
|
|
1457
|
-
if (typeof window === "undefined") {
|
|
1458
|
-
return null;
|
|
1459
|
-
}
|
|
1460
|
-
if (typeof window.crypto === "undefined") {
|
|
1461
|
-
return null;
|
|
1462
|
-
}
|
|
1463
|
-
if (typeof window.crypto.subtle === "undefined") {
|
|
1464
|
-
return null;
|
|
1465
|
-
}
|
|
1466
|
-
try {
|
|
1467
|
-
const hashBuffer = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(window.location.hostname));
|
|
1468
|
-
return Array.from(new Uint8Array(hashBuffer)).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
1469
|
-
} catch {
|
|
1470
|
-
return null;
|
|
1471
|
-
}
|
|
1362
|
+
var barBackground = {
|
|
1363
|
+
height: BAR_HEIGHT2,
|
|
1364
|
+
backgroundColor: "rgba(255, 255, 255, 0.25)",
|
|
1365
|
+
width: "100%",
|
|
1366
|
+
borderRadius: BAR_HEIGHT2 / 2
|
|
1472
1367
|
};
|
|
1473
|
-
var
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1368
|
+
var findBodyInWhichDivIsLocated = (div) => {
|
|
1369
|
+
let current = div;
|
|
1370
|
+
while (current.parentElement) {
|
|
1371
|
+
current = current.parentElement;
|
|
1372
|
+
}
|
|
1373
|
+
return current;
|
|
1478
1374
|
};
|
|
1479
|
-
var
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1375
|
+
var PlayerSeekBar = ({ durationInFrames, onSeekEnd, onSeekStart, inFrame, outFrame }) => {
|
|
1376
|
+
const containerRef = useRef4(null);
|
|
1377
|
+
const barHovered = useHoverState(containerRef, false);
|
|
1378
|
+
const size = useElementSize(containerRef, {
|
|
1379
|
+
triggerOnWindowResize: true,
|
|
1380
|
+
shouldApplyCssTransforms: true
|
|
1381
|
+
});
|
|
1382
|
+
const { seek, play, pause, isPlaying } = usePlayerMethods();
|
|
1383
|
+
const frame = Internals6.Timeline.useTimelinePosition();
|
|
1384
|
+
const [dragging, setDragging] = useState8({
|
|
1385
|
+
dragging: false
|
|
1386
|
+
});
|
|
1387
|
+
const width = size?.width ?? 0;
|
|
1388
|
+
const onPointerDown = useCallback6((e) => {
|
|
1389
|
+
if (e.button !== 0) {
|
|
1492
1390
|
return;
|
|
1493
1391
|
}
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1392
|
+
const posLeft = containerRef.current?.getBoundingClientRect().left;
|
|
1393
|
+
const _frame = getFrameFromX(e.clientX - posLeft, durationInFrames, width);
|
|
1394
|
+
const wasPlaying = isPlaying();
|
|
1395
|
+
pause();
|
|
1396
|
+
seek(_frame);
|
|
1397
|
+
setDragging({
|
|
1398
|
+
dragging: true,
|
|
1399
|
+
wasPlaying
|
|
1400
|
+
});
|
|
1401
|
+
onSeekStart();
|
|
1402
|
+
}, [durationInFrames, width, isPlaying, pause, seek, onSeekStart]);
|
|
1403
|
+
const onPointerMove = useCallback6((e) => {
|
|
1404
|
+
if (!size) {
|
|
1405
|
+
throw new Error("Player has no size");
|
|
1406
|
+
}
|
|
1407
|
+
if (!dragging.dragging) {
|
|
1503
1408
|
return;
|
|
1504
1409
|
}
|
|
1505
|
-
const
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1410
|
+
const posLeft = containerRef.current?.getBoundingClientRect().left;
|
|
1411
|
+
const _frame = getFrameFromX(e.clientX - posLeft, durationInFrames, size.width);
|
|
1412
|
+
seek(_frame);
|
|
1413
|
+
}, [dragging.dragging, durationInFrames, seek, size]);
|
|
1414
|
+
const onPointerUp = useCallback6(() => {
|
|
1415
|
+
setDragging({
|
|
1416
|
+
dragging: false
|
|
1417
|
+
});
|
|
1418
|
+
if (!dragging.dragging) {
|
|
1419
|
+
return;
|
|
1420
|
+
}
|
|
1421
|
+
if (dragging.wasPlaying) {
|
|
1422
|
+
play();
|
|
1423
|
+
} else {
|
|
1424
|
+
pause();
|
|
1425
|
+
}
|
|
1426
|
+
onSeekEnd();
|
|
1427
|
+
}, [dragging, onSeekEnd, pause, play]);
|
|
1428
|
+
useEffect6(() => {
|
|
1429
|
+
if (!dragging.dragging) {
|
|
1430
|
+
return;
|
|
1431
|
+
}
|
|
1432
|
+
const body = findBodyInWhichDivIsLocated(containerRef.current);
|
|
1433
|
+
body.addEventListener("pointermove", onPointerMove);
|
|
1434
|
+
body.addEventListener("pointerup", onPointerUp);
|
|
1524
1435
|
return () => {
|
|
1525
|
-
|
|
1436
|
+
body.removeEventListener("pointermove", onPointerMove);
|
|
1437
|
+
body.removeEventListener("pointerup", onPointerUp);
|
|
1526
1438
|
};
|
|
1527
|
-
}, [
|
|
1528
|
-
|
|
1529
|
-
return
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1439
|
+
}, [dragging.dragging, onPointerMove, onPointerUp]);
|
|
1440
|
+
const knobStyle = useMemo6(() => {
|
|
1441
|
+
return {
|
|
1442
|
+
height: KNOB_SIZE2,
|
|
1443
|
+
width: KNOB_SIZE2,
|
|
1444
|
+
borderRadius: KNOB_SIZE2 / 2,
|
|
1445
|
+
position: "absolute",
|
|
1446
|
+
top: VERTICAL_PADDING - KNOB_SIZE2 / 2 + 5 / 2,
|
|
1447
|
+
backgroundColor: "white",
|
|
1448
|
+
left: Math.max(0, frame / Math.max(1, durationInFrames - 1) * width - KNOB_SIZE2 / 2),
|
|
1449
|
+
boxShadow: "0 0 2px black",
|
|
1450
|
+
opacity: Number(barHovered || dragging.dragging)
|
|
1451
|
+
};
|
|
1452
|
+
}, [barHovered, dragging.dragging, durationInFrames, frame, width]);
|
|
1453
|
+
const fillStyle = useMemo6(() => {
|
|
1454
|
+
return {
|
|
1455
|
+
height: BAR_HEIGHT2,
|
|
1456
|
+
backgroundColor: "rgba(255, 255, 255, 1)",
|
|
1457
|
+
width: (frame - (inFrame ?? 0)) / (durationInFrames - 1) * width,
|
|
1458
|
+
marginLeft: (inFrame ?? 0) / (durationInFrames - 1) * width,
|
|
1459
|
+
borderRadius: BAR_HEIGHT2 / 2
|
|
1460
|
+
};
|
|
1461
|
+
}, [durationInFrames, frame, inFrame, width]);
|
|
1462
|
+
const active = useMemo6(() => {
|
|
1463
|
+
return {
|
|
1464
|
+
height: BAR_HEIGHT2,
|
|
1465
|
+
backgroundColor: "rgba(255, 255, 255, 0.25)",
|
|
1466
|
+
width: ((outFrame ?? durationInFrames - 1) - (inFrame ?? 0)) / (durationInFrames - 1) * 100 + "%",
|
|
1467
|
+
marginLeft: (inFrame ?? 0) / (durationInFrames - 1) * 100 + "%",
|
|
1468
|
+
borderRadius: BAR_HEIGHT2 / 2,
|
|
1469
|
+
position: "absolute"
|
|
1470
|
+
};
|
|
1471
|
+
}, [durationInFrames, inFrame, outFrame]);
|
|
1472
|
+
return /* @__PURE__ */ jsxs6("div", {
|
|
1473
|
+
ref: containerRef,
|
|
1474
|
+
onPointerDown,
|
|
1475
|
+
style: containerStyle,
|
|
1476
|
+
children: [
|
|
1477
|
+
/* @__PURE__ */ jsxs6("div", {
|
|
1478
|
+
style: barBackground,
|
|
1479
|
+
children: [
|
|
1480
|
+
/* @__PURE__ */ jsx8("div", {
|
|
1481
|
+
style: active
|
|
1482
|
+
}),
|
|
1483
|
+
/* @__PURE__ */ jsx8("div", {
|
|
1484
|
+
style: fillStyle
|
|
1485
|
+
})
|
|
1486
|
+
]
|
|
1487
|
+
}),
|
|
1488
|
+
/* @__PURE__ */ jsx8("div", {
|
|
1489
|
+
style: knobStyle
|
|
1490
|
+
})
|
|
1491
|
+
]
|
|
1539
1492
|
});
|
|
1540
1493
|
};
|
|
1541
1494
|
|
|
1542
|
-
// src/
|
|
1543
|
-
import {
|
|
1495
|
+
// src/PlayerTimeLabel.tsx
|
|
1496
|
+
import { useMemo as useMemo7 } from "react";
|
|
1497
|
+
import { Internals as Internals7 } from "remotion";
|
|
1544
1498
|
|
|
1545
|
-
// src/
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
type: "player"
|
|
1551
|
-
});
|
|
1552
|
-
}
|
|
1553
|
-
if (playing) {
|
|
1554
|
-
return /* @__PURE__ */ jsx6(PauseIcon, {});
|
|
1555
|
-
}
|
|
1556
|
-
return /* @__PURE__ */ jsx6(PlayIcon, {});
|
|
1499
|
+
// src/format-time.ts
|
|
1500
|
+
var formatTime = (timeInSeconds) => {
|
|
1501
|
+
const minutes = Math.floor(timeInSeconds / 60);
|
|
1502
|
+
const seconds = Math.floor(timeInSeconds - minutes * 60);
|
|
1503
|
+
return `${String(minutes)}:${String(seconds).padStart(2, "0")}`;
|
|
1557
1504
|
};
|
|
1558
1505
|
|
|
1559
|
-
// src/
|
|
1560
|
-
import {
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
import React6, { useCallback as useCallback3, useMemo as useMemo3, useState as useState4 } from "react";
|
|
1565
|
-
import { random } from "remotion";
|
|
1566
|
-
import { jsx as jsx7, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
1567
|
-
var KNOB_SIZE = 12;
|
|
1568
|
-
var BAR_HEIGHT = 5;
|
|
1569
|
-
var DefaultVolumeSlider = ({
|
|
1570
|
-
volume,
|
|
1571
|
-
isVertical,
|
|
1572
|
-
onBlur,
|
|
1573
|
-
inputRef,
|
|
1574
|
-
setVolume
|
|
1575
|
-
}) => {
|
|
1576
|
-
const sliderContainer = useMemo3(() => {
|
|
1577
|
-
const paddingLeft = 5;
|
|
1578
|
-
const common = {
|
|
1579
|
-
paddingLeft,
|
|
1580
|
-
height: ICON_SIZE,
|
|
1581
|
-
width: VOLUME_SLIDER_WIDTH,
|
|
1582
|
-
display: "inline-flex",
|
|
1583
|
-
alignItems: "center"
|
|
1584
|
-
};
|
|
1585
|
-
if (isVertical) {
|
|
1586
|
-
return {
|
|
1587
|
-
...common,
|
|
1588
|
-
position: "absolute",
|
|
1589
|
-
transform: `rotate(-90deg) translateX(${VOLUME_SLIDER_WIDTH / 2 + ICON_SIZE / 2}px)`
|
|
1590
|
-
};
|
|
1591
|
-
}
|
|
1506
|
+
// src/PlayerTimeLabel.tsx
|
|
1507
|
+
import { jsxs as jsxs7 } from "react/jsx-runtime";
|
|
1508
|
+
var PlayerTimeLabel = ({ durationInFrames, maxTimeLabelWidth, fps }) => {
|
|
1509
|
+
const frame = Internals7.Timeline.useTimelinePosition();
|
|
1510
|
+
const timeLabel = useMemo7(() => {
|
|
1592
1511
|
return {
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
setVolume(parseFloat(e.target.value));
|
|
1600
|
-
}, [setVolume]);
|
|
1601
|
-
const inputStyle = useMemo3(() => {
|
|
1602
|
-
const commonStyle = {
|
|
1603
|
-
WebkitAppearance: "none",
|
|
1604
|
-
backgroundColor: "rgba(255, 255, 255, 0.5)",
|
|
1605
|
-
borderRadius: BAR_HEIGHT / 2,
|
|
1606
|
-
cursor: "pointer",
|
|
1607
|
-
height: BAR_HEIGHT,
|
|
1608
|
-
width: VOLUME_SLIDER_WIDTH,
|
|
1609
|
-
backgroundImage: `linear-gradient(
|
|
1610
|
-
to right,
|
|
1611
|
-
white ${volume * 100}%, rgba(255, 255, 255, 0) ${volume * 100}%
|
|
1612
|
-
)`
|
|
1512
|
+
color: "white",
|
|
1513
|
+
fontFamily: "sans-serif",
|
|
1514
|
+
fontSize: 14,
|
|
1515
|
+
maxWidth: maxTimeLabelWidth === null ? undefined : maxTimeLabelWidth,
|
|
1516
|
+
overflow: "hidden",
|
|
1517
|
+
textOverflow: "ellipsis"
|
|
1613
1518
|
};
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
}
|
|
1620
|
-
return commonStyle;
|
|
1621
|
-
}, [isVertical, volume]);
|
|
1622
|
-
const sliderStyle = `
|
|
1623
|
-
.${randomClass}::-webkit-slider-thumb {
|
|
1624
|
-
-webkit-appearance: none;
|
|
1625
|
-
background-color: white;
|
|
1626
|
-
border-radius: ${KNOB_SIZE / 2}px;
|
|
1627
|
-
box-shadow: 0 0 2px black;
|
|
1628
|
-
height: ${KNOB_SIZE}px;
|
|
1629
|
-
width: ${KNOB_SIZE}px;
|
|
1630
|
-
}
|
|
1631
|
-
|
|
1632
|
-
.${randomClass}::-moz-range-thumb {
|
|
1633
|
-
-webkit-appearance: none;
|
|
1634
|
-
background-color: white;
|
|
1635
|
-
border-radius: ${KNOB_SIZE / 2}px;
|
|
1636
|
-
box-shadow: 0 0 2px black;
|
|
1637
|
-
height: ${KNOB_SIZE}px;
|
|
1638
|
-
width: ${KNOB_SIZE}px;
|
|
1639
|
-
}
|
|
1640
|
-
`;
|
|
1641
|
-
return /* @__PURE__ */ jsxs3("div", {
|
|
1642
|
-
style: sliderContainer,
|
|
1519
|
+
}, [maxTimeLabelWidth]);
|
|
1520
|
+
const isLastFrame = frame === durationInFrames - 1;
|
|
1521
|
+
const frameToDisplay = isLastFrame ? frame + 1 : frame;
|
|
1522
|
+
return /* @__PURE__ */ jsxs7("div", {
|
|
1523
|
+
style: timeLabel,
|
|
1643
1524
|
children: [
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
}
|
|
1648
|
-
}),
|
|
1649
|
-
/* @__PURE__ */ jsx7("input", {
|
|
1650
|
-
ref: inputRef,
|
|
1651
|
-
"aria-label": "Change volume",
|
|
1652
|
-
className: randomClass,
|
|
1653
|
-
max: 1,
|
|
1654
|
-
min: 0,
|
|
1655
|
-
onBlur,
|
|
1656
|
-
onChange: onVolumeChange,
|
|
1657
|
-
step: 0.01,
|
|
1658
|
-
type: "range",
|
|
1659
|
-
value: volume,
|
|
1660
|
-
style: inputStyle
|
|
1661
|
-
})
|
|
1525
|
+
formatTime(frameToDisplay / fps),
|
|
1526
|
+
" / ",
|
|
1527
|
+
formatTime(durationInFrames / fps)
|
|
1662
1528
|
]
|
|
1663
1529
|
});
|
|
1664
1530
|
};
|
|
1665
|
-
var renderDefaultVolumeSlider = (props) => {
|
|
1666
|
-
return /* @__PURE__ */ jsx7(DefaultVolumeSlider, {
|
|
1667
|
-
...props
|
|
1668
|
-
});
|
|
1669
|
-
};
|
|
1670
1531
|
|
|
1671
|
-
// src/
|
|
1672
|
-
import {
|
|
1673
|
-
var
|
|
1674
|
-
var
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
const
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
if (isVolume0) {
|
|
1691
|
-
setMediaVolume(1);
|
|
1692
|
-
setPlayerMuted(false);
|
|
1693
|
-
return;
|
|
1694
|
-
}
|
|
1695
|
-
setPlayerMuted((mute) => !mute);
|
|
1696
|
-
}, [isVolume0, setPlayerMuted, setMediaVolume]);
|
|
1697
|
-
const parentDivStyle = useMemo4(() => {
|
|
1698
|
-
return {
|
|
1699
|
-
display: "inline-flex",
|
|
1700
|
-
background: "none",
|
|
1701
|
-
border: "none",
|
|
1702
|
-
justifyContent: "center",
|
|
1703
|
-
alignItems: "center",
|
|
1704
|
-
touchAction: "none",
|
|
1705
|
-
...displayVerticalVolumeSlider && { position: "relative" }
|
|
1706
|
-
};
|
|
1707
|
-
}, [displayVerticalVolumeSlider]);
|
|
1708
|
-
const volumeContainer = useMemo4(() => {
|
|
1532
|
+
// src/use-video-controls-resize.ts
|
|
1533
|
+
import { useMemo as useMemo8 } from "react";
|
|
1534
|
+
var X_SPACER = 10;
|
|
1535
|
+
var X_PADDING = 12;
|
|
1536
|
+
var useVideoControlsResize = ({
|
|
1537
|
+
allowFullscreen: allowFullScreen,
|
|
1538
|
+
playerWidth
|
|
1539
|
+
}) => {
|
|
1540
|
+
const resizeInfo = useMemo8(() => {
|
|
1541
|
+
const playPauseIconSize = ICON_SIZE;
|
|
1542
|
+
const volumeIconSize = ICON_SIZE;
|
|
1543
|
+
const _fullscreenIconSize = allowFullScreen ? fullscreenIconSize : 0;
|
|
1544
|
+
const elementsSize = volumeIconSize + playPauseIconSize + _fullscreenIconSize + X_PADDING * 2 + X_SPACER * 2;
|
|
1545
|
+
const maxTimeLabelWidth = playerWidth - elementsSize;
|
|
1546
|
+
const maxTimeLabelWidthWithoutNegativeValue = Math.max(maxTimeLabelWidth, 0);
|
|
1547
|
+
const availableTimeLabelWidthIfVolumeOpen = maxTimeLabelWidthWithoutNegativeValue - VOLUME_SLIDER_WIDTH;
|
|
1548
|
+
const computedLabelWidth = availableTimeLabelWidthIfVolumeOpen < VOLUME_SLIDER_WIDTH ? maxTimeLabelWidthWithoutNegativeValue : availableTimeLabelWidthIfVolumeOpen;
|
|
1549
|
+
const minWidthForHorizontalDisplay = computedLabelWidth + elementsSize + VOLUME_SLIDER_WIDTH;
|
|
1550
|
+
const displayVerticalVolumeSlider = playerWidth < minWidthForHorizontalDisplay;
|
|
1709
1551
|
return {
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
height: ICON_SIZE,
|
|
1713
|
-
cursor: "pointer",
|
|
1714
|
-
appearance: "none",
|
|
1715
|
-
background: "none",
|
|
1716
|
-
border: "none",
|
|
1717
|
-
padding: 0
|
|
1552
|
+
maxTimeLabelWidth: maxTimeLabelWidthWithoutNegativeValue === 0 ? null : maxTimeLabelWidthWithoutNegativeValue,
|
|
1553
|
+
displayVerticalVolumeSlider
|
|
1718
1554
|
};
|
|
1719
|
-
}, []);
|
|
1720
|
-
|
|
1721
|
-
const isMutedOrZero = muted || volume === 0;
|
|
1722
|
-
return /* @__PURE__ */ jsx8("button", {
|
|
1723
|
-
"aria-label": isMutedOrZero ? "Unmute sound" : "Mute sound",
|
|
1724
|
-
title: isMutedOrZero ? "Unmute sound" : "Mute sound",
|
|
1725
|
-
onClick,
|
|
1726
|
-
onBlur,
|
|
1727
|
-
onFocus: () => setFocused(true),
|
|
1728
|
-
style: volumeContainer,
|
|
1729
|
-
type: "button",
|
|
1730
|
-
children: isMutedOrZero ? /* @__PURE__ */ jsx8(VolumeOffIcon, {}) : /* @__PURE__ */ jsx8(VolumeOnIcon, {})
|
|
1731
|
-
});
|
|
1732
|
-
}, [onBlur, onClick, volumeContainer]);
|
|
1733
|
-
const muteButton = useMemo4(() => {
|
|
1734
|
-
return renderMuteButton ? renderMuteButton({ muted: playerMuted, volume: mediaVolume }) : renderDefaultMuteButton({ muted: playerMuted, volume: mediaVolume });
|
|
1735
|
-
}, [playerMuted, mediaVolume, renderDefaultMuteButton, renderMuteButton]);
|
|
1736
|
-
const volumeSlider = useMemo4(() => {
|
|
1737
|
-
return (focused || hover) && !playerMuted && !Internals7.isIosSafari() ? (renderVolumeSlider ?? renderDefaultVolumeSlider)({
|
|
1738
|
-
isVertical: displayVerticalVolumeSlider,
|
|
1739
|
-
volume: mediaVolume,
|
|
1740
|
-
onBlur: () => setFocused(false),
|
|
1741
|
-
inputRef,
|
|
1742
|
-
setVolume: setMediaVolume
|
|
1743
|
-
}) : null;
|
|
1744
|
-
}, [
|
|
1745
|
-
displayVerticalVolumeSlider,
|
|
1746
|
-
focused,
|
|
1747
|
-
hover,
|
|
1748
|
-
playerMuted,
|
|
1749
|
-
mediaVolume,
|
|
1750
|
-
renderVolumeSlider,
|
|
1751
|
-
setMediaVolume
|
|
1752
|
-
]);
|
|
1753
|
-
return /* @__PURE__ */ jsxs4("div", {
|
|
1754
|
-
ref: parentDivRef,
|
|
1755
|
-
style: parentDivStyle,
|
|
1756
|
-
children: [
|
|
1757
|
-
muteButton,
|
|
1758
|
-
volumeSlider
|
|
1759
|
-
]
|
|
1760
|
-
});
|
|
1555
|
+
}, [allowFullScreen, playerWidth]);
|
|
1556
|
+
return resizeInfo;
|
|
1761
1557
|
};
|
|
1762
1558
|
|
|
1763
|
-
// src/
|
|
1764
|
-
import {
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1559
|
+
// src/PlayerControls.tsx
|
|
1560
|
+
import { jsx as jsx9, jsxs as jsxs8, Fragment as Fragment2 } from "react/jsx-runtime";
|
|
1561
|
+
var gradientSteps = [
|
|
1562
|
+
0,
|
|
1563
|
+
0.013,
|
|
1564
|
+
0.049,
|
|
1565
|
+
0.104,
|
|
1566
|
+
0.175,
|
|
1567
|
+
0.259,
|
|
1568
|
+
0.352,
|
|
1569
|
+
0.45,
|
|
1570
|
+
0.55,
|
|
1571
|
+
0.648,
|
|
1572
|
+
0.741,
|
|
1573
|
+
0.825,
|
|
1574
|
+
0.896,
|
|
1575
|
+
0.951,
|
|
1576
|
+
0.987
|
|
1577
|
+
];
|
|
1578
|
+
var gradientOpacities = [
|
|
1579
|
+
0,
|
|
1580
|
+
8.1,
|
|
1581
|
+
15.5,
|
|
1582
|
+
22.5,
|
|
1583
|
+
29,
|
|
1584
|
+
35.3,
|
|
1585
|
+
41.2,
|
|
1586
|
+
47.1,
|
|
1587
|
+
52.9,
|
|
1588
|
+
58.8,
|
|
1589
|
+
64.7,
|
|
1590
|
+
71,
|
|
1591
|
+
77.5,
|
|
1592
|
+
84.5,
|
|
1593
|
+
91.9
|
|
1594
|
+
];
|
|
1595
|
+
var globalGradientOpacity = 1 / 0.7;
|
|
1596
|
+
var containerStyle2 = {
|
|
1597
|
+
boxSizing: "border-box",
|
|
1598
|
+
position: "absolute",
|
|
1599
|
+
bottom: 0,
|
|
1600
|
+
width: "100%",
|
|
1601
|
+
paddingTop: 40,
|
|
1602
|
+
paddingBottom: 10,
|
|
1603
|
+
backgroundImage: `linear-gradient(to bottom,${gradientSteps.map((g, i) => {
|
|
1604
|
+
return `hsla(0, 0%, 0%, ${g}) ${gradientOpacities[i] * globalGradientOpacity}%`;
|
|
1605
|
+
}).join(", ")}, hsl(0, 0%, 0%) 100%)`,
|
|
1606
|
+
backgroundSize: "auto 145px",
|
|
1794
1607
|
display: "flex",
|
|
1795
|
-
|
|
1796
|
-
|
|
1608
|
+
paddingRight: X_PADDING,
|
|
1609
|
+
paddingLeft: X_PADDING,
|
|
1610
|
+
flexDirection: "column",
|
|
1611
|
+
transition: "opacity 0.3s"
|
|
1797
1612
|
};
|
|
1798
|
-
var
|
|
1799
|
-
width: 22,
|
|
1613
|
+
var controlsRow = {
|
|
1800
1614
|
display: "flex",
|
|
1615
|
+
flexDirection: "row",
|
|
1616
|
+
width: "100%",
|
|
1617
|
+
alignItems: "center",
|
|
1618
|
+
justifyContent: "center",
|
|
1619
|
+
userSelect: "none",
|
|
1620
|
+
WebkitUserSelect: "none"
|
|
1621
|
+
};
|
|
1622
|
+
var leftPartStyle = {
|
|
1623
|
+
display: "flex",
|
|
1624
|
+
flexDirection: "row",
|
|
1625
|
+
userSelect: "none",
|
|
1626
|
+
WebkitUserSelect: "none",
|
|
1801
1627
|
alignItems: "center"
|
|
1802
1628
|
};
|
|
1803
|
-
var
|
|
1804
|
-
width:
|
|
1805
|
-
height: 14,
|
|
1806
|
-
color: "black"
|
|
1629
|
+
var xSpacer = {
|
|
1630
|
+
width: 12
|
|
1807
1631
|
};
|
|
1808
|
-
var
|
|
1809
|
-
|
|
1810
|
-
style: checkmarkStyle,
|
|
1811
|
-
children: /* @__PURE__ */ jsx9("path", {
|
|
1812
|
-
fill: "currentColor",
|
|
1813
|
-
d: "M435.848 83.466L172.804 346.51l-96.652-96.652c-4.686-4.686-12.284-4.686-16.971 0l-28.284 28.284c-4.686 4.686-4.686 12.284 0 16.971l133.421 133.421c4.686 4.686 12.284 4.686 16.971 0l299.813-299.813c4.686-4.686 4.686-12.284 0-16.971l-28.284-28.284c-4.686-4.686-12.284-4.686-16.97 0z"
|
|
1814
|
-
})
|
|
1815
|
-
});
|
|
1816
|
-
var formatPlaybackRate = (rate) => {
|
|
1817
|
-
const str = rate.toString();
|
|
1818
|
-
return str.includes(".") ? str : str + ".0";
|
|
1632
|
+
var ySpacer = {
|
|
1633
|
+
height: 8
|
|
1819
1634
|
};
|
|
1820
|
-
var
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1635
|
+
var flex1 = {
|
|
1636
|
+
flex: 1
|
|
1637
|
+
};
|
|
1638
|
+
var fullscreen = {};
|
|
1639
|
+
var Controls = ({
|
|
1640
|
+
durationInFrames,
|
|
1641
|
+
isFullscreen,
|
|
1642
|
+
fps,
|
|
1643
|
+
showVolumeControls,
|
|
1644
|
+
onFullscreenButtonClick,
|
|
1645
|
+
allowFullscreen,
|
|
1646
|
+
onExitFullscreenButtonClick,
|
|
1647
|
+
spaceKeyToPlayOrPause,
|
|
1648
|
+
onSeekEnd,
|
|
1649
|
+
onSeekStart,
|
|
1650
|
+
inFrame,
|
|
1651
|
+
outFrame,
|
|
1652
|
+
initiallyShowControls,
|
|
1653
|
+
canvasSize,
|
|
1654
|
+
renderPlayPauseButton,
|
|
1655
|
+
renderFullscreenButton,
|
|
1656
|
+
alwaysShowControls,
|
|
1657
|
+
showPlaybackRateControl,
|
|
1658
|
+
containerRef,
|
|
1659
|
+
buffering,
|
|
1660
|
+
hideControlsWhenPointerDoesntMove,
|
|
1661
|
+
onPointerDown,
|
|
1662
|
+
onDoubleClick,
|
|
1663
|
+
renderMuteButton,
|
|
1664
|
+
renderVolumeSlider,
|
|
1665
|
+
playing,
|
|
1666
|
+
toggle,
|
|
1667
|
+
renderCustomControls
|
|
1668
|
+
}) => {
|
|
1669
|
+
const playButtonRef = useRef5(null);
|
|
1670
|
+
const [supportsFullscreen, setSupportsFullscreen] = useState9(false);
|
|
1671
|
+
const hovered = useHoverState(containerRef, hideControlsWhenPointerDoesntMove);
|
|
1672
|
+
const { maxTimeLabelWidth, displayVerticalVolumeSlider } = useVideoControlsResize({
|
|
1673
|
+
allowFullscreen,
|
|
1674
|
+
playerWidth: canvasSize?.width ?? 0
|
|
1675
|
+
});
|
|
1676
|
+
const [shouldShowInitially, setInitiallyShowControls] = useState9(() => {
|
|
1677
|
+
if (typeof initiallyShowControls === "boolean") {
|
|
1678
|
+
return initiallyShowControls;
|
|
1679
|
+
}
|
|
1680
|
+
if (typeof initiallyShowControls === "number") {
|
|
1681
|
+
if (initiallyShowControls % 1 !== 0) {
|
|
1682
|
+
throw new Error("initiallyShowControls must be an integer or a boolean");
|
|
1683
|
+
}
|
|
1684
|
+
if (Number.isNaN(initiallyShowControls)) {
|
|
1685
|
+
throw new Error("initiallyShowControls must not be NaN");
|
|
1686
|
+
}
|
|
1687
|
+
if (!Number.isFinite(initiallyShowControls)) {
|
|
1688
|
+
throw new Error("initiallyShowControls must be finite");
|
|
1689
|
+
}
|
|
1690
|
+
if (initiallyShowControls <= 0) {
|
|
1691
|
+
throw new Error("initiallyShowControls must be a positive integer");
|
|
1692
|
+
}
|
|
1693
|
+
return initiallyShowControls;
|
|
1694
|
+
}
|
|
1695
|
+
throw new TypeError("initiallyShowControls must be a number or a boolean");
|
|
1696
|
+
});
|
|
1697
|
+
const containerCss = useMemo9(() => {
|
|
1698
|
+
const shouldShow = hovered || !playing || shouldShowInitially || alwaysShowControls;
|
|
1835
1699
|
return {
|
|
1836
|
-
...
|
|
1837
|
-
|
|
1700
|
+
...containerStyle2,
|
|
1701
|
+
opacity: Number(shouldShow)
|
|
1838
1702
|
};
|
|
1839
|
-
}, [hovered,
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1703
|
+
}, [hovered, shouldShowInitially, playing, alwaysShowControls]);
|
|
1704
|
+
useEffect7(() => {
|
|
1705
|
+
if (playButtonRef.current && spaceKeyToPlayOrPause) {
|
|
1706
|
+
playButtonRef.current.focus({
|
|
1707
|
+
preventScroll: true
|
|
1708
|
+
});
|
|
1709
|
+
}
|
|
1710
|
+
}, [playing, spaceKeyToPlayOrPause]);
|
|
1711
|
+
useEffect7(() => {
|
|
1712
|
+
setSupportsFullscreen((typeof document !== "undefined" && (document.fullscreenEnabled || document.webkitFullscreenEnabled)) ?? false);
|
|
1713
|
+
}, []);
|
|
1714
|
+
useEffect7(() => {
|
|
1715
|
+
if (shouldShowInitially === false) {
|
|
1716
|
+
return;
|
|
1717
|
+
}
|
|
1718
|
+
const time = shouldShowInitially === true ? 2000 : shouldShowInitially;
|
|
1719
|
+
const timeout = setTimeout(() => {
|
|
1720
|
+
setInitiallyShowControls(false);
|
|
1721
|
+
}, time);
|
|
1722
|
+
return () => {
|
|
1723
|
+
clearInterval(timeout);
|
|
1724
|
+
};
|
|
1725
|
+
}, [shouldShowInitially]);
|
|
1726
|
+
const playbackRates = useMemo9(() => {
|
|
1727
|
+
if (showPlaybackRateControl === true) {
|
|
1728
|
+
return [0.5, 0.8, 1, 1.2, 1.5, 1.8, 2, 2.5, 3];
|
|
1729
|
+
}
|
|
1730
|
+
if (Array.isArray(showPlaybackRateControl)) {
|
|
1731
|
+
for (const rate of showPlaybackRateControl) {
|
|
1732
|
+
if (typeof rate !== "number") {
|
|
1733
|
+
throw new Error("Every item in showPlaybackRateControl must be a number");
|
|
1734
|
+
}
|
|
1735
|
+
if (rate <= 0) {
|
|
1736
|
+
throw new Error("Every item in showPlaybackRateControl must be positive");
|
|
1737
|
+
}
|
|
1738
|
+
}
|
|
1739
|
+
return showPlaybackRateControl;
|
|
1740
|
+
}
|
|
1741
|
+
return null;
|
|
1742
|
+
}, [showPlaybackRateControl]);
|
|
1743
|
+
const customControlsElement = renderCustomControls ? renderCustomControls() : null;
|
|
1744
|
+
const ref = useRef5(null);
|
|
1745
|
+
const flexRef = useRef5(null);
|
|
1746
|
+
const onPointerDownIfContainer = useCallback7((e) => {
|
|
1747
|
+
if (e.target === ref.current || e.target === flexRef.current) {
|
|
1748
|
+
onPointerDown?.(e);
|
|
1749
|
+
}
|
|
1750
|
+
}, [onPointerDown]);
|
|
1751
|
+
const onDoubleClickIfContainer = useCallback7((e) => {
|
|
1752
|
+
if (e.target === ref.current || e.target === flexRef.current) {
|
|
1753
|
+
onDoubleClick?.(e);
|
|
1754
|
+
}
|
|
1755
|
+
}, [onDoubleClick]);
|
|
1756
|
+
return /* @__PURE__ */ jsxs8("div", {
|
|
1757
|
+
ref,
|
|
1758
|
+
style: containerCss,
|
|
1759
|
+
onPointerDown: onPointerDownIfContainer,
|
|
1760
|
+
onDoubleClick: onDoubleClickIfContainer,
|
|
1846
1761
|
children: [
|
|
1762
|
+
/* @__PURE__ */ jsxs8("div", {
|
|
1763
|
+
ref: flexRef,
|
|
1764
|
+
style: controlsRow,
|
|
1765
|
+
children: [
|
|
1766
|
+
/* @__PURE__ */ jsxs8("div", {
|
|
1767
|
+
style: leftPartStyle,
|
|
1768
|
+
children: [
|
|
1769
|
+
/* @__PURE__ */ jsx9("button", {
|
|
1770
|
+
ref: playButtonRef,
|
|
1771
|
+
type: "button",
|
|
1772
|
+
style: playerButtonStyle,
|
|
1773
|
+
onClick: toggle,
|
|
1774
|
+
"aria-label": playing ? "Pause video" : "Play video",
|
|
1775
|
+
title: playing ? "Pause video" : "Play video",
|
|
1776
|
+
children: renderPlayPauseButton === null ? /* @__PURE__ */ jsx9(DefaultPlayPauseButton, {
|
|
1777
|
+
buffering,
|
|
1778
|
+
playing
|
|
1779
|
+
}) : renderPlayPauseButton({
|
|
1780
|
+
playing,
|
|
1781
|
+
isBuffering: buffering
|
|
1782
|
+
}) ?? /* @__PURE__ */ jsx9(DefaultPlayPauseButton, {
|
|
1783
|
+
buffering,
|
|
1784
|
+
playing
|
|
1785
|
+
})
|
|
1786
|
+
}),
|
|
1787
|
+
showVolumeControls ? /* @__PURE__ */ jsxs8(Fragment2, {
|
|
1788
|
+
children: [
|
|
1789
|
+
/* @__PURE__ */ jsx9("div", {
|
|
1790
|
+
style: xSpacer
|
|
1791
|
+
}),
|
|
1792
|
+
/* @__PURE__ */ jsx9(MediaVolumeSlider, {
|
|
1793
|
+
renderMuteButton,
|
|
1794
|
+
renderVolumeSlider,
|
|
1795
|
+
displayVerticalVolumeSlider
|
|
1796
|
+
})
|
|
1797
|
+
]
|
|
1798
|
+
}) : null,
|
|
1799
|
+
/* @__PURE__ */ jsx9("div", {
|
|
1800
|
+
style: xSpacer
|
|
1801
|
+
}),
|
|
1802
|
+
/* @__PURE__ */ jsx9(PlayerTimeLabel, {
|
|
1803
|
+
durationInFrames,
|
|
1804
|
+
fps,
|
|
1805
|
+
maxTimeLabelWidth
|
|
1806
|
+
}),
|
|
1807
|
+
/* @__PURE__ */ jsx9("div", {
|
|
1808
|
+
style: xSpacer
|
|
1809
|
+
})
|
|
1810
|
+
]
|
|
1811
|
+
}),
|
|
1812
|
+
/* @__PURE__ */ jsx9("div", {
|
|
1813
|
+
style: flex1
|
|
1814
|
+
}),
|
|
1815
|
+
customControlsElement,
|
|
1816
|
+
customControlsElement && playbackRates && canvasSize ? /* @__PURE__ */ jsx9("div", {
|
|
1817
|
+
style: xSpacer
|
|
1818
|
+
}) : null,
|
|
1819
|
+
playbackRates && canvasSize && /* @__PURE__ */ jsx9(PlaybackrateControl, {
|
|
1820
|
+
canvasSize,
|
|
1821
|
+
playbackRates
|
|
1822
|
+
}),
|
|
1823
|
+
playbackRates && supportsFullscreen && allowFullscreen ? /* @__PURE__ */ jsx9("div", {
|
|
1824
|
+
style: xSpacer
|
|
1825
|
+
}) : null,
|
|
1826
|
+
/* @__PURE__ */ jsx9("div", {
|
|
1827
|
+
style: fullscreen,
|
|
1828
|
+
children: supportsFullscreen && allowFullscreen ? /* @__PURE__ */ jsx9("button", {
|
|
1829
|
+
type: "button",
|
|
1830
|
+
"aria-label": isFullscreen ? "Exit fullscreen" : "Enter Fullscreen",
|
|
1831
|
+
title: isFullscreen ? "Exit fullscreen" : "Enter Fullscreen",
|
|
1832
|
+
style: playerButtonStyle,
|
|
1833
|
+
onClick: isFullscreen ? onExitFullscreenButtonClick : onFullscreenButtonClick,
|
|
1834
|
+
children: renderFullscreenButton === null ? /* @__PURE__ */ jsx9(FullscreenIcon, {
|
|
1835
|
+
isFullscreen
|
|
1836
|
+
}) : renderFullscreenButton({ isFullscreen })
|
|
1837
|
+
}) : null
|
|
1838
|
+
})
|
|
1839
|
+
]
|
|
1840
|
+
}),
|
|
1847
1841
|
/* @__PURE__ */ jsx9("div", {
|
|
1848
|
-
style:
|
|
1849
|
-
children: rate === selectedRate ? /* @__PURE__ */ jsx9(Checkmark, {}) : null
|
|
1842
|
+
style: ySpacer
|
|
1850
1843
|
}),
|
|
1851
|
-
|
|
1852
|
-
|
|
1844
|
+
/* @__PURE__ */ jsx9(PlayerSeekBar, {
|
|
1845
|
+
onSeekEnd,
|
|
1846
|
+
onSeekStart,
|
|
1847
|
+
durationInFrames,
|
|
1848
|
+
inFrame,
|
|
1849
|
+
outFrame
|
|
1850
|
+
})
|
|
1853
1851
|
]
|
|
1854
|
-
}
|
|
1852
|
+
});
|
|
1855
1853
|
};
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1854
|
+
|
|
1855
|
+
// src/timeline-sequence-observer-context.ts
|
|
1856
|
+
import React8 from "react";
|
|
1857
|
+
var TimelineSequenceObserverContext = React8.createContext(null);
|
|
1858
|
+
|
|
1859
|
+
// src/use-playback.ts
|
|
1860
|
+
import { useLayoutEffect as useLayoutEffect2 } from "react";
|
|
1861
|
+
import { useContext as useContext3, useEffect as useEffect10, useRef as useRef8 } from "react";
|
|
1862
|
+
import { Internals as Internals10 } from "remotion";
|
|
1863
|
+
|
|
1864
|
+
// src/browser-mediasession.ts
|
|
1865
|
+
import { useEffect as useEffect8, useRef as useRef6 } from "react";
|
|
1866
|
+
import { Internals as Internals8 } from "remotion";
|
|
1867
|
+
var useBrowserMediaSession = ({
|
|
1868
|
+
browserMediaControlsBehavior,
|
|
1869
|
+
videoConfig,
|
|
1870
|
+
playbackRate
|
|
1871
|
+
}) => {
|
|
1872
|
+
const playing = Internals8.usePlaying();
|
|
1873
|
+
const { pause, play, emitter, getCurrentFrame, seek } = usePlayerMethods();
|
|
1874
|
+
const hasEverPlayed = useRef6(false);
|
|
1875
|
+
useEffect8(() => {
|
|
1876
|
+
if (playing) {
|
|
1877
|
+
hasEverPlayed.current = true;
|
|
1878
|
+
}
|
|
1879
|
+
if (!navigator.mediaSession) {
|
|
1880
|
+
return;
|
|
1881
|
+
}
|
|
1882
|
+
if (browserMediaControlsBehavior.mode === "do-nothing") {
|
|
1883
|
+
return;
|
|
1884
|
+
}
|
|
1885
|
+
if (playing) {
|
|
1886
|
+
navigator.mediaSession.playbackState = "playing";
|
|
1887
|
+
} else if (hasEverPlayed.current) {
|
|
1888
|
+
navigator.mediaSession.playbackState = "paused";
|
|
1889
|
+
}
|
|
1890
|
+
}, [browserMediaControlsBehavior.mode, playing]);
|
|
1891
|
+
useEffect8(() => {
|
|
1892
|
+
if (!navigator.mediaSession) {
|
|
1893
|
+
return;
|
|
1894
|
+
}
|
|
1895
|
+
if (browserMediaControlsBehavior.mode === "do-nothing") {
|
|
1896
|
+
return;
|
|
1897
|
+
}
|
|
1898
|
+
const onTimeUpdate = () => {
|
|
1899
|
+
if (!videoConfig) {
|
|
1900
|
+
return;
|
|
1901
|
+
}
|
|
1902
|
+
if (navigator.mediaSession) {
|
|
1903
|
+
navigator.mediaSession.setPositionState({
|
|
1904
|
+
duration: videoConfig.durationInFrames / videoConfig.fps,
|
|
1905
|
+
playbackRate,
|
|
1906
|
+
position: getCurrentFrame() / videoConfig.fps
|
|
1907
|
+
});
|
|
1895
1908
|
}
|
|
1896
1909
|
};
|
|
1897
|
-
|
|
1910
|
+
emitter.addEventListener("timeupdate", onTimeUpdate);
|
|
1898
1911
|
return () => {
|
|
1899
|
-
|
|
1912
|
+
emitter.removeEventListener("timeupdate", onTimeUpdate);
|
|
1900
1913
|
};
|
|
1901
1914
|
}, [
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1915
|
+
browserMediaControlsBehavior.mode,
|
|
1916
|
+
emitter,
|
|
1917
|
+
getCurrentFrame,
|
|
1918
|
+
playbackRate,
|
|
1919
|
+
videoConfig
|
|
1906
1920
|
]);
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
setIsComponentVisible(false);
|
|
1910
|
-
}, [setIsComponentVisible, setPlaybackRate]);
|
|
1911
|
-
const playbackPopup = useMemo5(() => {
|
|
1912
|
-
return {
|
|
1913
|
-
position: "absolute",
|
|
1914
|
-
right: 0,
|
|
1915
|
-
width: 125,
|
|
1916
|
-
maxHeight: canvasSize.height - THRESHOLD - BOTTOM,
|
|
1917
|
-
bottom: 35,
|
|
1918
|
-
background: "#fff",
|
|
1919
|
-
borderRadius: 4,
|
|
1920
|
-
overflow: "auto",
|
|
1921
|
-
color: "black",
|
|
1922
|
-
textAlign: "left"
|
|
1923
|
-
};
|
|
1924
|
-
}, [canvasSize.height]);
|
|
1925
|
-
return /* @__PURE__ */ jsx9("div", {
|
|
1926
|
-
style: playbackPopup,
|
|
1927
|
-
children: playbackRates.map((rate) => {
|
|
1928
|
-
return /* @__PURE__ */ jsx9(PlaybackrateOption, {
|
|
1929
|
-
selectedRate: playbackRate,
|
|
1930
|
-
onSelect,
|
|
1931
|
-
rate,
|
|
1932
|
-
keyboardSelectedRate
|
|
1933
|
-
}, rate);
|
|
1934
|
-
})
|
|
1935
|
-
});
|
|
1936
|
-
};
|
|
1937
|
-
var label = {
|
|
1938
|
-
fontSize: 13,
|
|
1939
|
-
fontWeight: "bold",
|
|
1940
|
-
color: "white",
|
|
1941
|
-
border: "2px solid white",
|
|
1942
|
-
borderRadius: 20,
|
|
1943
|
-
paddingLeft: 8,
|
|
1944
|
-
paddingRight: 8,
|
|
1945
|
-
paddingTop: 2,
|
|
1946
|
-
paddingBottom: 2
|
|
1947
|
-
};
|
|
1948
|
-
var playerButtonStyle = {
|
|
1949
|
-
appearance: "none",
|
|
1950
|
-
backgroundColor: "transparent",
|
|
1951
|
-
border: "none",
|
|
1952
|
-
cursor: "pointer",
|
|
1953
|
-
paddingLeft: 0,
|
|
1954
|
-
paddingRight: 0,
|
|
1955
|
-
paddingTop: 6,
|
|
1956
|
-
paddingBottom: 6,
|
|
1957
|
-
height: 37,
|
|
1958
|
-
display: "inline-flex",
|
|
1959
|
-
marginBottom: 0,
|
|
1960
|
-
marginTop: 0,
|
|
1961
|
-
alignItems: "center"
|
|
1962
|
-
};
|
|
1963
|
-
var button = {
|
|
1964
|
-
...playerButtonStyle,
|
|
1965
|
-
position: "relative"
|
|
1966
|
-
};
|
|
1967
|
-
var PlaybackrateControl = ({ playbackRates, canvasSize }) => {
|
|
1968
|
-
const { ref, isComponentVisible, setIsComponentVisible } = useComponentVisible(false);
|
|
1969
|
-
const { playbackRate } = Internals8.usePlaybackRate();
|
|
1970
|
-
const onClick = useCallback5((e) => {
|
|
1971
|
-
e.stopPropagation();
|
|
1972
|
-
e.preventDefault();
|
|
1973
|
-
setIsComponentVisible((prevIsComponentVisible) => !prevIsComponentVisible);
|
|
1974
|
-
}, [setIsComponentVisible]);
|
|
1975
|
-
return /* @__PURE__ */ jsx9("div", {
|
|
1976
|
-
ref,
|
|
1977
|
-
children: /* @__PURE__ */ jsxs5("button", {
|
|
1978
|
-
type: "button",
|
|
1979
|
-
"aria-label": "Change playback rate",
|
|
1980
|
-
style: button,
|
|
1981
|
-
onClick,
|
|
1982
|
-
children: [
|
|
1983
|
-
/* @__PURE__ */ jsxs5("div", {
|
|
1984
|
-
style: label,
|
|
1985
|
-
children: [
|
|
1986
|
-
playbackRate,
|
|
1987
|
-
"x"
|
|
1988
|
-
]
|
|
1989
|
-
}),
|
|
1990
|
-
isComponentVisible && /* @__PURE__ */ jsx9(PlaybackPopup, {
|
|
1991
|
-
canvasSize,
|
|
1992
|
-
playbackRates,
|
|
1993
|
-
setIsComponentVisible
|
|
1994
|
-
})
|
|
1995
|
-
]
|
|
1996
|
-
})
|
|
1997
|
-
});
|
|
1998
|
-
};
|
|
1999
|
-
|
|
2000
|
-
// src/PlayerSeekBar.tsx
|
|
2001
|
-
import { useCallback as useCallback6, useEffect as useEffect10, useMemo as useMemo6, useRef as useRef7, useState as useState8 } from "react";
|
|
2002
|
-
import { Internals as Internals9, interpolate } from "remotion";
|
|
2003
|
-
import { jsx as jsx10, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
2004
|
-
var getFrameFromX = (clientX, durationInFrames, width) => {
|
|
2005
|
-
const pos = clientX;
|
|
2006
|
-
const frame = Math.round(interpolate(pos, [0, width], [0, durationInFrames - 1], {
|
|
2007
|
-
extrapolateLeft: "clamp",
|
|
2008
|
-
extrapolateRight: "clamp"
|
|
2009
|
-
}));
|
|
2010
|
-
return frame;
|
|
2011
|
-
};
|
|
2012
|
-
var BAR_HEIGHT2 = 5;
|
|
2013
|
-
var KNOB_SIZE2 = 12;
|
|
2014
|
-
var VERTICAL_PADDING = 4;
|
|
2015
|
-
var containerStyle = {
|
|
2016
|
-
userSelect: "none",
|
|
2017
|
-
WebkitUserSelect: "none",
|
|
2018
|
-
paddingTop: VERTICAL_PADDING,
|
|
2019
|
-
paddingBottom: VERTICAL_PADDING,
|
|
2020
|
-
boxSizing: "border-box",
|
|
2021
|
-
cursor: "pointer",
|
|
2022
|
-
position: "relative",
|
|
2023
|
-
touchAction: "none"
|
|
2024
|
-
};
|
|
2025
|
-
var barBackground = {
|
|
2026
|
-
height: BAR_HEIGHT2,
|
|
2027
|
-
backgroundColor: "rgba(255, 255, 255, 0.25)",
|
|
2028
|
-
width: "100%",
|
|
2029
|
-
borderRadius: BAR_HEIGHT2 / 2
|
|
2030
|
-
};
|
|
2031
|
-
var findBodyInWhichDivIsLocated = (div) => {
|
|
2032
|
-
let current = div;
|
|
2033
|
-
while (current.parentElement) {
|
|
2034
|
-
current = current.parentElement;
|
|
2035
|
-
}
|
|
2036
|
-
return current;
|
|
2037
|
-
};
|
|
2038
|
-
var PlayerSeekBar = ({ durationInFrames, onSeekEnd, onSeekStart, inFrame, outFrame }) => {
|
|
2039
|
-
const containerRef = useRef7(null);
|
|
2040
|
-
const barHovered = useHoverState(containerRef, false);
|
|
2041
|
-
const size = useElementSize(containerRef, {
|
|
2042
|
-
triggerOnWindowResize: true,
|
|
2043
|
-
shouldApplyCssTransforms: true
|
|
2044
|
-
});
|
|
2045
|
-
const { seek, play, pause, isPlaying } = usePlayerMethods();
|
|
2046
|
-
const frame = Internals9.Timeline.useTimelinePosition();
|
|
2047
|
-
const [dragging, setDragging] = useState8({
|
|
2048
|
-
dragging: false
|
|
2049
|
-
});
|
|
2050
|
-
const width = size?.width ?? 0;
|
|
2051
|
-
const onPointerDown = useCallback6((e) => {
|
|
2052
|
-
if (e.button !== 0) {
|
|
1921
|
+
useEffect8(() => {
|
|
1922
|
+
if (!navigator.mediaSession) {
|
|
2053
1923
|
return;
|
|
2054
1924
|
}
|
|
2055
|
-
|
|
2056
|
-
const _frame = getFrameFromX(e.clientX - posLeft, durationInFrames, width);
|
|
2057
|
-
const wasPlaying = isPlaying();
|
|
2058
|
-
pause();
|
|
2059
|
-
seek(_frame);
|
|
2060
|
-
setDragging({
|
|
2061
|
-
dragging: true,
|
|
2062
|
-
wasPlaying
|
|
2063
|
-
});
|
|
2064
|
-
onSeekStart();
|
|
2065
|
-
}, [durationInFrames, width, isPlaying, pause, seek, onSeekStart]);
|
|
2066
|
-
const onPointerMove = useCallback6((e) => {
|
|
2067
|
-
if (!size) {
|
|
2068
|
-
throw new Error("Player has no size");
|
|
2069
|
-
}
|
|
2070
|
-
if (!dragging.dragging) {
|
|
1925
|
+
if (browserMediaControlsBehavior.mode === "do-nothing") {
|
|
2071
1926
|
return;
|
|
2072
1927
|
}
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
const onPointerUp = useCallback6(() => {
|
|
2078
|
-
setDragging({
|
|
2079
|
-
dragging: false
|
|
1928
|
+
navigator.mediaSession.setActionHandler("play", () => {
|
|
1929
|
+
if (browserMediaControlsBehavior.mode === "register-media-session") {
|
|
1930
|
+
play();
|
|
1931
|
+
}
|
|
2080
1932
|
});
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
|
|
2086
|
-
|
|
2087
|
-
|
|
1933
|
+
navigator.mediaSession.setActionHandler("pause", () => {
|
|
1934
|
+
if (browserMediaControlsBehavior.mode === "register-media-session") {
|
|
1935
|
+
pause();
|
|
1936
|
+
}
|
|
1937
|
+
});
|
|
1938
|
+
navigator.mediaSession.setActionHandler("seekto", (event) => {
|
|
1939
|
+
if (browserMediaControlsBehavior.mode === "register-media-session" && event.seekTime !== undefined && videoConfig) {
|
|
1940
|
+
seek(Math.round(event.seekTime * videoConfig.fps));
|
|
1941
|
+
}
|
|
1942
|
+
});
|
|
1943
|
+
navigator.mediaSession.setActionHandler("seekbackward", () => {
|
|
1944
|
+
if (browserMediaControlsBehavior.mode === "register-media-session" && videoConfig) {
|
|
1945
|
+
seek(Math.max(0, Math.round(getCurrentFrame() - 10 * videoConfig.fps)));
|
|
1946
|
+
}
|
|
1947
|
+
});
|
|
1948
|
+
navigator.mediaSession.setActionHandler("seekforward", () => {
|
|
1949
|
+
if (browserMediaControlsBehavior.mode === "register-media-session" && videoConfig) {
|
|
1950
|
+
seek(Math.min(videoConfig.durationInFrames - 1, Math.round(getCurrentFrame() + 10 * videoConfig.fps)));
|
|
1951
|
+
}
|
|
1952
|
+
});
|
|
1953
|
+
navigator.mediaSession.setActionHandler("previoustrack", () => {
|
|
1954
|
+
if (browserMediaControlsBehavior.mode === "register-media-session") {
|
|
1955
|
+
seek(0);
|
|
1956
|
+
}
|
|
1957
|
+
});
|
|
1958
|
+
return () => {
|
|
1959
|
+
navigator.mediaSession.metadata = null;
|
|
1960
|
+
navigator.mediaSession.setActionHandler("play", null);
|
|
1961
|
+
navigator.mediaSession.setActionHandler("pause", null);
|
|
1962
|
+
navigator.mediaSession.setActionHandler("seekto", null);
|
|
1963
|
+
navigator.mediaSession.setActionHandler("seekbackward", null);
|
|
1964
|
+
navigator.mediaSession.setActionHandler("seekforward", null);
|
|
1965
|
+
navigator.mediaSession.setActionHandler("previoustrack", null);
|
|
1966
|
+
};
|
|
1967
|
+
}, [
|
|
1968
|
+
browserMediaControlsBehavior.mode,
|
|
1969
|
+
getCurrentFrame,
|
|
1970
|
+
pause,
|
|
1971
|
+
play,
|
|
1972
|
+
seek,
|
|
1973
|
+
videoConfig
|
|
1974
|
+
]);
|
|
1975
|
+
};
|
|
1976
|
+
|
|
1977
|
+
// src/calculate-next-frame.ts
|
|
1978
|
+
var calculateNextFrame = ({
|
|
1979
|
+
time,
|
|
1980
|
+
currentFrame: startFrame,
|
|
1981
|
+
playbackSpeed,
|
|
1982
|
+
fps,
|
|
1983
|
+
actualLastFrame,
|
|
1984
|
+
actualFirstFrame,
|
|
1985
|
+
framesAdvanced,
|
|
1986
|
+
shouldLoop
|
|
1987
|
+
}) => {
|
|
1988
|
+
const op = playbackSpeed < 0 ? Math.ceil : Math.floor;
|
|
1989
|
+
const framesToAdvance = op(time * playbackSpeed / (1000 / fps)) - framesAdvanced;
|
|
1990
|
+
const nextFrame = framesToAdvance + startFrame;
|
|
1991
|
+
const isCurrentFrameOutside = startFrame > actualLastFrame || startFrame < actualFirstFrame;
|
|
1992
|
+
const isNextFrameOutside = nextFrame > actualLastFrame || nextFrame < actualFirstFrame;
|
|
1993
|
+
const hasEnded = !shouldLoop && isNextFrameOutside && !isCurrentFrameOutside;
|
|
1994
|
+
if (shouldLoop && isNextFrameOutside && !isCurrentFrameOutside) {
|
|
1995
|
+
const playbackRange = actualLastFrame - actualFirstFrame + 1;
|
|
1996
|
+
const frameWithinRange = (nextFrame - actualFirstFrame) % playbackRange;
|
|
1997
|
+
return {
|
|
1998
|
+
nextFrame: actualFirstFrame + (frameWithinRange + playbackRange) % playbackRange,
|
|
1999
|
+
framesToAdvance,
|
|
2000
|
+
hasEnded
|
|
2001
|
+
};
|
|
2002
|
+
}
|
|
2003
|
+
if (playbackSpeed > 0) {
|
|
2004
|
+
if (isNextFrameOutside) {
|
|
2005
|
+
return {
|
|
2006
|
+
nextFrame: actualFirstFrame,
|
|
2007
|
+
framesToAdvance,
|
|
2008
|
+
hasEnded
|
|
2009
|
+
};
|
|
2088
2010
|
}
|
|
2089
|
-
|
|
2090
|
-
}
|
|
2011
|
+
return { nextFrame, framesToAdvance, hasEnded };
|
|
2012
|
+
}
|
|
2013
|
+
if (isNextFrameOutside) {
|
|
2014
|
+
return { nextFrame: actualLastFrame, framesToAdvance, hasEnded };
|
|
2015
|
+
}
|
|
2016
|
+
return { nextFrame, framesToAdvance, hasEnded };
|
|
2017
|
+
};
|
|
2018
|
+
|
|
2019
|
+
// src/is-backgrounded.ts
|
|
2020
|
+
import { useEffect as useEffect9, useRef as useRef7 } from "react";
|
|
2021
|
+
var getIsBackgrounded = () => {
|
|
2022
|
+
if (typeof document === "undefined") {
|
|
2023
|
+
return false;
|
|
2024
|
+
}
|
|
2025
|
+
return document.visibilityState === "hidden";
|
|
2026
|
+
};
|
|
2027
|
+
var useIsBackgrounded = () => {
|
|
2028
|
+
const isBackgrounded = useRef7(getIsBackgrounded());
|
|
2029
|
+
useEffect9(() => {
|
|
2030
|
+
const onVisibilityChange = () => {
|
|
2031
|
+
isBackgrounded.current = getIsBackgrounded();
|
|
2032
|
+
};
|
|
2033
|
+
document.addEventListener("visibilitychange", onVisibilityChange);
|
|
2034
|
+
return () => {
|
|
2035
|
+
document.removeEventListener("visibilitychange", onVisibilityChange);
|
|
2036
|
+
};
|
|
2037
|
+
}, []);
|
|
2038
|
+
return isBackgrounded;
|
|
2039
|
+
};
|
|
2040
|
+
|
|
2041
|
+
// src/set-global-time-anchor.ts
|
|
2042
|
+
import { Internals as Internals9 } from "remotion";
|
|
2043
|
+
var setGlobalTimeAnchor = ({
|
|
2044
|
+
audioContext,
|
|
2045
|
+
audioSyncAnchor,
|
|
2046
|
+
absoluteTimeInSeconds,
|
|
2047
|
+
globalPlaybackRate,
|
|
2048
|
+
logLevel,
|
|
2049
|
+
force
|
|
2050
|
+
}) => {
|
|
2051
|
+
const newAnchor = audioContext.currentTime - absoluteTimeInSeconds / globalPlaybackRate;
|
|
2052
|
+
const shift = newAnchor - audioSyncAnchor.value;
|
|
2053
|
+
const tolerance = Internals9.getAudioSyncAnchorTolerance(audioContext);
|
|
2054
|
+
if (Math.abs(shift) < tolerance && !force) {
|
|
2055
|
+
return false;
|
|
2056
|
+
}
|
|
2057
|
+
if (Math.abs(shift) < Number.EPSILON) {
|
|
2058
|
+
return false;
|
|
2059
|
+
}
|
|
2060
|
+
Internals9.Log.verbose({ logLevel, tag: "audio-scheduling" }, "Anchor " + (force ? "forcibly " : "") + "changed from %s to %s with shift %s", audioSyncAnchor.value, newAnchor, shift);
|
|
2061
|
+
audioSyncAnchor.value = newAnchor;
|
|
2062
|
+
return true;
|
|
2063
|
+
};
|
|
2064
|
+
|
|
2065
|
+
// src/use-playback.ts
|
|
2066
|
+
var shouldForceAnchorChange = (newState) => {
|
|
2067
|
+
if (newState === "suspended" || newState === "running-to-suspended") {
|
|
2068
|
+
return true;
|
|
2069
|
+
}
|
|
2070
|
+
if (newState === "closed" || newState === "interrupted" || newState === "running" || newState === "suspended-to-running") {
|
|
2071
|
+
return false;
|
|
2072
|
+
}
|
|
2073
|
+
throw new Error(`Unexpected audio context state: ${newState}`);
|
|
2074
|
+
};
|
|
2075
|
+
var usePlayback = ({
|
|
2076
|
+
loop,
|
|
2077
|
+
playbackRate,
|
|
2078
|
+
moveToBeginningWhenEnded,
|
|
2079
|
+
inFrame,
|
|
2080
|
+
outFrame,
|
|
2081
|
+
browserMediaControlsBehavior,
|
|
2082
|
+
getCurrentFrame,
|
|
2083
|
+
muted
|
|
2084
|
+
}) => {
|
|
2085
|
+
const config = Internals10.useUnsafeVideoConfig();
|
|
2086
|
+
const fps = config?.fps ?? null;
|
|
2087
|
+
const durationInFrames = config?.durationInFrames ?? null;
|
|
2088
|
+
const compositionId = config?.id ?? null;
|
|
2089
|
+
const frame = Internals10.Timeline.useTimelinePosition();
|
|
2090
|
+
const playing = Internals10.usePlaying();
|
|
2091
|
+
const { pause, emitter, isPlaying } = usePlayerMethods();
|
|
2092
|
+
const setFrameFromPlayback = Internals10.Timeline.useTimelineSetFrameWithoutSeek();
|
|
2093
|
+
const sharedAudioContext = useContext3(Internals10.SharedAudioContext);
|
|
2094
|
+
const { setPlayerMuted } = useContext3(Internals10.SetMediaVolumeContext);
|
|
2095
|
+
const { isBuffering, subscribeBuffering, seek } = useContext3(Internals10.SetTimelineContext);
|
|
2096
|
+
const logLevel = Internals10.useLogLevel();
|
|
2097
|
+
const isBackgroundedRef = useIsBackgrounded();
|
|
2098
|
+
const lastTimeUpdateTimestamp = useRef8(0);
|
|
2099
|
+
const playbackClockRef = useRef8(null);
|
|
2100
|
+
const previousMutedRef = useRef8(muted);
|
|
2101
|
+
const anchoredAudioContextRef = useRef8(null);
|
|
2102
|
+
useBrowserMediaSession({
|
|
2103
|
+
browserMediaControlsBehavior,
|
|
2104
|
+
playbackRate,
|
|
2105
|
+
videoConfig: config
|
|
2106
|
+
});
|
|
2107
|
+
useLayoutEffect2(() => {
|
|
2108
|
+
if (!sharedAudioContext) {
|
|
2109
|
+
return;
|
|
2110
|
+
}
|
|
2111
|
+
if (!sharedAudioContext.audioContext) {
|
|
2112
|
+
return;
|
|
2113
|
+
}
|
|
2114
|
+
if (fps === null) {
|
|
2115
|
+
return;
|
|
2116
|
+
}
|
|
2117
|
+
if (muted) {
|
|
2118
|
+
return;
|
|
2119
|
+
}
|
|
2120
|
+
const changed = setGlobalTimeAnchor({
|
|
2121
|
+
audioContext: sharedAudioContext.audioContext,
|
|
2122
|
+
audioSyncAnchor: sharedAudioContext.audioSyncAnchor,
|
|
2123
|
+
absoluteTimeInSeconds: frame / fps,
|
|
2124
|
+
globalPlaybackRate: playbackRate,
|
|
2125
|
+
logLevel,
|
|
2126
|
+
force: false
|
|
2127
|
+
});
|
|
2128
|
+
if (changed) {
|
|
2129
|
+
sharedAudioContext.audioSyncAnchorEmitter.dispatch("changed");
|
|
2130
|
+
}
|
|
2131
|
+
}, [fps, frame, logLevel, playbackRate, sharedAudioContext, muted]);
|
|
2132
|
+
useLayoutEffect2(() => {
|
|
2133
|
+
const audioContext = sharedAudioContext?.audioContext;
|
|
2134
|
+
if (!audioContext) {
|
|
2135
|
+
return;
|
|
2136
|
+
}
|
|
2137
|
+
if (fps === null) {
|
|
2138
|
+
return;
|
|
2139
|
+
}
|
|
2140
|
+
if (muted) {
|
|
2141
|
+
return;
|
|
2142
|
+
}
|
|
2143
|
+
const callback = () => {
|
|
2144
|
+
const newState = sharedAudioContext?.getAudioContextState();
|
|
2145
|
+
if (newState && shouldForceAnchorChange(newState)) {
|
|
2146
|
+
const changed = setGlobalTimeAnchor({
|
|
2147
|
+
audioContext,
|
|
2148
|
+
audioSyncAnchor: sharedAudioContext.audioSyncAnchor,
|
|
2149
|
+
absoluteTimeInSeconds: getCurrentFrame() / fps,
|
|
2150
|
+
globalPlaybackRate: playbackRate,
|
|
2151
|
+
logLevel,
|
|
2152
|
+
force: true
|
|
2153
|
+
});
|
|
2154
|
+
if (changed) {
|
|
2155
|
+
sharedAudioContext.audioSyncAnchorEmitter.dispatch("changed");
|
|
2156
|
+
}
|
|
2157
|
+
}
|
|
2158
|
+
};
|
|
2159
|
+
audioContext?.addEventListener("statechange", callback);
|
|
2160
|
+
return () => {
|
|
2161
|
+
audioContext?.removeEventListener("statechange", callback);
|
|
2162
|
+
};
|
|
2163
|
+
}, [fps, getCurrentFrame, logLevel, muted, playbackRate, sharedAudioContext]);
|
|
2091
2164
|
useEffect10(() => {
|
|
2092
|
-
|
|
2165
|
+
const wasMuted = previousMutedRef.current;
|
|
2166
|
+
previousMutedRef.current = muted;
|
|
2167
|
+
if (fps === null || durationInFrames === null || compositionId === null) {
|
|
2168
|
+
playbackClockRef.current = null;
|
|
2169
|
+
return;
|
|
2170
|
+
}
|
|
2171
|
+
if (!playing) {
|
|
2172
|
+
playbackClockRef.current = null;
|
|
2173
|
+
sharedAudioContext?.suspend?.();
|
|
2174
|
+
return;
|
|
2175
|
+
}
|
|
2176
|
+
if (muted) {
|
|
2177
|
+
sharedAudioContext?.suspend?.();
|
|
2178
|
+
}
|
|
2179
|
+
const previousClock = playbackClockRef.current;
|
|
2180
|
+
const shouldRestartClock = previousClock === null || previousClock.compositionId !== compositionId || previousClock.fps !== fps || previousClock.playbackRate !== playbackRate;
|
|
2181
|
+
const clock = shouldRestartClock ? {
|
|
2182
|
+
compositionId,
|
|
2183
|
+
startedTime: performance.now(),
|
|
2184
|
+
framesAdvanced: 0,
|
|
2185
|
+
fps,
|
|
2186
|
+
playbackRate
|
|
2187
|
+
} : previousClock;
|
|
2188
|
+
playbackClockRef.current = clock;
|
|
2189
|
+
if (sharedAudioContext?._experimentalKeepAudioContextAlive && sharedAudioContext.audioContext && !muted) {
|
|
2190
|
+
const didUnmute = wasMuted && !muted;
|
|
2191
|
+
const didReplaceAudioContext = anchoredAudioContextRef.current !== sharedAudioContext.audioContext;
|
|
2192
|
+
const shouldRescheduleAudio = shouldRestartClock || didUnmute || didReplaceAudioContext;
|
|
2193
|
+
const changed = setGlobalTimeAnchor({
|
|
2194
|
+
audioContext: sharedAudioContext.audioContext,
|
|
2195
|
+
audioSyncAnchor: sharedAudioContext.audioSyncAnchor,
|
|
2196
|
+
absoluteTimeInSeconds: getCurrentFrame() / fps,
|
|
2197
|
+
globalPlaybackRate: playbackRate,
|
|
2198
|
+
logLevel,
|
|
2199
|
+
force: shouldRescheduleAudio
|
|
2200
|
+
});
|
|
2201
|
+
anchoredAudioContextRef.current = sharedAudioContext.audioContext;
|
|
2202
|
+
if (changed || shouldRescheduleAudio) {
|
|
2203
|
+
sharedAudioContext.audioSyncAnchorEmitter.dispatch("changed");
|
|
2204
|
+
}
|
|
2205
|
+
}
|
|
2206
|
+
let hasBeenStopped = false;
|
|
2207
|
+
let audioContextFailed = false;
|
|
2208
|
+
let reqAnimFrameCall = null;
|
|
2209
|
+
let playbackFrame = getCurrentFrame();
|
|
2210
|
+
let lastSeekRevision = seek?.revision.current ?? null;
|
|
2211
|
+
let unsubscribeBuffering = null;
|
|
2212
|
+
const cancelQueuedFrame = () => {
|
|
2213
|
+
if (reqAnimFrameCall !== null) {
|
|
2214
|
+
if (reqAnimFrameCall.type === "raf") {
|
|
2215
|
+
cancelAnimationFrame(reqAnimFrameCall.id);
|
|
2216
|
+
} else {
|
|
2217
|
+
clearTimeout(reqAnimFrameCall.id);
|
|
2218
|
+
}
|
|
2219
|
+
reqAnimFrameCall = null;
|
|
2220
|
+
}
|
|
2221
|
+
};
|
|
2222
|
+
const stop = () => {
|
|
2223
|
+
hasBeenStopped = true;
|
|
2224
|
+
cancelQueuedFrame();
|
|
2225
|
+
unsubscribeBuffering?.();
|
|
2226
|
+
unsubscribeBuffering = null;
|
|
2227
|
+
};
|
|
2228
|
+
const callback = () => {
|
|
2229
|
+
reqAnimFrameCall = null;
|
|
2230
|
+
if (hasBeenStopped) {
|
|
2231
|
+
return;
|
|
2232
|
+
}
|
|
2233
|
+
if (!isPlaying()) {
|
|
2234
|
+
sharedAudioContext?.suspend?.();
|
|
2235
|
+
return;
|
|
2236
|
+
}
|
|
2237
|
+
if (isBuffering()) {
|
|
2238
|
+
queueNextFrame();
|
|
2239
|
+
return;
|
|
2240
|
+
}
|
|
2241
|
+
if (!muted && !audioContextFailed) {
|
|
2242
|
+
sharedAudioContext?.resume?.();
|
|
2243
|
+
}
|
|
2244
|
+
const time = performance.now() - clock.startedTime;
|
|
2245
|
+
const actualLastFrame = outFrame ?? durationInFrames - 1;
|
|
2246
|
+
const actualFirstFrame = inFrame ?? 0;
|
|
2247
|
+
const seekRevision = seek?.revision.current ?? null;
|
|
2248
|
+
if (seekRevision !== lastSeekRevision) {
|
|
2249
|
+
playbackFrame = getCurrentFrame();
|
|
2250
|
+
lastSeekRevision = seekRevision;
|
|
2251
|
+
}
|
|
2252
|
+
const currentFrame = playbackFrame;
|
|
2253
|
+
const { nextFrame, framesToAdvance, hasEnded } = calculateNextFrame({
|
|
2254
|
+
time,
|
|
2255
|
+
currentFrame,
|
|
2256
|
+
playbackSpeed: playbackRate,
|
|
2257
|
+
fps,
|
|
2258
|
+
actualFirstFrame,
|
|
2259
|
+
actualLastFrame,
|
|
2260
|
+
framesAdvanced: clock.framesAdvanced,
|
|
2261
|
+
shouldLoop: loop
|
|
2262
|
+
});
|
|
2263
|
+
clock.framesAdvanced += framesToAdvance;
|
|
2264
|
+
const frameToDisplay = hasEnded && !moveToBeginningWhenEnded ? playbackRate > 0 ? actualLastFrame : actualFirstFrame : nextFrame;
|
|
2265
|
+
if (frameToDisplay !== currentFrame) {
|
|
2266
|
+
playbackFrame = frameToDisplay;
|
|
2267
|
+
setFrameFromPlayback((c) => ({ ...c, [compositionId]: frameToDisplay }));
|
|
2268
|
+
}
|
|
2269
|
+
if (hasEnded) {
|
|
2270
|
+
stop();
|
|
2271
|
+
pause();
|
|
2272
|
+
emitter.dispatchEnded();
|
|
2273
|
+
return;
|
|
2274
|
+
}
|
|
2275
|
+
queueNextFrame();
|
|
2276
|
+
};
|
|
2277
|
+
const queueNextFrame = () => {
|
|
2278
|
+
if (hasBeenStopped) {
|
|
2279
|
+
return;
|
|
2280
|
+
}
|
|
2281
|
+
const getIsResumingAudioContext = audioContextFailed ? null : sharedAudioContext?.getIsResumingAudioContext?.() ?? null;
|
|
2282
|
+
if (getIsResumingAudioContext !== null && !muted) {
|
|
2283
|
+
getIsResumingAudioContext.then((result) => {
|
|
2284
|
+
if (hasBeenStopped) {
|
|
2285
|
+
return;
|
|
2286
|
+
}
|
|
2287
|
+
if (result === "failed") {
|
|
2288
|
+
audioContextFailed = true;
|
|
2289
|
+
sharedAudioContext?.suspend();
|
|
2290
|
+
setPlayerMuted(true);
|
|
2291
|
+
}
|
|
2292
|
+
clock.startedTime = performance.now();
|
|
2293
|
+
clock.framesAdvanced = 0;
|
|
2294
|
+
queueNextFrame();
|
|
2295
|
+
});
|
|
2296
|
+
return;
|
|
2297
|
+
}
|
|
2298
|
+
if (isBuffering()) {
|
|
2299
|
+
if (!muted && !audioContextFailed) {
|
|
2300
|
+
sharedAudioContext?.suspend?.();
|
|
2301
|
+
}
|
|
2302
|
+
unsubscribeBuffering = subscribeBuffering((state) => {
|
|
2303
|
+
if (state.buffering) {
|
|
2304
|
+
return;
|
|
2305
|
+
}
|
|
2306
|
+
unsubscribeBuffering?.();
|
|
2307
|
+
unsubscribeBuffering = null;
|
|
2308
|
+
if (hasBeenStopped) {
|
|
2309
|
+
return;
|
|
2310
|
+
}
|
|
2311
|
+
if (!muted && !audioContextFailed && sharedAudioContext?._experimentalKeepAudioContextAlive) {
|
|
2312
|
+
sharedAudioContext.resume();
|
|
2313
|
+
}
|
|
2314
|
+
clock.startedTime = performance.now();
|
|
2315
|
+
clock.framesAdvanced = 0;
|
|
2316
|
+
queueNextFrame();
|
|
2317
|
+
});
|
|
2318
|
+
return;
|
|
2319
|
+
}
|
|
2320
|
+
if (isBackgroundedRef.current) {
|
|
2321
|
+
reqAnimFrameCall = {
|
|
2322
|
+
type: "timeout",
|
|
2323
|
+
id: setTimeout(callback, 1000 / fps)
|
|
2324
|
+
};
|
|
2325
|
+
return;
|
|
2326
|
+
}
|
|
2327
|
+
reqAnimFrameCall = { type: "raf", id: requestAnimationFrame(callback) };
|
|
2328
|
+
};
|
|
2329
|
+
const unsubscribeSeek = seek?.subscribe(() => {
|
|
2330
|
+
clock.startedTime = performance.now();
|
|
2331
|
+
clock.framesAdvanced = 0;
|
|
2332
|
+
});
|
|
2333
|
+
queueNextFrame();
|
|
2334
|
+
const onVisibilityChange = () => {
|
|
2335
|
+
if (reqAnimFrameCall === null) {
|
|
2336
|
+
return;
|
|
2337
|
+
}
|
|
2338
|
+
cancelQueuedFrame();
|
|
2339
|
+
callback();
|
|
2340
|
+
};
|
|
2341
|
+
window.addEventListener("visibilitychange", onVisibilityChange);
|
|
2342
|
+
return () => {
|
|
2343
|
+
window.removeEventListener("visibilitychange", onVisibilityChange);
|
|
2344
|
+
unsubscribeSeek?.();
|
|
2345
|
+
stop();
|
|
2346
|
+
};
|
|
2347
|
+
}, [
|
|
2348
|
+
compositionId,
|
|
2349
|
+
durationInFrames,
|
|
2350
|
+
fps,
|
|
2351
|
+
loop,
|
|
2352
|
+
pause,
|
|
2353
|
+
playing,
|
|
2354
|
+
setFrameFromPlayback,
|
|
2355
|
+
emitter,
|
|
2356
|
+
playbackRate,
|
|
2357
|
+
inFrame,
|
|
2358
|
+
outFrame,
|
|
2359
|
+
moveToBeginningWhenEnded,
|
|
2360
|
+
isBackgroundedRef,
|
|
2361
|
+
getCurrentFrame,
|
|
2362
|
+
isBuffering,
|
|
2363
|
+
isPlaying,
|
|
2364
|
+
sharedAudioContext,
|
|
2365
|
+
setPlayerMuted,
|
|
2366
|
+
subscribeBuffering,
|
|
2367
|
+
seek,
|
|
2368
|
+
logLevel,
|
|
2369
|
+
muted
|
|
2370
|
+
]);
|
|
2371
|
+
useEffect10(() => {
|
|
2372
|
+
const now = performance.now();
|
|
2373
|
+
const timeSinceLastUpdate = now - lastTimeUpdateTimestamp.current;
|
|
2374
|
+
if (timeSinceLastUpdate >= 250) {
|
|
2375
|
+
emitter.dispatchTimeUpdate({ frame });
|
|
2376
|
+
lastTimeUpdateTimestamp.current = now;
|
|
2093
2377
|
return;
|
|
2094
2378
|
}
|
|
2095
|
-
const
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2100
|
-
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
return {
|
|
2105
|
-
height: KNOB_SIZE2,
|
|
2106
|
-
width: KNOB_SIZE2,
|
|
2107
|
-
borderRadius: KNOB_SIZE2 / 2,
|
|
2108
|
-
position: "absolute",
|
|
2109
|
-
top: VERTICAL_PADDING - KNOB_SIZE2 / 2 + 5 / 2,
|
|
2110
|
-
backgroundColor: "white",
|
|
2111
|
-
left: Math.max(0, frame / Math.max(1, durationInFrames - 1) * width - KNOB_SIZE2 / 2),
|
|
2112
|
-
boxShadow: "0 0 2px black",
|
|
2113
|
-
opacity: Number(barHovered || dragging.dragging)
|
|
2114
|
-
};
|
|
2115
|
-
}, [barHovered, dragging.dragging, durationInFrames, frame, width]);
|
|
2116
|
-
const fillStyle = useMemo6(() => {
|
|
2117
|
-
return {
|
|
2118
|
-
height: BAR_HEIGHT2,
|
|
2119
|
-
backgroundColor: "rgba(255, 255, 255, 1)",
|
|
2120
|
-
width: (frame - (inFrame ?? 0)) / (durationInFrames - 1) * width,
|
|
2121
|
-
marginLeft: (inFrame ?? 0) / (durationInFrames - 1) * width,
|
|
2122
|
-
borderRadius: BAR_HEIGHT2 / 2
|
|
2123
|
-
};
|
|
2124
|
-
}, [durationInFrames, frame, inFrame, width]);
|
|
2125
|
-
const active = useMemo6(() => {
|
|
2126
|
-
return {
|
|
2127
|
-
height: BAR_HEIGHT2,
|
|
2128
|
-
backgroundColor: "rgba(255, 255, 255, 0.25)",
|
|
2129
|
-
width: ((outFrame ?? durationInFrames - 1) - (inFrame ?? 0)) / (durationInFrames - 1) * 100 + "%",
|
|
2130
|
-
marginLeft: (inFrame ?? 0) / (durationInFrames - 1) * 100 + "%",
|
|
2131
|
-
borderRadius: BAR_HEIGHT2 / 2,
|
|
2132
|
-
position: "absolute"
|
|
2133
|
-
};
|
|
2134
|
-
}, [durationInFrames, inFrame, outFrame]);
|
|
2135
|
-
return /* @__PURE__ */ jsxs6("div", {
|
|
2136
|
-
ref: containerRef,
|
|
2137
|
-
onPointerDown,
|
|
2138
|
-
style: containerStyle,
|
|
2139
|
-
children: [
|
|
2140
|
-
/* @__PURE__ */ jsxs6("div", {
|
|
2141
|
-
style: barBackground,
|
|
2142
|
-
children: [
|
|
2143
|
-
/* @__PURE__ */ jsx10("div", {
|
|
2144
|
-
style: active
|
|
2145
|
-
}),
|
|
2146
|
-
/* @__PURE__ */ jsx10("div", {
|
|
2147
|
-
style: fillStyle
|
|
2148
|
-
})
|
|
2149
|
-
]
|
|
2150
|
-
}),
|
|
2151
|
-
/* @__PURE__ */ jsx10("div", {
|
|
2152
|
-
style: knobStyle
|
|
2153
|
-
})
|
|
2154
|
-
]
|
|
2155
|
-
});
|
|
2379
|
+
const timeoutId = setTimeout(() => {
|
|
2380
|
+
emitter.dispatchTimeUpdate({ frame });
|
|
2381
|
+
lastTimeUpdateTimestamp.current = performance.now();
|
|
2382
|
+
}, 250 - timeSinceLastUpdate);
|
|
2383
|
+
return () => clearTimeout(timeoutId);
|
|
2384
|
+
}, [emitter, frame]);
|
|
2385
|
+
useEffect10(() => {
|
|
2386
|
+
emitter.dispatchFrameUpdate({ frame });
|
|
2387
|
+
}, [emitter, frame]);
|
|
2156
2388
|
};
|
|
2157
2389
|
|
|
2158
|
-
// src/
|
|
2159
|
-
import {
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2390
|
+
// src/Player.tsx
|
|
2391
|
+
import React13, {
|
|
2392
|
+
forwardRef as forwardRef2,
|
|
2393
|
+
useCallback as useCallback12,
|
|
2394
|
+
useEffect as useEffect13,
|
|
2395
|
+
useImperativeHandle as useImperativeHandle2,
|
|
2396
|
+
useLayoutEffect as useLayoutEffect3,
|
|
2397
|
+
useMemo as useMemo14,
|
|
2398
|
+
useRef as useRef12,
|
|
2399
|
+
useState as useState12
|
|
2400
|
+
} from "react";
|
|
2401
|
+
import { Composition, Internals as Internals15 } from "remotion";
|
|
2402
|
+
import { NoReactInternals as NoReactInternals2 } from "remotion/no-react";
|
|
2168
2403
|
|
|
2169
|
-
// src/
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
const frame = Internals10.Timeline.useTimelinePosition();
|
|
2173
|
-
const timeLabel = useMemo7(() => {
|
|
2174
|
-
return {
|
|
2175
|
-
color: "white",
|
|
2176
|
-
fontFamily: "sans-serif",
|
|
2177
|
-
fontSize: 14,
|
|
2178
|
-
maxWidth: maxTimeLabelWidth === null ? undefined : maxTimeLabelWidth,
|
|
2179
|
-
overflow: "hidden",
|
|
2180
|
-
textOverflow: "ellipsis"
|
|
2181
|
-
};
|
|
2182
|
-
}, [maxTimeLabelWidth]);
|
|
2183
|
-
const isLastFrame = frame === durationInFrames - 1;
|
|
2184
|
-
const frameToDisplay = isLastFrame ? frame + 1 : frame;
|
|
2185
|
-
return /* @__PURE__ */ jsxs7("div", {
|
|
2186
|
-
style: timeLabel,
|
|
2187
|
-
children: [
|
|
2188
|
-
formatTime(frameToDisplay / fps),
|
|
2189
|
-
" / ",
|
|
2190
|
-
formatTime(durationInFrames / fps)
|
|
2191
|
-
]
|
|
2192
|
-
});
|
|
2404
|
+
// src/player-css-classname.ts
|
|
2405
|
+
var playerCssClassname = (override) => {
|
|
2406
|
+
return override ?? "__remotion-player";
|
|
2193
2407
|
};
|
|
2194
2408
|
|
|
2195
|
-
// src/
|
|
2196
|
-
import {
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
const maxTimeLabelWidth = playerWidth - elementsSize;
|
|
2209
|
-
const maxTimeLabelWidthWithoutNegativeValue = Math.max(maxTimeLabelWidth, 0);
|
|
2210
|
-
const availableTimeLabelWidthIfVolumeOpen = maxTimeLabelWidthWithoutNegativeValue - VOLUME_SLIDER_WIDTH;
|
|
2211
|
-
const computedLabelWidth = availableTimeLabelWidthIfVolumeOpen < VOLUME_SLIDER_WIDTH ? maxTimeLabelWidthWithoutNegativeValue : availableTimeLabelWidthIfVolumeOpen;
|
|
2212
|
-
const minWidthForHorizontalDisplay = computedLabelWidth + elementsSize + VOLUME_SLIDER_WIDTH;
|
|
2213
|
-
const displayVerticalVolumeSlider = playerWidth < minWidthForHorizontalDisplay;
|
|
2214
|
-
return {
|
|
2215
|
-
maxTimeLabelWidth: maxTimeLabelWidthWithoutNegativeValue === 0 ? null : maxTimeLabelWidthWithoutNegativeValue,
|
|
2216
|
-
displayVerticalVolumeSlider
|
|
2217
|
-
};
|
|
2218
|
-
}, [allowFullScreen, playerWidth]);
|
|
2219
|
-
return resizeInfo;
|
|
2220
|
-
};
|
|
2409
|
+
// src/PlayerUI.tsx
|
|
2410
|
+
import React11, {
|
|
2411
|
+
Suspense,
|
|
2412
|
+
forwardRef,
|
|
2413
|
+
useCallback as useCallback10,
|
|
2414
|
+
useContext as useContext4,
|
|
2415
|
+
useEffect as useEffect12,
|
|
2416
|
+
useImperativeHandle,
|
|
2417
|
+
useMemo as useMemo12,
|
|
2418
|
+
useRef as useRef10,
|
|
2419
|
+
useState as useState10
|
|
2420
|
+
} from "react";
|
|
2421
|
+
import { Internals as Internals11 } from "remotion";
|
|
2221
2422
|
|
|
2222
|
-
// src/
|
|
2223
|
-
import
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
0.013,
|
|
2227
|
-
0.049,
|
|
2228
|
-
0.104,
|
|
2229
|
-
0.175,
|
|
2230
|
-
0.259,
|
|
2231
|
-
0.352,
|
|
2232
|
-
0.45,
|
|
2233
|
-
0.55,
|
|
2234
|
-
0.648,
|
|
2235
|
-
0.741,
|
|
2236
|
-
0.825,
|
|
2237
|
-
0.896,
|
|
2238
|
-
0.951,
|
|
2239
|
-
0.987
|
|
2240
|
-
];
|
|
2241
|
-
var gradientOpacities = [
|
|
2242
|
-
0,
|
|
2243
|
-
8.1,
|
|
2244
|
-
15.5,
|
|
2245
|
-
22.5,
|
|
2246
|
-
29,
|
|
2247
|
-
35.3,
|
|
2248
|
-
41.2,
|
|
2249
|
-
47.1,
|
|
2250
|
-
52.9,
|
|
2251
|
-
58.8,
|
|
2252
|
-
64.7,
|
|
2253
|
-
71,
|
|
2254
|
-
77.5,
|
|
2255
|
-
84.5,
|
|
2256
|
-
91.9
|
|
2257
|
-
];
|
|
2258
|
-
var globalGradientOpacity = 1 / 0.7;
|
|
2259
|
-
var containerStyle2 = {
|
|
2260
|
-
boxSizing: "border-box",
|
|
2261
|
-
position: "absolute",
|
|
2262
|
-
bottom: 0,
|
|
2263
|
-
width: "100%",
|
|
2264
|
-
paddingTop: 40,
|
|
2265
|
-
paddingBottom: 10,
|
|
2266
|
-
backgroundImage: `linear-gradient(to bottom,${gradientSteps.map((g, i) => {
|
|
2267
|
-
return `hsla(0, 0%, 0%, ${g}) ${gradientOpacities[i] * globalGradientOpacity}%`;
|
|
2268
|
-
}).join(", ")}, hsl(0, 0%, 0%) 100%)`,
|
|
2269
|
-
backgroundSize: "auto 145px",
|
|
2270
|
-
display: "flex",
|
|
2271
|
-
paddingRight: X_PADDING,
|
|
2272
|
-
paddingLeft: X_PADDING,
|
|
2273
|
-
flexDirection: "column",
|
|
2274
|
-
transition: "opacity 0.3s"
|
|
2275
|
-
};
|
|
2276
|
-
var controlsRow = {
|
|
2423
|
+
// src/error-boundary.tsx
|
|
2424
|
+
import React9 from "react";
|
|
2425
|
+
import { jsx as jsx10 } from "react/jsx-runtime";
|
|
2426
|
+
var errorStyle = {
|
|
2277
2427
|
display: "flex",
|
|
2278
|
-
flexDirection: "row",
|
|
2279
|
-
width: "100%",
|
|
2280
|
-
alignItems: "center",
|
|
2281
2428
|
justifyContent: "center",
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
display: "flex",
|
|
2287
|
-
flexDirection: "row",
|
|
2288
|
-
userSelect: "none",
|
|
2289
|
-
WebkitUserSelect: "none",
|
|
2290
|
-
alignItems: "center"
|
|
2291
|
-
};
|
|
2292
|
-
var xSpacer = {
|
|
2293
|
-
width: 12
|
|
2429
|
+
alignItems: "center",
|
|
2430
|
+
flex: 1,
|
|
2431
|
+
height: "100%",
|
|
2432
|
+
width: "100%"
|
|
2294
2433
|
};
|
|
2295
|
-
|
|
2296
|
-
|
|
2434
|
+
|
|
2435
|
+
class ErrorBoundary extends React9.Component {
|
|
2436
|
+
state = { hasError: null };
|
|
2437
|
+
static getDerivedStateFromError(error) {
|
|
2438
|
+
return { hasError: error };
|
|
2439
|
+
}
|
|
2440
|
+
componentDidCatch(error) {
|
|
2441
|
+
this.props.onError(error);
|
|
2442
|
+
}
|
|
2443
|
+
render() {
|
|
2444
|
+
if (this.state.hasError) {
|
|
2445
|
+
return /* @__PURE__ */ jsx10("div", {
|
|
2446
|
+
style: errorStyle,
|
|
2447
|
+
children: this.props.errorFallback({
|
|
2448
|
+
error: this.state.hasError
|
|
2449
|
+
})
|
|
2450
|
+
});
|
|
2451
|
+
}
|
|
2452
|
+
return this.props.children;
|
|
2453
|
+
}
|
|
2454
|
+
}
|
|
2455
|
+
|
|
2456
|
+
// src/license-blacklist.tsx
|
|
2457
|
+
import React10, { useEffect as useEffect11 } from "react";
|
|
2458
|
+
import { jsx as jsx11 } from "react/jsx-runtime";
|
|
2459
|
+
var getHashOfDomain = async () => {
|
|
2460
|
+
if (typeof window === "undefined") {
|
|
2461
|
+
return null;
|
|
2462
|
+
}
|
|
2463
|
+
if (typeof window.crypto === "undefined") {
|
|
2464
|
+
return null;
|
|
2465
|
+
}
|
|
2466
|
+
if (typeof window.crypto.subtle === "undefined") {
|
|
2467
|
+
return null;
|
|
2468
|
+
}
|
|
2469
|
+
try {
|
|
2470
|
+
const hashBuffer = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(window.location.hostname));
|
|
2471
|
+
return Array.from(new Uint8Array(hashBuffer)).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
2472
|
+
} catch {
|
|
2473
|
+
return null;
|
|
2474
|
+
}
|
|
2297
2475
|
};
|
|
2298
|
-
var
|
|
2299
|
-
|
|
2476
|
+
var style = {
|
|
2477
|
+
backgroundColor: "red",
|
|
2478
|
+
position: "absolute",
|
|
2479
|
+
padding: 12,
|
|
2480
|
+
fontFamily: "Arial"
|
|
2300
2481
|
};
|
|
2301
|
-
var
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
|
|
2308
|
-
|
|
2309
|
-
|
|
2310
|
-
|
|
2311
|
-
|
|
2312
|
-
onSeekStart,
|
|
2313
|
-
inFrame,
|
|
2314
|
-
outFrame,
|
|
2315
|
-
initiallyShowControls,
|
|
2316
|
-
canvasSize,
|
|
2317
|
-
renderPlayPauseButton,
|
|
2318
|
-
renderFullscreenButton,
|
|
2319
|
-
alwaysShowControls,
|
|
2320
|
-
showPlaybackRateControl,
|
|
2321
|
-
containerRef,
|
|
2322
|
-
buffering,
|
|
2323
|
-
hideControlsWhenPointerDoesntMove,
|
|
2324
|
-
onPointerDown,
|
|
2325
|
-
onDoubleClick,
|
|
2326
|
-
renderMuteButton,
|
|
2327
|
-
renderVolumeSlider,
|
|
2328
|
-
playing,
|
|
2329
|
-
toggle,
|
|
2330
|
-
renderCustomControls
|
|
2331
|
-
}) => {
|
|
2332
|
-
const playButtonRef = useRef8(null);
|
|
2333
|
-
const [supportsFullscreen, setSupportsFullscreen] = useState9(false);
|
|
2334
|
-
const hovered = useHoverState(containerRef, hideControlsWhenPointerDoesntMove);
|
|
2335
|
-
const { maxTimeLabelWidth, displayVerticalVolumeSlider } = useVideoControlsResize({
|
|
2336
|
-
allowFullscreen,
|
|
2337
|
-
playerWidth: canvasSize?.width ?? 0
|
|
2338
|
-
});
|
|
2339
|
-
const [shouldShowInitially, setInitiallyShowControls] = useState9(() => {
|
|
2340
|
-
if (typeof initiallyShowControls === "boolean") {
|
|
2341
|
-
return initiallyShowControls;
|
|
2342
|
-
}
|
|
2343
|
-
if (typeof initiallyShowControls === "number") {
|
|
2344
|
-
if (initiallyShowControls % 1 !== 0) {
|
|
2345
|
-
throw new Error("initiallyShowControls must be an integer or a boolean");
|
|
2346
|
-
}
|
|
2347
|
-
if (Number.isNaN(initiallyShowControls)) {
|
|
2348
|
-
throw new Error("initiallyShowControls must not be NaN");
|
|
2349
|
-
}
|
|
2350
|
-
if (!Number.isFinite(initiallyShowControls)) {
|
|
2351
|
-
throw new Error("initiallyShowControls must be finite");
|
|
2352
|
-
}
|
|
2353
|
-
if (initiallyShowControls <= 0) {
|
|
2354
|
-
throw new Error("initiallyShowControls must be a positive integer");
|
|
2355
|
-
}
|
|
2356
|
-
return initiallyShowControls;
|
|
2357
|
-
}
|
|
2358
|
-
throw new TypeError("initiallyShowControls must be a number or a boolean");
|
|
2359
|
-
});
|
|
2360
|
-
const containerCss = useMemo9(() => {
|
|
2361
|
-
const shouldShow = hovered || !playing || shouldShowInitially || alwaysShowControls;
|
|
2362
|
-
return {
|
|
2363
|
-
...containerStyle2,
|
|
2364
|
-
opacity: Number(shouldShow)
|
|
2365
|
-
};
|
|
2366
|
-
}, [hovered, shouldShowInitially, playing, alwaysShowControls]);
|
|
2482
|
+
var DOMAIN_BLACKLIST = [
|
|
2483
|
+
"28d262b44cc61fa750f1686b16ad0604dabfe193fbc263eec05c89b7ad4c2cd6",
|
|
2484
|
+
"4db1b0a94be33165dfefcb3ba03d04c7a2666dd27c496d3dc9fa41858e94925e",
|
|
2485
|
+
"fbc48530bbf245da790f63675e84e06bab38c3b114fab07eb350025119922bdc",
|
|
2486
|
+
"7baf10a8932757b1b3a22b3fce10a048747ac2f8eaf638603487e3705b07eb83",
|
|
2487
|
+
"8a6c21a598d8c667272b5207c051b85997bf5b45d5fb712378be3f27cd72c6a6",
|
|
2488
|
+
"a2f7aaac9c50a9255e7fc376110c4e0bfe153722dc66ed3c5d3bf2a135f65518"
|
|
2489
|
+
];
|
|
2490
|
+
var ran = false;
|
|
2491
|
+
var RenderWarningIfBlacklist = () => {
|
|
2492
|
+
const [unlicensed, setUnlicensed] = React10.useState(false);
|
|
2367
2493
|
useEffect11(() => {
|
|
2368
|
-
if (
|
|
2369
|
-
|
|
2370
|
-
preventScroll: true
|
|
2371
|
-
});
|
|
2494
|
+
if (ran) {
|
|
2495
|
+
return;
|
|
2372
2496
|
}
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2497
|
+
ran = true;
|
|
2498
|
+
getHashOfDomain().then((hash) => {
|
|
2499
|
+
if (hash && DOMAIN_BLACKLIST.includes(hash)) {
|
|
2500
|
+
setUnlicensed(true);
|
|
2501
|
+
}
|
|
2502
|
+
}).catch(() => {});
|
|
2376
2503
|
}, []);
|
|
2377
2504
|
useEffect11(() => {
|
|
2378
|
-
if (
|
|
2505
|
+
if (!unlicensed) {
|
|
2379
2506
|
return;
|
|
2380
2507
|
}
|
|
2381
|
-
const
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2508
|
+
const ensureBanner = () => {
|
|
2509
|
+
const banner = document.querySelector(".warning-banner");
|
|
2510
|
+
if (!banner) {
|
|
2511
|
+
const div = document.createElement("div");
|
|
2512
|
+
div.className = "warning-banner";
|
|
2513
|
+
Object.assign(div.style, style, {
|
|
2514
|
+
zIndex: "9999",
|
|
2515
|
+
cssText: `${style.cssText} !important;`
|
|
2516
|
+
});
|
|
2517
|
+
div.innerHTML = `
|
|
2518
|
+
<a href="https://github.com/remotion-dev/remotion/pull/4589" style="color: white;">
|
|
2519
|
+
Remotion Unlicensed – Contact hi@remotion.dev
|
|
2520
|
+
</a>
|
|
2521
|
+
`;
|
|
2522
|
+
document.body.appendChild(div);
|
|
2523
|
+
}
|
|
2524
|
+
};
|
|
2525
|
+
const observer = new MutationObserver(() => ensureBanner());
|
|
2526
|
+
observer.observe(document.body, { childList: true, subtree: true });
|
|
2385
2527
|
return () => {
|
|
2386
|
-
|
|
2528
|
+
observer.disconnect();
|
|
2387
2529
|
};
|
|
2388
|
-
}, [
|
|
2389
|
-
|
|
2390
|
-
if (showPlaybackRateControl === true) {
|
|
2391
|
-
return [0.5, 0.8, 1, 1.2, 1.5, 1.8, 2, 2.5, 3];
|
|
2392
|
-
}
|
|
2393
|
-
if (Array.isArray(showPlaybackRateControl)) {
|
|
2394
|
-
for (const rate of showPlaybackRateControl) {
|
|
2395
|
-
if (typeof rate !== "number") {
|
|
2396
|
-
throw new Error("Every item in showPlaybackRateControl must be a number");
|
|
2397
|
-
}
|
|
2398
|
-
if (rate <= 0) {
|
|
2399
|
-
throw new Error("Every item in showPlaybackRateControl must be positive");
|
|
2400
|
-
}
|
|
2401
|
-
}
|
|
2402
|
-
return showPlaybackRateControl;
|
|
2403
|
-
}
|
|
2530
|
+
}, [unlicensed]);
|
|
2531
|
+
if (!unlicensed) {
|
|
2404
2532
|
return null;
|
|
2405
|
-
}
|
|
2406
|
-
|
|
2407
|
-
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
const onDoubleClickIfContainer = useCallback7((e) => {
|
|
2415
|
-
if (e.target === ref.current || e.target === flexRef.current) {
|
|
2416
|
-
onDoubleClick?.(e);
|
|
2417
|
-
}
|
|
2418
|
-
}, [onDoubleClick]);
|
|
2419
|
-
return /* @__PURE__ */ jsxs8("div", {
|
|
2420
|
-
ref,
|
|
2421
|
-
style: containerCss,
|
|
2422
|
-
onPointerDown: onPointerDownIfContainer,
|
|
2423
|
-
onDoubleClick: onDoubleClickIfContainer,
|
|
2424
|
-
children: [
|
|
2425
|
-
/* @__PURE__ */ jsxs8("div", {
|
|
2426
|
-
ref: flexRef,
|
|
2427
|
-
style: controlsRow,
|
|
2428
|
-
children: [
|
|
2429
|
-
/* @__PURE__ */ jsxs8("div", {
|
|
2430
|
-
style: leftPartStyle,
|
|
2431
|
-
children: [
|
|
2432
|
-
/* @__PURE__ */ jsx11("button", {
|
|
2433
|
-
ref: playButtonRef,
|
|
2434
|
-
type: "button",
|
|
2435
|
-
style: playerButtonStyle,
|
|
2436
|
-
onClick: toggle,
|
|
2437
|
-
"aria-label": playing ? "Pause video" : "Play video",
|
|
2438
|
-
title: playing ? "Pause video" : "Play video",
|
|
2439
|
-
children: renderPlayPauseButton === null ? /* @__PURE__ */ jsx11(DefaultPlayPauseButton, {
|
|
2440
|
-
buffering,
|
|
2441
|
-
playing
|
|
2442
|
-
}) : renderPlayPauseButton({
|
|
2443
|
-
playing,
|
|
2444
|
-
isBuffering: buffering
|
|
2445
|
-
}) ?? /* @__PURE__ */ jsx11(DefaultPlayPauseButton, {
|
|
2446
|
-
buffering,
|
|
2447
|
-
playing
|
|
2448
|
-
})
|
|
2449
|
-
}),
|
|
2450
|
-
showVolumeControls ? /* @__PURE__ */ jsxs8(Fragment2, {
|
|
2451
|
-
children: [
|
|
2452
|
-
/* @__PURE__ */ jsx11("div", {
|
|
2453
|
-
style: xSpacer
|
|
2454
|
-
}),
|
|
2455
|
-
/* @__PURE__ */ jsx11(MediaVolumeSlider, {
|
|
2456
|
-
renderMuteButton,
|
|
2457
|
-
renderVolumeSlider,
|
|
2458
|
-
displayVerticalVolumeSlider
|
|
2459
|
-
})
|
|
2460
|
-
]
|
|
2461
|
-
}) : null,
|
|
2462
|
-
/* @__PURE__ */ jsx11("div", {
|
|
2463
|
-
style: xSpacer
|
|
2464
|
-
}),
|
|
2465
|
-
/* @__PURE__ */ jsx11(PlayerTimeLabel, {
|
|
2466
|
-
durationInFrames,
|
|
2467
|
-
fps,
|
|
2468
|
-
maxTimeLabelWidth
|
|
2469
|
-
}),
|
|
2470
|
-
/* @__PURE__ */ jsx11("div", {
|
|
2471
|
-
style: xSpacer
|
|
2472
|
-
})
|
|
2473
|
-
]
|
|
2474
|
-
}),
|
|
2475
|
-
/* @__PURE__ */ jsx11("div", {
|
|
2476
|
-
style: flex1
|
|
2477
|
-
}),
|
|
2478
|
-
customControlsElement,
|
|
2479
|
-
customControlsElement && playbackRates && canvasSize ? /* @__PURE__ */ jsx11("div", {
|
|
2480
|
-
style: xSpacer
|
|
2481
|
-
}) : null,
|
|
2482
|
-
playbackRates && canvasSize && /* @__PURE__ */ jsx11(PlaybackrateControl, {
|
|
2483
|
-
canvasSize,
|
|
2484
|
-
playbackRates
|
|
2485
|
-
}),
|
|
2486
|
-
playbackRates && supportsFullscreen && allowFullscreen ? /* @__PURE__ */ jsx11("div", {
|
|
2487
|
-
style: xSpacer
|
|
2488
|
-
}) : null,
|
|
2489
|
-
/* @__PURE__ */ jsx11("div", {
|
|
2490
|
-
style: fullscreen,
|
|
2491
|
-
children: supportsFullscreen && allowFullscreen ? /* @__PURE__ */ jsx11("button", {
|
|
2492
|
-
type: "button",
|
|
2493
|
-
"aria-label": isFullscreen ? "Exit fullscreen" : "Enter Fullscreen",
|
|
2494
|
-
title: isFullscreen ? "Exit fullscreen" : "Enter Fullscreen",
|
|
2495
|
-
style: playerButtonStyle,
|
|
2496
|
-
onClick: isFullscreen ? onExitFullscreenButtonClick : onFullscreenButtonClick,
|
|
2497
|
-
children: renderFullscreenButton === null ? /* @__PURE__ */ jsx11(FullscreenIcon, {
|
|
2498
|
-
isFullscreen
|
|
2499
|
-
}) : renderFullscreenButton({ isFullscreen })
|
|
2500
|
-
}) : null
|
|
2501
|
-
})
|
|
2502
|
-
]
|
|
2503
|
-
}),
|
|
2504
|
-
/* @__PURE__ */ jsx11("div", {
|
|
2505
|
-
style: ySpacer
|
|
2506
|
-
}),
|
|
2507
|
-
/* @__PURE__ */ jsx11(PlayerSeekBar, {
|
|
2508
|
-
onSeekEnd,
|
|
2509
|
-
onSeekStart,
|
|
2510
|
-
durationInFrames,
|
|
2511
|
-
inFrame,
|
|
2512
|
-
outFrame
|
|
2513
|
-
})
|
|
2514
|
-
]
|
|
2533
|
+
}
|
|
2534
|
+
return /* @__PURE__ */ jsx11("div", {
|
|
2535
|
+
style,
|
|
2536
|
+
className: "warning-banner",
|
|
2537
|
+
children: /* @__PURE__ */ jsx11("a", {
|
|
2538
|
+
style: { color: "white" },
|
|
2539
|
+
href: "https://github.com/remotion-dev/remotion/pull/4589",
|
|
2540
|
+
children: "Remotion Unlicensed – Contact hi@remotion.dev"
|
|
2541
|
+
})
|
|
2515
2542
|
});
|
|
2516
2543
|
};
|
|
2517
2544
|
|
|
@@ -4048,6 +4075,7 @@ var PlayerInternals = {
|
|
|
4048
4075
|
updateAllElementsSizes,
|
|
4049
4076
|
PlayerEmitterProvider,
|
|
4050
4077
|
BufferingIndicator,
|
|
4078
|
+
PlayerControls: Controls,
|
|
4051
4079
|
TimelineSequenceObserverContext,
|
|
4052
4080
|
CanvasOverlayContext,
|
|
4053
4081
|
CanvasContentContext
|