diff --git a/next_app/src/components/VideoPlayer/VideoPlayer.tsx b/next_app/src/components/VideoPlayer/VideoPlayer.tsx index b0861a3..ca6a754 100644 --- a/next_app/src/components/VideoPlayer/VideoPlayer.tsx +++ b/next_app/src/components/VideoPlayer/VideoPlayer.tsx @@ -1,31 +1,18 @@ 'use client' import 'client-only' -import { useEffect, useMemo, useRef, useState } from 'react' -import { browserName, detectOS, Browser } from 'detect-browser' -import Hls from 'hls.js' +import { DetailedHTMLProps, RefObject, VideoHTMLAttributes, useRef } from 'react' +import { browserName } from 'detect-browser' import css from './VideoPlayer.module.scss' import VideoControl from './VideoControl' -type Props = { - src: string +type Props = DetailedHTMLProps, HTMLVideoElement> & { + videoRef: RefObject } const VideoPlayer = (props: Props) => { const videoContainerRef = useRef(null) - const videoRef = useRef(null) - useEffect(() => { - var hls = new Hls({ enableWorker: false }) - hls.attachMedia(videoRef.current!) - hls.on(Hls.Events.MEDIA_ATTACHED, () => { - hls.loadSource(props.src) - }) - - return () => { - hls.removeAllListeners() - hls.stopLoad() - } - }, []) + const { ['videoRef']: {} = {}, ...p2 } = props return (
@@ -34,12 +21,12 @@ const VideoPlayer = (props: Props) => { if (typeof window !== 'undefined' && browserName(window.navigator.userAgent) !== 'ios') { return ( <> - - + + ) } else { - return + return } })()}
diff --git a/next_app/src/components/VideoPlayer/VideoPlayerHls.tsx b/next_app/src/components/VideoPlayer/VideoPlayerHls.tsx new file mode 100644 index 0000000..a0ad1a3 --- /dev/null +++ b/next_app/src/components/VideoPlayer/VideoPlayerHls.tsx @@ -0,0 +1,50 @@ +'use client' +import 'client-only' +import { useEffect, useRef } from 'react' +import { browserName } from 'detect-browser' +import Hls from 'hls.js' +import css from './VideoPlayer.module.scss' +import VideoControl from './VideoControl' + +type Props = { + src: string +} + +const VideoPlayer = (props: Props) => { + const videoContainerRef = useRef(null) + const videoRef = useRef(null) + + useEffect(() => { + var hls = new Hls({ enableWorker: false }) + hls.attachMedia(videoRef.current!) + hls.on(Hls.Events.MEDIA_ATTACHED, () => { + hls.loadSource(props.src) + }) + + return () => { + hls.removeAllListeners() + hls.stopLoad() + } + }, []) + + return ( +
+
+ {(() => { + if (typeof window !== 'undefined' && browserName(window.navigator.userAgent) !== 'ios') { + return ( + <> + + + + ) + } else { + return + } + })()} +
+
+ ) +} + +export default VideoPlayer diff --git a/next_app/src/features/room_video/components/pages/content.tsx b/next_app/src/features/room_video/components/pages/content.tsx index 2f1b905..198deae 100644 --- a/next_app/src/features/room_video/components/pages/content.tsx +++ b/next_app/src/features/room_video/components/pages/content.tsx @@ -8,7 +8,7 @@ import css from './content.module.scss' import reactStringReplace from 'react-string-replace' import SimpleButton from 'components/SimpleButton' -const VideoPlayer = dynamic(() => import('components/VideoPlayer/VideoPlayer'), { ssr: false, suspense: true }) +const VideoPlayerHls = dynamic(() => import('components/VideoPlayer/VideoPlayerHls'), { ssr: false, suspense: true }) type ContentData = { id?: string @@ -49,7 +49,7 @@ const ContentPage = async ({ roomName, roomId, contentId }: { roomName: string;
- diff --git a/next_app/src/features/rooms/components/editForm/EditVideo.tsx b/next_app/src/features/rooms/components/editForm/EditVideo.tsx index f87cb9b..a3eacec 100644 --- a/next_app/src/features/rooms/components/editForm/EditVideo.tsx +++ b/next_app/src/features/rooms/components/editForm/EditVideo.tsx @@ -1,7 +1,10 @@ 'use client' +import dynamic from 'next/dynamic' import css from './EditContentForm.module.scss' import React, { useCallback, useMemo, useRef, useState } from 'react' +const VideoPlayer = dynamic(() => import('components/VideoPlayer/VideoPlayer'), { ssr: false, suspense: true }) + const EditVideo = ({ videoRef, videoSrc, @@ -58,10 +61,10 @@ const EditVideo = ({
- + />
)