|
@@ -3,7 +3,7 @@ import { Slider } from 'antd';
|
|
|
import './index.less';
|
|
|
import videojs from 'video.js';
|
|
|
import Assets from '@src/components/Assets';
|
|
|
-import { generateUUID } from '@src/services/Tools';
|
|
|
+import { generateUUID, formatSecondAuto } from '@src/services/Tools';
|
|
|
|
|
|
function fullScreen(id) {
|
|
|
const element = document.getElementById(id);
|
|
@@ -99,7 +99,7 @@ export default class Video extends Component {
|
|
|
this.timeInterval = setInterval(() => {
|
|
|
const { onTimeUpdate } = this.props;
|
|
|
if (onTimeUpdate) onTimeUpdate(this.player.currentTime());
|
|
|
- // this.setState({ progress: this.player.currentTime() * 100 / this.player.duration() });
|
|
|
+ this.setState({ progress: this.player.currentTime() * 100 / this.player.duration() });
|
|
|
}, 1000);
|
|
|
}
|
|
|
|
|
@@ -107,6 +107,12 @@ export default class Video extends Component {
|
|
|
if (!this.ready) return;
|
|
|
this.player.currentTime((this.player.duration() * value) / 100);
|
|
|
this.setState({ progress: (this.player.currentTime() * 100) / this.player.duration() });
|
|
|
+ const { onChangeProgress } = this.props;
|
|
|
+ const { playing } = this.state;
|
|
|
+ if (!playing) {
|
|
|
+ this.player.pause();
|
|
|
+ }
|
|
|
+ if (onChangeProgress) onChangeProgress(this.player.currentTime());
|
|
|
}
|
|
|
|
|
|
onPlay() {
|
|
@@ -114,7 +120,7 @@ export default class Video extends Component {
|
|
|
const { onPlay } = this.props;
|
|
|
this.player.play();
|
|
|
this.setState({ playing: true });
|
|
|
- if (onPlay) onPlay();
|
|
|
+ if (onPlay) onPlay(this.player.currentTime());
|
|
|
this.refreshTimeUpdate();
|
|
|
}
|
|
|
|
|
@@ -123,7 +129,7 @@ export default class Video extends Component {
|
|
|
const { onPause } = this.props;
|
|
|
this.player.pause();
|
|
|
this.setState({ playing: false });
|
|
|
- if (onPause) onPause();
|
|
|
+ if (onPause) onPause(this.player.currentTime());
|
|
|
this.clearTimeUpdate();
|
|
|
}
|
|
|
|
|
@@ -158,24 +164,46 @@ export default class Video extends Component {
|
|
|
exitFullscreen();
|
|
|
}
|
|
|
|
|
|
+ showProgressTip(e) {
|
|
|
+ let x = e.clientX;
|
|
|
+ const percent = x * 100 / this.progress.clientWidth;
|
|
|
+ const text = percent > 0 ? formatSecondAuto(percent * this.player.duration() / 100) : '00:00';
|
|
|
+ const width = text.length > 5 ? 67.8 : 47.3;
|
|
|
+ x += 1;
|
|
|
+ x -= width / 2;
|
|
|
+ if (x < 0) {
|
|
|
+ x = 0;
|
|
|
+ } else if (x + width > this.progress.clientWidth) {
|
|
|
+ x = this.progress.clientWidth - width;
|
|
|
+ }
|
|
|
+ this.setState({ pt: { left: x, display: 'block', text, width } });
|
|
|
+ }
|
|
|
+
|
|
|
+ hideProgressTip() {
|
|
|
+ this.setState({ pt: {} });
|
|
|
+ }
|
|
|
+
|
|
|
render() {
|
|
|
- const { btnList = [], children, onAction, hideAction } = this.props;
|
|
|
+ const { btnList = [], children, onAction, hideAction, water } = this.props;
|
|
|
const { playing, fulling, id, selectSpeed, speed } = this.state;
|
|
|
return (
|
|
|
<div id={id} className={`video-item ${!hideAction ? 'action' : ''} ${fulling ? 'full' : ''}`}>
|
|
|
- <div className="video-wrapper">
|
|
|
+ <div className="video-wrapper c-p" onClick={() => {
|
|
|
+ return playing ? this.onPause() : this.onPlay();
|
|
|
+ }}>
|
|
|
<video
|
|
|
ref={node => {
|
|
|
this.videoNode = node;
|
|
|
}}
|
|
|
// vjs-fluid
|
|
|
/>
|
|
|
- {!playing && <Assets className="play" name="play" onClick={() => this.onPlay()} />}
|
|
|
- {playing && <Assets className="stop" name="stop" onClick={() => this.onPause()} />}
|
|
|
+ {water}
|
|
|
+ {!playing && <Assets className="play c-p" name="play" />}
|
|
|
+ {playing && <Assets className="stop c-p" name="stop" />}
|
|
|
</div>
|
|
|
<div className="video-bottom">
|
|
|
- <div className="progress" />
|
|
|
- {/* {this.renderProgress()} */}
|
|
|
+ {/* <div className="progress" /> */}
|
|
|
+ {this.renderProgress()}
|
|
|
{!hideAction && (
|
|
|
<div className="action-bar">
|
|
|
<div className="d-i-b m-r-1">
|
|
@@ -188,8 +216,9 @@ export default class Video extends Component {
|
|
|
<div className="d-i-b m-r-1">
|
|
|
<Assets name="next2" onClick={() => this.onNext()} />
|
|
|
</div>
|
|
|
- {/* <div className="m-r-1">{this.ready ? (formatMinuteSecond(this.player.currentTime())) : ('00:00')}</div>
|
|
|
- <div className="m-r-1">/{this.ready ? (formatMinuteSecond(this.player.duration())) : ('00:00')}</div> */}
|
|
|
+ <div className="m-r-1 c-w">{this.ready ? (formatSecondAuto(this.player.currentTime())) : ('00:00')}</div>
|
|
|
+ <div className="m-r-1 c-w">/</div>
|
|
|
+ <div className="m-r-1 c-w">{this.ready ? (formatSecondAuto(this.player.duration())) : ('00:00')}</div>
|
|
|
<div className="flex-block" />
|
|
|
{btnList.map(btn => {
|
|
|
if (btn.full && !fulling) return '';
|
|
@@ -209,10 +238,7 @@ export default class Video extends Component {
|
|
|
) : (<div
|
|
|
className={`btn-action ${btn.active ? 'active' : ''}`}
|
|
|
onClick={() => onAction && onAction(btn.key)}
|
|
|
- >
|
|
|
- {btn.title}
|
|
|
- </div>
|
|
|
- )}
|
|
|
+ >{btn.title}</div>)}
|
|
|
</div>
|
|
|
);
|
|
|
})}
|
|
@@ -257,10 +283,10 @@ export default class Video extends Component {
|
|
|
|
|
|
renderProgress() {
|
|
|
const { hideProgress } = this.props;
|
|
|
- const { progress } = this.state;
|
|
|
+ const { progress, pt = {} } = this.state;
|
|
|
return (
|
|
|
!hideProgress && (
|
|
|
- <Slider value={progress || 0} tooltipVisible={false} onChange={value => this.onChangeProgress(value)} />
|
|
|
+ <div ref={ref => { if (ref) this.progress = ref; }} onMouseMove={(e) => this.showProgressTip(e)} onMouseLeave={() => this.hideProgressTip()}><Slider value={progress || 0} step={0.01} tooltipVisible={false} onChange={value => this.onChangeProgress(value)} /><div className={'show-progress-tip'} style={{ ...pt }}>{pt.text}</div></div>
|
|
|
)
|
|
|
);
|
|
|
}
|