add artplayer-template

This commit is contained in:
Harvey Zack committed 2022-05-03 11:11:23 +08:00
1 parent 8fa763b9c7
commit 703f881019
59 files changed
+1408 -1

No files matched your search

@@ -0,0 +1,25 @@
import { useEffect, useRef } from "react";
import Artplayer from "artplayer";
export default function ({ option, getInstance, ...rest }) {
const artRef = useRef();
useEffect(() => {
const art = new Artplayer({
...option,
container: artRef.current,
});
if (getInstance && typeof getInstance === "function") {
getInstance(art);
}
return () => {
if (art && art.destroy) {
art.destroy(false);
}
};
}, [option, getInstance]);
return <div ref={artRef} {...rest}></div>;
}
@@ -0,0 +1,7 @@
import '../styles/globals.css'
function MyApp({ Component, pageProps }) {
return <Component {...pageProps} />
}
export default MyApp
@@ -0,0 +1,5 @@
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
export default function handler(req, res) {
res.status(200).json({ name: 'John Doe' })
}
@@ -0,0 +1,21 @@
import { useRef } from "react";
import Artplayer from "./Artplayer";
export default function Home() {
const option = useRef({
url: "https://artplayer.org/assets/sample/video.mp4",
autoSize: true,
});
return (
<Artplayer
option={option.current}
style={{
width: "600px",
height: "400px",
margin: "60px auto 0",
}}
getInstance={(art) => console.log(art)}
/>
);
}