mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-17 10:01:20 -08:00
添加react组件
This commit is contained in:
1 parent
f13aebd720
commit
e00fab0bfe
6 files changed
+129
No files matched your search
@@ -0,0 +1,12 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>WIP</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||
</head>
|
||||
<body>
|
||||
WIP
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,9 @@
|
||||
node_modules
|
||||
.DS_Store
|
||||
yarn.lock
|
||||
package-lock.json
|
||||
test
|
||||
coverage
|
||||
.nyc_output
|
||||
.cache
|
||||
docs
|
||||
@@ -0,0 +1 @@
|
||||
package-lock=false
|
||||
@@ -0,0 +1,42 @@
|
||||
# artplayer-react
|
||||
|
||||
Artplayer React Component, It is recommended to package itself according to actual business needs.
|
||||
|
||||
## Demo
|
||||
|
||||
[Checkout the demo](https://artplayer.org/react/) from Github Pages
|
||||
|
||||
## Install
|
||||
|
||||
Install with `npm`
|
||||
|
||||
```
|
||||
$ npm install artplayer-react
|
||||
```
|
||||
|
||||
Or install with `yarn`
|
||||
|
||||
```
|
||||
$ yarn add artplayer-react
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```js
|
||||
import Artplayer from 'artplayer-react';
|
||||
import 'artplayer/dist/artplayer.css';
|
||||
|
||||
// ...
|
||||
<Artplayer
|
||||
option={
|
||||
{
|
||||
// option, no 'container' property required
|
||||
}
|
||||
}
|
||||
getInstance={ins => console.log(ins)} // get the instance
|
||||
/>;
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
MIT © [Harvey Zack](https://www.zhw-island.com/)
|
||||
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"name": "artplayer-react",
|
||||
"version": "1.0.6",
|
||||
"description": "Artplayer React Component",
|
||||
"main": "src/index.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/zhw2590582/ArtPlayer.git"
|
||||
},
|
||||
"keywords": [
|
||||
"video",
|
||||
"player"
|
||||
],
|
||||
"author": "Harvey Zack <laozhaochaguan@gmail.com>",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/zhw2590582/ArtPlayer/issues"
|
||||
},
|
||||
"homepage": "https://github.com/zhw2590582/ArtPlayer#readme",
|
||||
"dependencies": {
|
||||
"artplayer": "^1.0.6",
|
||||
"react": "^16.8.6",
|
||||
"react-dom": "^16.8.6"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
import React, { Component } from 'react';
|
||||
import Artplayer from 'artplayer';
|
||||
|
||||
export default class ArtplayerComponent extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
Artplayer.utils.errorHandle(
|
||||
props.option && typeof props.option === 'object',
|
||||
"The prop 'option' object cannot be missing",
|
||||
);
|
||||
this.instance = null;
|
||||
this.artRef = React.createRef();
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
const { option, getInstance } = this.props;
|
||||
this.instance = new Artplayer({
|
||||
...option,
|
||||
container: this.artRef,
|
||||
});
|
||||
|
||||
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 <div ref={this.artRef} {...rest} />;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user