diff options
Diffstat (limited to 'components/videoPlayer.js')
| -rw-r--r-- | components/videoPlayer.js | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/components/videoPlayer.js b/components/videoPlayer.js index c680430..e568772 100644 --- a/components/videoPlayer.js +++ b/components/videoPlayer.js @@ -1,10 +1,22 @@ import Player from "../lib/Artplayer"; import { useEffect, useState } from "react"; +import { useAniList } from "../lib/useAnilist"; -export default function VideoPlayer({ data, seek, titles, id }) { +export default function VideoPlayer({ + data, + seek, + titles, + id, + progress, + session, + aniId, +}) { const [url, setUrl] = useState(); const [source, setSource] = useState([]); const [loading, setLoading] = useState(true); + const { markProgress } = useAniList(session); + + // console.log(progress); useEffect(() => { async function compiler() { @@ -70,6 +82,24 @@ export default function VideoPlayer({ data, seek, titles, id }) { }); art.on("destroy", () => { + const currentTime = art.currentTime; + const duration = art.duration; + const percentage = currentTime / duration; + + if (percentage >= 0.9) { + // use >= instead of > + markProgress(aniId, progress); + } else { + console.log("Something went wrong"); + } + }); + + art.on("video:ended", () => { + art.destroy(); + console.log("Video ended"); + }); + + art.on("destroy", () => { const lastPlayed = { id: id, time: art.currentTime, |