2017-06-07 07:36:12 +02:00
|
|
|
import React from "react";
|
|
|
|
import { Thumbnail } from "component/common";
|
|
|
|
import player from "render-media";
|
|
|
|
import fs from "fs";
|
|
|
|
|
2017-06-09 01:41:44 +02:00
|
|
|
class VideoPlayer extends React.PureComponent {
|
2017-06-07 07:36:12 +02:00
|
|
|
componentDidMount() {
|
|
|
|
const elem = this.refs.media;
|
|
|
|
const { downloadPath, filename } = this.props;
|
|
|
|
const file = {
|
|
|
|
name: filename,
|
|
|
|
createReadStream: opts => {
|
|
|
|
return fs.createReadStream(downloadPath, opts);
|
|
|
|
},
|
|
|
|
};
|
|
|
|
player.append(file, elem, {
|
|
|
|
autoplay: true,
|
|
|
|
controls: true,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const { downloadPath, mediaType, poster } = this.props;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
{["audio", "application"].indexOf(mediaType) !== -1 &&
|
|
|
|
<Thumbnail src={poster} className="video-embedded" />}
|
|
|
|
<div ref="media" />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default VideoPlayer;
|