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
151
152
153
154
155
156
157
158
159
160
|
import React, { Component } from 'react'
import { connect } from 'react-redux'
import VimeoPlayer from 'app/utils/vendor/vimeo'
import actions from 'app/actions'
import { timestampToSeconds } from 'app/utils'
import { VideoScrubber, VideoSubtitles } from '../player/components.media'
class ModalVideo extends Component {
state = {
// duration of the video, in seconds
duration: 60.0,
// percentage offset from vimeo. not used
percent: 0.0,
// current timestamp from vimeo, in seconds
seconds: 0.0,
// video start offset, in seconds
video_start_ts: 0.0,
// seek position, used to tell the player to seek
seek: 0.0,
// whether or not the scrubber is scrubbing
scrubbing: false,
// whether or not the video is ready and displaying an image
ready: false,
// trigger an audio fade-out
fadeOut: false,
// volume
volume: 1.0,
volumeFadeTime: 1000,
lastCue: -1,
// play state
playing: false,
}
constructor(props) {
super(props)
this.handlePlay = this.handlePlay.bind(this)
this.handlePause = this.handlePause.bind(this)
this.handleTimeUpdate = this.handleTimeUpdate.bind(this)
this.handleScrub = this.handleScrub.bind(this)
this.handleToggle = this.handleToggle.bind(this)
this.handleEnd = this.handleEnd.bind(this)
}
componentDidUpdate(prevProps) {
if (prevProps.open && !this.props.open) {
setTimeout(() => {
actions.viewer.resetVideoModal()
}, 500)
}
}
handlePlay() {
this.setState({ ready: true, playing: true })
}
handlePause() {
console.log("pause")
this.setState({ playing: false })
}
handleEnd() {
this.setState({ playing: false })
}
handleTimeUpdate(timing) {
console.log(timing.seconds)
if (!this.state.scrubbing || ('scrubbing' in timing)) {
this.setState({
...timing,
playing: true
})
}
}
handleScrub(timing) {
console.log('scrub', timing.seconds)
if (timing.seconds) {
this.setState({
playing: true,
...timing,
seek: timing.seconds,
})
} else {
this.setState({ scrubbing: false })
}
}
handleToggle() {
this.setState({ playing: !this.state.playing })
}
render() {
const { open, media: mediaItem, color, cc, playerVolume } = this.props
const { duration, seconds, ready, volume, volumeFadeTime, playing, fadeOut, lastCue } = this.state
if (!color || !mediaItem) {
return <div />
}
const style = {
backgroundColor: color.backgroundColor,
color: color.textColor,
}
const playerStyle = {
opacity: ready ? 1.0 : 0.0
}
// console.log(volume, playerVolume)
return (
<div
className={open ? 'video-modal open' : 'video-modal'}
style={style}
>
<div className='fullscreen-element video' onClick={this.handleToggle}>
<div
className='videoPlayer'
style={playerStyle}
>
<VimeoPlayer
video={mediaItem.url}
paused={!open || (ready && !playing)}
autoplay={true}
autopause={false}
muted={false}
loop={false}
seek={this.state.seek}
responsive={true}
controls={false}
byline={false}
volume={playerVolume}
targetVolume={playerVolume}
volumeFadeTime={volumeFadeTime}
fadeOut={0}
onPlay={this.handlePlay}
onPause={this.handlePause}
onTimeUpdate={this.handleTimeUpdate}
onEnd={this.handleEnd}
lastCue={lastCue}
/>
</div>
<VideoScrubber
play_ts={seconds}
start_ts={0}
video_start_ts={0}
playing={playing}
duration={duration}
timing={this.state}
mediaItem={mediaItem}
cc={cc}
onScrub={this.handleScrub}
onToggle={this.handleToggle}
scrubMasterAudio={false}
/>
<VideoSubtitles
cc={cc}
play_ts={seconds}
mediaItem={mediaItem}
/>
</div>
</div>
)
}
}
const mapStateToProps = state => ({
...state.viewer.videoModal,
playerVolume: state.audio.volume,
cc: state.audio.cc,
})
export default connect(mapStateToProps)(ModalVideo)
|