1
0
Fork 0
mirror of https://github.com/sussy-code/smov.git synced 2024-12-29 16:07:40 +01:00
This commit is contained in:
James Hawkins 2021-08-07 21:19:01 +01:00
parent 0ce6efae2e
commit 40ee5bb012
2 changed files with 21 additions and 23 deletions

View file

@ -6,9 +6,17 @@ import './VideoElement.css'
// streamUrl: string // streamUrl: string
// loading: boolean // loading: boolean
export function VideoElement({ streamUrl, loading, setProgress, videoRef }) { // setProgress: (event: NativeEvent) => void
// videoRef: useRef
// startTime: number
export function VideoElement({ streamUrl, loading, setProgress, videoRef, startTime }) {
const [error, setError] = React.useState(false); const [error, setError] = React.useState(false);
function onLoad() {
if (startTime)
videoRef.current.currentTime = startTime;
}
React.useEffect(() => { React.useEffect(() => {
if (!streamUrl.endsWith('.mp4')) { if (!streamUrl.endsWith('.mp4')) {
setError(false) setError(false)
@ -40,11 +48,11 @@ export function VideoElement({ streamUrl, loading, setProgress, videoRef }) {
if (!streamUrl.endsWith('.mp4')) { if (!streamUrl.endsWith('.mp4')) {
return ( return (
<video className="videoElement" ref={videoRef} controls autoPlay onProgress={setProgress} /> <video className="videoElement" ref={videoRef} controls autoPlay onProgress={setProgress} onLoadedData={onLoad} />
) )
} else { } else {
return ( return (
<video className="videoElement" ref={videoRef} controls autoPlay onProgress={setProgress}> <video className="videoElement" ref={videoRef} controls autoPlay onProgress={setProgress} onLoadedData={onLoad}>
<source src={streamUrl} type="video/mp4" /> <source src={streamUrl} type="video/mp4" />
</video> </video>
) )

View file

@ -20,15 +20,17 @@ export function MovieView(props) {
const [ episodeLists, setEpisodeList ] = React.useState([]); const [ episodeLists, setEpisodeList ] = React.useState([]);
const [ loading, setLoading ] = React.useState(false); const [ loading, setLoading ] = React.useState(false);
const [ selectedSeason, setSelectedSeason ] = React.useState("1"); const [ selectedSeason, setSelectedSeason ] = React.useState("1");
const [ startTime, setStartTime ] = React.useState(0);
const videoRef = React.useRef(null); const videoRef = React.useRef(null);
let isVideoTimeSet = React.useRef(false) let isVideoTimeSet = React.useRef(false);
const season = showRouteMatch?.params.season || "1"; const season = showRouteMatch?.params.season || "1";
const episode = showRouteMatch?.params.episode || "1"; const episode = showRouteMatch?.params.episode || "1";
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps
function setEpisode({ season, episode }) { function setEpisode({ season, episode }) {
history.replace(`${baseRouteMatch.url}/season/${season}/episode/${episode}`); history.push(`${baseRouteMatch.url}/season/${season}/episode/${episode}`);
isVideoTimeSet.current = false;
} }
React.useEffect(() => { React.useEffect(() => {
@ -79,24 +81,12 @@ export function MovieView(props) {
}, [streamData.seasons, streamData.episodes, streamData.type, selectedSeason]) }, [streamData.seasons, streamData.episodes, streamData.type, selectedSeason])
React.useEffect(() => { React.useEffect(() => {
if (!isVideoTimeSet.current) { let ls = JSON.parse(localStorage.getItem("video-progress") || "{}")
let ls = JSON.parse(localStorage.getItem("video-progress") || "{}") let key = streamData.type === "show" ? `${season}-${episode}` : "full"
let key = streamData.type === "show" ? `${season}-${episode}` : "full" let time = ls?.[streamData.source]?.[streamData.type]?.[streamData.slug]?.[key]?.currentlyAt;
let time = ls?.[streamData.source]?.[streamData.type]?.[streamData.slug]?.[key]?.currentlyAt; setStartTime(time);
if (time) {
if (!videoRef.current) {
isVideoTimeSet.current = false;
return;
}
videoRef.current.currentTime = time;
}
}
isVideoTimeSet.current = true;
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps
}) }, [baseRouteMatch, showRouteMatch]);
const setProgress = (evt) => { const setProgress = (evt) => {
let ls = JSON.parse(localStorage.getItem("video-progress") || "{}") let ls = JSON.parse(localStorage.getItem("video-progress") || "{}")
@ -141,7 +131,7 @@ export function MovieView(props) {
Season {season}: Episode {episode} Season {season}: Episode {episode}
</Title> : undefined} </Title> : undefined}
<VideoElement streamUrl={streamUrl} loading={loading} setProgress={setProgress} videoRef={videoRef} /> <VideoElement streamUrl={streamUrl} loading={loading} setProgress={setProgress} videoRef={videoRef} startTime={startTime} />
{streamData.type === "show" ? {streamData.type === "show" ?
<EpisodeSelector <EpisodeSelector