-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[front] Use original video controller in edit content
close #30
- Loading branch information
1 parent
76a6420
commit 9151549
Showing
4 changed files
with
66 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<HTMLDivElement>(null) | ||
const videoRef = useRef<HTMLVideoElement>(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 ( | ||
<div className={css.video_container} ref={videoContainerRef}> | ||
<div className={css.video_wrapper}> | ||
{(() => { | ||
if (typeof window !== 'undefined' && browserName(window.navigator.userAgent) !== 'ios') { | ||
return ( | ||
<> | ||
<video className={css.video} ref={videoRef}></video> | ||
<VideoControl videoRef={videoRef} videoContainerRef={videoContainerRef}></VideoControl> | ||
</> | ||
) | ||
} else { | ||
return <video className={css.video} src={props.src} poster={props.src.replace('m3u8', 'webp')} controls playsInline></video> | ||
} | ||
})()} | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
export default VideoPlayer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters