From ce18001005bcc39f0b43f6fe7dad4730b541f008 Mon Sep 17 00:00:00 2001 From: toshi-pono <66683209+toshi-pono@users.noreply.github.com> Date: Wed, 29 Dec 2021 16:59:21 +0900 Subject: [PATCH] use webm --- .../PausableMovie/PausableMovie.jsx | 53 +++++++------------ client/src/utils/get_path.js | 2 +- server/src/routes/api/movie.js | 4 +- 3 files changed, 21 insertions(+), 38 deletions(-) diff --git a/client/src/components/foundation/PausableMovie/PausableMovie.jsx b/client/src/components/foundation/PausableMovie/PausableMovie.jsx index 7bdea81e4..209f029a0 100644 --- a/client/src/components/foundation/PausableMovie/PausableMovie.jsx +++ b/client/src/components/foundation/PausableMovie/PausableMovie.jsx @@ -2,6 +2,7 @@ import classNames from 'classnames'; import { Animator, Decoder } from 'gifler'; import { GifReader } from 'omggif'; import React from 'react'; +import { useEffect } from 'react'; import { useFetch } from '../../../hooks/use_fetch'; import { fetchBinary } from '../../../utils/fetchers'; @@ -20,46 +21,26 @@ import { FontAwesomeIcon } from '../FontAwesomeIcon'; const PausableMovie = ({ src }) => { const { data, isLoading } = useFetch(src, fetchBinary); - /** @type {React.RefObject} */ - const animatorRef = React.useRef(null); - /** @type {React.RefCallback} */ - const canvasCallbackRef = React.useCallback( - (el) => { - animatorRef.current?.stop(); - - if (el === null || data === null) { - return; - } - - // GIF を解析する - const reader = new GifReader(new Uint8Array(data)); - const frames = Decoder.decodeFramesSync(reader); - const animator = new Animator(reader, frames); - - animator.animateInCanvas(el); - animator.onFrame(frames[0]); - - // 視覚効果 off のとき GIF を自動再生しない - if (window.matchMedia('(prefers-reduced-motion: reduce)').matches) { - setIsPlaying(false); - animator.stop(); - } else { - setIsPlaying(true); - animator.start(); - } - - animatorRef.current = animator; - }, - [data], - ); + /** @type {React.RefCallback} */ + const videoRef = React.useRef(null); + useEffect(() => { + // 視覚効果 off のとき GIF を自動再生しない + if (window.matchMedia('(prefers-reduced-motion: reduce)').matches) { + setIsPlaying(false); + videoRef.current?.pause(); + } else { + setIsPlaying(true); + videoRef.current?.play(); + } + }, []) const [isPlaying, setIsPlaying] = React.useState(true); const handleClick = React.useCallback(() => { setIsPlaying((isPlaying) => { if (isPlaying) { - animatorRef.current?.stop(); + videoRef.current?.pause(); } else { - animatorRef.current?.start(); + videoRef.current?.play(); } return !isPlaying; }); @@ -72,7 +53,9 @@ const PausableMovie = ({ src }) => { return (