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
|
import React, { Component } from 'react'
import { connect } from 'react-redux'
import VimeoPlayer from 'app/utils/vendor/vimeo'
import actions from 'app/actions'
import { PlayButton, PlayerTime, VolumeControl } from 'app/views/viewer/nav/viewer.icons'
class FullscreenVideo extends Component {
state = {
duration: 0.0,
percent: 0.0,
seconds: 0.0,
seek: 0.0,
scrubbing: false,
}
constructor(props) {
super(props)
this.scrubberRef = React.createRef()
this.handlePlay = this.handlePlay.bind(this)
this.handlePause = this.handlePause.bind(this)
this.handleTimeUpdate = this.handleTimeUpdate.bind(this)
this.handleEnd = this.handleEnd.bind(this)
this.handleScrubBarClick = this.handleScrubBarClick.bind(this)
this.handleScrubDotMouseDown = this.handleScrubDotMouseDown.bind(this)
this.handleScrubDotMouseMove = this.handleScrubDotMouseMove.bind(this)
this.handleScrubDotMouseUp = this.handleScrubDotMouseUp.bind(this)
}
componentDidMount() {
window.addEventListener('mousemove', this.handleScrubDotMouseMove)
window.addEventListener('mouseup', this.handleScrubDotMouseUp)
}
componentWillUnmount() {
window.removeEventListener('mousemove', this.handleScrubDotMouseMove)
window.removeEventListener('mouseup', this.handleScrubDotMouseUp)
this.setState({ scrubbing: false })
}
componentDidUpdate(prevProps) {
if (Math.abs(this.props.play_ts - prevProps.play_ts) > 2.0) {
// handle seek
const seek = this.props.play_ts - this.props.element.start_ts
this.setState({ seek })
}
}
handlePlay() {
}
handlePause() {
}
handleEnd() {
}
handleTimeUpdate(timing) {
this.setState(timing)
}
handleScrubBarClick(e) {
e.stopPropagation()
const bounds = this.scrubberRef.current.getBoundingClientRect()
const percent = (e.pageX - bounds.left) / bounds.width
const seconds = percent * this.state.duration
actions.audio.seek(this.props.element.start_ts + seconds)
this.setState({ percent, seconds })
// actions.audio.seek(clamp(play_ts - 5.0, start_ts, end_ts))
}
handleScrubDotMouseDown(e) {
e.stopPropagation()
this.setState({ scrubbing: true })
}
handleScrubDotMouseMove(e) {
e.stopPropagation()
if (!this.state.scrubbing) return
}
handleScrubDotMouseUp(e) {
e.stopPropagation()
this.setState({ scrubbing: false })
}
render() {
const { element, media, transitionDuration, playing, volume } = this.props
const { duration, percent, seconds } = this.state
const { color } = element
const item = media.lookup[element.settings.media_id]
const style = {
backgroundColor: color.backgroundColor,
color: color.textColor,
transitionDuration,
}
// console.log(item)
return (
<div
className='fullscreen-element video'
style={style}
>
<div className='vimeoPlayer'>
<VimeoPlayer
video={item.url}
paused={!playing}
autoplay={true}
muted={true}
seek={this.state.seek}
responsive={true}
controls={false}
byline={false}
onPlay={this.handlePlay}
onPause={this.handlePause}
onTimeUpdate={this.handleTimeUpdate}
onEnd={this.handleEnd}
/>
</div>
<div
className='video-scrubber'
onClick={this.handleScrubBarClick}
ref={this.scrubberRef}
>
<div className='scrub-bar' />
<div
className='scrub-dot'
style={{ left: (100 * this.state.percent) + "%" }}
onMouseDown={this.handleScrubDotMouseDown}
/>
</div>
</div>
)
}
}
const mapStateToProps = state => ({
viewer: state.viewer,
play_ts: state.audio.play_ts,
playing: state.audio.playing,
volume: state.audio.volume,
})
export default connect(mapStateToProps)(FullscreenVideo)
|