mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-08 19:06:15 -08:00
29 lines
644 B
JavaScript
29 lines
644 B
JavaScript
import React, { useEffect, useRef } from 'react';
|
|
import Artplayer from 'artplayer';
|
|
|
|
export default function Player({ 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);
|
|
}
|
|
};
|
|
}, []);
|
|
|
|
return React.createElement('div', {
|
|
ref: artRef,
|
|
...rest,
|
|
});
|
|
}
|