From d2c3cdcf04619f3745869ab2f191256eb7a4c7f1 Mon Sep 17 00:00:00 2001 From: Blake Blackshear Date: Mon, 16 May 2022 06:49:47 -0500 Subject: [PATCH] don't add 16x on every render --- web/src/components/VideoPlayer.jsx | 31 +++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/web/src/components/VideoPlayer.jsx b/web/src/components/VideoPlayer.jsx index df75ad5e4..2ef534464 100644 --- a/web/src/components/VideoPlayer.jsx +++ b/web/src/components/VideoPlayer.jsx @@ -6,24 +6,25 @@ import 'videojs-seek-buttons'; import 'video.js/dist/video-js.css'; import 'videojs-seek-buttons/dist/videojs-seek-buttons.css'; -const defaultOptions = { - controls: true, - playbackRates: [0.5, 1, 2, 4, 8], - fluid: true, -}; -const defaultSeekOptions = { - forward: 30, - back: 10, -}; - export default function VideoPlayer({ children, options, seekOptions = {}, onReady = () => {}, onDispose = () => {} }) { const playerRef = useRef(); - - if (!videojs.browser.IS_FIREFOX) { - defaultOptions.playbackRates.push(16); - } - + useEffect(() => { + const defaultOptions = { + controls: true, + playbackRates: [0.5, 1, 2, 4, 8], + fluid: true, + }; + + const defaultSeekOptions = { + forward: 30, + back: 10, + }; + + if (!videojs.browser.IS_FIREFOX) { + defaultOptions.playbackRates.push(16); + } + const player = videojs(playerRef.current, { ...defaultOptions, ...options }, () => { onReady(player); });