mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-10 04:36:15 -08:00
37 lines
897 B
JavaScript
37 lines
897 B
JavaScript
import React from 'react';
|
|
import Artplayer from 'artplayer';
|
|
|
|
export default class ArtplayerReact extends React.Component {
|
|
constructor(props) {
|
|
super(props);
|
|
this.instance = null;
|
|
this.artRef = React.createRef();
|
|
}
|
|
|
|
componentDidMount() {
|
|
const { option, getInstance } = this.props;
|
|
this.instance = new Artplayer({
|
|
...option,
|
|
container: this.artRef.current,
|
|
});
|
|
|
|
if (getInstance && typeof getInstance === 'function') {
|
|
getInstance(this.instance);
|
|
}
|
|
}
|
|
|
|
componentWillUnmount() {
|
|
if (this.instance && this.instance.destroy) {
|
|
this.instance.destroy();
|
|
}
|
|
}
|
|
|
|
render() {
|
|
const { option, getInstance, ...rest } = this.props;
|
|
return React.createElement('div', {
|
|
ref: this.artRef,
|
|
...rest,
|
|
});
|
|
}
|
|
}
|