-
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.
Merge pull request #278 from gaohan085/dev
migrate to artplayer
- Loading branch information
Showing
13 changed files
with
206 additions
and
80 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,14 @@ | ||
.artplayer { | ||
padding: 18px; | ||
> div:nth-child(1) { | ||
width: 1120px; | ||
height: 630px; | ||
z-index: 0; | ||
|
||
@media (width <= 992px) { | ||
width: auto; | ||
height: auto; | ||
aspect-ratio: 16/9; | ||
} | ||
} | ||
} |
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,76 @@ | ||
import React, { forwardRef, useEffect, useRef } from "react"; | ||
import ArtPlayer from "artplayer" | ||
import { Title } from "./player-title"; | ||
import * as styles from "./artplayer.module.scss" | ||
import * as lib from "../lib" | ||
|
||
const ForwardArtPlayer = forwardRef(function ArtPlayer(props, ref: React.LegacyRef<HTMLDivElement> | undefined) { | ||
return ( | ||
<div ref={ref} /> | ||
) | ||
}) | ||
|
||
const APlayer: React.FC<{ option: Omit<ArtPlayer["option"], "container"> }> = (props) => { | ||
const { option } = props | ||
const ref = useRef<HTMLDivElement>(null) | ||
|
||
useEffect(() => { | ||
const art = new ArtPlayer({ | ||
...option, | ||
container: ref.current! | ||
}) | ||
|
||
art.on("video:loadedmetadata", async () => { | ||
await new Promise(r => setTimeout(r, 2500)) | ||
await art.play() | ||
}) | ||
|
||
lib.redux.store.subscribe(() => { | ||
const playingVideo = lib.redux.store.getState().redux.playingVideo | ||
|
||
if (encodeURI(playingVideo.playSrc) !== art.url) { | ||
art.url = playingVideo.playSrc | ||
art.poster = "/assets/poster/" + playingVideo?.poster | ||
} | ||
}) | ||
|
||
return () => { | ||
if (art && art.destroy) { | ||
art.destroy(false) | ||
} | ||
} | ||
}, []) | ||
|
||
return ( | ||
<div className={styles.artplayer}> | ||
<ForwardArtPlayer ref={ref} /> | ||
<Title /> | ||
</div> | ||
) | ||
} | ||
|
||
export const Art: React.FC = (props) => { | ||
const option: Omit<ArtPlayer["option"], "container"> = { | ||
url: "", | ||
screenshot: true, | ||
autoplay: false, | ||
setting: true, | ||
hotkey: true, | ||
pip: true, | ||
mutex: true, | ||
fullscreen: true, | ||
fullscreenWeb: true, | ||
playsInline: true, | ||
autoOrientation: true, | ||
theme: "#e85982", | ||
autoPlayback: true, | ||
id: "playbackid" | ||
} | ||
|
||
return ( | ||
<div> | ||
<APlayer option={option} /> | ||
</div> | ||
) | ||
} | ||
|
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
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,38 @@ | ||
.title { | ||
border-left: 3px solid #e85982; | ||
border-right: 3px solid #e85982; | ||
padding: 0.25rem 1rem; | ||
margin-top: 1rem; | ||
border-radius: 5px; | ||
|
||
> h4 { | ||
margin-block-end: 0em; | ||
margin-block-start: 0em; | ||
} | ||
|
||
> [class~="info"] { | ||
display: flex; | ||
justify-content: space-between; | ||
|
||
> a { | ||
margin-block-start: 0.6em; | ||
margin-block-end: 0em; | ||
line-height: 22px; | ||
font-size: 14px; | ||
font-style: italic; | ||
display: block; | ||
|
||
> span { | ||
display: inline-block; | ||
vertical-align: middle; | ||
font-size: 20px; | ||
margin-right: 3px; | ||
} | ||
|
||
&:hover { | ||
color: #e85982; | ||
text-decoration: underline; | ||
} | ||
} | ||
} | ||
} |
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,36 @@ | ||
import React from "react"; | ||
import { FcLink } from "react-icons/fc"; | ||
import { Link } from "react-router-dom"; | ||
import * as lib from "../lib"; | ||
import * as styles from "./player-title.module.scss" | ||
|
||
const Title: React.FC = () => { | ||
const videoPlaying = lib.redux.useAppSelector(lib.redux.selectVideoPlaying); | ||
const serialNumber = videoPlaying.name.match( | ||
/([0-9]|[a-z]|[A-Z]){3,}-[0-9]{3,}/g, | ||
); | ||
|
||
return ( | ||
<div className={styles["title"]}> | ||
<h4> | ||
{!!videoPlaying.name && | ||
`${serialNumber ? serialNumber[0] : videoPlaying.name} ${videoPlaying.title}`} | ||
{!videoPlaying.name && "没有正在播放"} | ||
</h4> | ||
<div className="info"> | ||
{!!videoPlaying.actress && ( | ||
<Link to={`/actress/${videoPlaying.actress}`}> | ||
{videoPlaying.actress} | ||
</Link> | ||
)} | ||
{ | ||
!!videoPlaying.sourceUrl && <a href={videoPlaying.sourceUrl} target="_blank" rel="noreferrer"> | ||
<span><FcLink /></span>{"On JavDB"} | ||
</a> | ||
} | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export { Title } |
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
Oops, something went wrong.