forked from u-wave/react-vimeo
-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
117 lines (105 loc) · 2.76 KB
/
app.js
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
/* global document */
import React from 'react';
import ReactDOM from 'react-dom';
import Vimeo from '@u-wave/react-vimeo'; // eslint-disable-line import/no-unresolved
const videos = [
{ id: 115783408, name: 'Jambinai - Connection' },
{ id: 162959050, name: 'Jambinai - They Keep Silence' },
{ id: 169408731, name: 'Hoody - Like You' },
];
class App extends React.Component {
constructor(props) {
super(props);
this.state = {
videoIndex: 0,
volume: 1,
paused: false,
};
this.handlePause = this.handlePause.bind(this);
this.handlePlayerPause = this.handlePlayerPause.bind(this);
this.handlePlayerPlay = this.handlePlayerPlay.bind(this);
this.handleVolume = this.handleVolume.bind(this);
}
handlePause(event) {
this.setState({
paused: event.target.checked,
});
}
handlePlayerPause() {
this.setState({ paused: true });
}
handlePlayerPlay() {
this.setState({ paused: false });
}
handleVolume(event) {
this.setState({
volume: parseFloat(event.target.value),
});
}
selectVideo(index) {
this.setState({ videoIndex: index });
}
render() {
const { videoIndex, paused, volume } = this.state;
const video = videos[videoIndex];
return (
<div className="row">
<div className="col s4">
<h5>
Video
</h5>
<div className="collection">
{videos.map((choice, index) => (
<a
href={`#!/video/${index}`}
className={`collection-item ${video === choice ? 'active' : ''}`}
onClick={() => this.selectVideo(index)}
>
{choice.name}
</a>
))}
</div>
<h5>
Paused
</h5>
<p>
<label htmlFor="paused">
<input
type="checkbox"
id="paused"
checked={paused}
onChange={this.handlePause}
/>
<span>Paused</span>
</label>
</p>
<h5>
Volume
</h5>
<input
type="range"
value={volume}
min={0}
max={1}
step={0.01}
onChange={this.handleVolume}
/>
</div>
<div className="col s8 center-align">
<Vimeo
video={video.id}
width={640}
height={480}
autoplay
volume={volume}
paused={paused}
onPause={this.handlePlayerPause}
onPlay={this.handlePlayerPlay}
/>
</div>
</div>
);
}
}
// eslint-disable-next-line react/no-deprecated
ReactDOM.render(<App />, document.getElementById('example'));