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 '../components.media' class FullscreenVideo 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, } 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.handleEnd = this.handleEnd.bind(this) } componentDidMount() { const video_start_ts = timestampToSeconds(this.props.element.settings.video_start_ts) || 0.0 // TODO: here you can add the current play time modulo ... this.setState({ seek: video_start_ts, video_start_ts, }) } componentDidUpdate(prevProps) { // if the play_ts jumped more than a second, seek const { play_ts, element } = this.props if (Math.abs(play_ts - prevProps.play_ts) > 1.0) { // handle seek const { duration, video_start_ts } = this.state const seek = ((play_ts - element.start_ts) % duration) + video_start_ts this.setState({ seek }) } // if we started leaving the element... if (element.fadeOutDuration && !this.state.fadeOut && element.settings.unmuted) { // console.log("fade out audio", this.props.fadeOutDuration) setTimeout(() => this.setState({ fadeOut: true }), 0) } } handlePlay() { this.setState({ ready: true }) } handlePause() { } handleEnd() { } handleTimeUpdate(timing) { if (!this.state.scrubbing || ('scrubbing' in timing)) { this.setState(timing) } } handleScrub(timing) { // console.log(timing) this.setState(timing) } render() { const { element, media, transitionDuration, play_ts, playing, cc, volume } = this.props const { duration, seconds, ready, fadeOut } = this.state const { color } = element const item = media.lookup[element.settings.media_id] const style = { backgroundColor: color.backgroundColor, color: color.textColor, transitionDuration, } const playerStyle = { opacity: ready ? 1.0 : 0.0 } // return (
) } } const mapStateToProps = state => ({ viewer: state.viewer, play_ts: state.audio.play_ts, playing: state.audio.playing, volume: state.audio.volume, cc: state.audio.cc, }) export default connect(mapStateToProps)(FullscreenVideo)