-
Notifications
You must be signed in to change notification settings - Fork 169
Expand file tree
/
Copy pathindex.js
More file actions
150 lines (130 loc) · 4.32 KB
/
index.js
File metadata and controls
150 lines (130 loc) · 4.32 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import React from 'react';
import PropTypes from 'prop-types';
import isEqual from 'react-fast-compare';
import {
faSave,
faTv,
faPlay,
faPause,
faBackward,
faForward,
faUndo,
faVolumeUp,
faVolumeMute
} from '@fortawesome/free-solid-svg-icons';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import PlaybackRate from '../PlaybackRate';
import TimeBox from './TimeBox.js';
import style from './index.module.scss';
class PlayerControls extends React.Component {
shouldComponentUpdate = (nextProps) => {
return !isEqual(this.props, nextProps);
}
setIntervalHelperBackward = () => {
// this.props.skipBackward();
this.interval = setInterval(() => {
this.props.skipBackward();
}, 300);
}
setIntervalHelperForward = () => {
// this.props.skipForward();
this.interval = setInterval(() => {
this.props.skipForward();
}, 300);
}
clearIntervalHelper = () => {
clearInterval(this.interval);
}
render() {
const pictureInPicture = ('pictureInPictureEnabled' in document) ? ( <button
type="button"
value="Picture-in-picture"
title="Picture-in-picture"
className={ `${ style.playerButton } ${ style.pip }` }
onClick={ this.props.pictureInPicture }>
<FontAwesomeIcon icon={ faTv } />
</button> ) : null;
return (
<div className={ style.playerControls }>
<TimeBox
promptSetCurrentTime={ this.props.promptSetCurrentTime }
currentTime={ this.props.currentTime }
duration={ this.props.duration }
/>
<div className={ style.btnsGroup }>
<button
type="button"
value="seek backward by a set interval: alt r"
title="seek backward by a set interval: alt r"
className={ style.playerButton }
onClick={ this.props.rollback }>
<FontAwesomeIcon icon={ faUndo } />
</button>
<button
type="button"
value="seek backward: alt j"
title="seek backward: alt j"
className={ style.playerButton }
onMouseDown={ this.setIntervalHelperBackward }
onMouseUp={ this.clearIntervalHelper }
onClick={ () => {this.props.skipBackward(); } }>
<FontAwesomeIcon icon={ faBackward } />
</button>
<button
type="button"
value="Play/Pause: alt k"
title="Play/Pause: alt k"
className={ style.playerButton }
onClick={ this.props.playMedia }>
{this.props.isPlaying ? <FontAwesomeIcon icon={ faPause } /> : <FontAwesomeIcon icon={ faPlay } />}
</button>
<button
value="seek forward: alt l"
title="seek forward: alt l"
type="button"
className={ style.playerButton }
onMouseDown={ this.setIntervalHelperForward }
onMouseUp={ this.clearIntervalHelper }
onClick={ () => {this.props.skipForward(); } }>
<FontAwesomeIcon icon={ faForward } />
</button>
</div>
<div className={ style.btnsGroup }>
<PlaybackRate
playbackRateOptions={ this.props.playbackRateOptions }
playbackRate={ this.props.playbackRate }
name={ 'playbackRate' }
handlePlayBackRateChange={ this.props.setPlayBackRate }
/>
{pictureInPicture}
<button
type="button"
value="Toggle Sound"
title="Toggle Sound"
className={ style.playerButton }
onClick={ this.props.handleMuteVolume }>
{ this.props.isMute ? <FontAwesomeIcon icon={ faVolumeMute } /> : <FontAwesomeIcon icon={ faVolumeUp } /> }
</button>
</div>
</div>
);
}
}
PlayerControls.propTypes = {
playMedia: PropTypes.func,
currentTime: PropTypes.string,
timecodeOffset: PropTypes.string,
promptSetCurrentTime: PropTypes.func,
rollback: PropTypes.func,
handleMuteVolume: PropTypes.func,
duration: PropTypes.string,
isPlaying: PropTypes.bool,
isMute: PropTypes.bool,
skipBackward: PropTypes.func,
skipForward: PropTypes.func,
playbackRate: PropTypes.number,
playbackRateOptions: PropTypes.array,
setPlayBackRate: PropTypes.func,
pictureInPicture: PropTypes.func
};
export default PlayerControls;