forked from roman01la/react-a11y-video
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayback-time.jsx
62 lines (40 loc) · 1.28 KB
/
playback-time.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import React from 'react';
let PlaybackTime = React.createClass({
getInitialState() {
return {
currTime: '00:00',
duration: 0
};
},
componentWillReceiveProps (nextProps) {
if (this.props.api !== nextProps.api) {
nextProps.api
.addEventListener('timeupdate', this._onTimeUpdate, false);
let check = setInterval(() => {
if (nextProps.api.duration > 0) {
this.setState({ duration: nextProps.api.duration });
clearInterval(check);
}
}, 1000);
}
},
_onTimeUpdate() {
let api = this.props.api;
let mins = this._formatTime(parseInt((api.currentTime / 60) % 60)),
secs = this._formatTime(parseInt(api.currentTime % 60));
this.setState({ currTime: mins + ':' + secs});
},
_formatTime (time) {
return ('0' + time).slice(-2);
},
render() {
return (
<div className='playback-time'
tabIndex='0'
aria-label={'Video duration is ' + Math.round(this.state.duration) + ' seconds.'}>
{this.state.currTime}
</div>
);
}
});
export default PlaybackTime;