mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-10 21:06:15 -08:00
- Implemented a React template with Vite, including ESLint configuration and necessary dependencies. - Created a Vue template with Vite, including setup for Artplayer and plugins. - Added internationalization support in both React and Vue examples. - Included sample video and Danmuku plugin integration in both frameworks. - Established project structure with appropriate configuration files and README documentation.
48 lines
1.2 KiB
TypeScript
48 lines
1.2 KiB
TypeScript
import { useEffect, useRef } from 'react'
|
|
import Artplayer, { type Option } from 'artplayer'
|
|
|
|
// Test i18n
|
|
import fr from 'artplayer/i18n/fr'
|
|
import id from 'artplayer/i18n/id'
|
|
|
|
// Test plugins
|
|
import artplayerPluginDanmuku from 'artplayer-plugin-danmuku'
|
|
import artplayerPluginDocumentPip from 'artplayer-plugin-document-pip'
|
|
|
|
interface PlayerProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
option: Partial<Option>,
|
|
getInstance?: (art: Artplayer) => void
|
|
}
|
|
|
|
export default function Player({ option, getInstance, ...rest }: PlayerProps) {
|
|
const containerRef = useRef<HTMLDivElement | null>(null)
|
|
|
|
useEffect(() => {
|
|
if (!containerRef.current) return
|
|
|
|
const art = new Artplayer({
|
|
...option,
|
|
container: containerRef.current,
|
|
url: option.url as string,
|
|
i18n: { id, fr },
|
|
lang: 'fr',
|
|
plugins: [
|
|
artplayerPluginDocumentPip({}),
|
|
artplayerPluginDanmuku({
|
|
danmuku: 'https://artplayer.org/assets/sample/danmuku.xml',
|
|
}),
|
|
],
|
|
})
|
|
|
|
if (typeof getInstance === 'function') {
|
|
getInstance(art)
|
|
}
|
|
|
|
return () => {
|
|
art.destroy(false)
|
|
}
|
|
}, [option, getInstance])
|
|
|
|
return <div ref={containerRef} {...rest}></div>
|
|
}
|