summaryrefslogtreecommitdiff
path: root/animism-align/frontend/app/views/viewer/player/components.inline/inline.video.js
blob: 00f2de426658bf6d51cd89870407336ac50d835b (plain)
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
import React, { Component } from 'react'
import VimeoPlayer from 'app/utils/vendor/vimeo'

import actions from 'app/actions'
import { CURTAIN_COLOR_LOOKUP } from 'app/constants'
import { SpeakerIcon } from '../../nav/viewer.icons'
import { MediaCitation } from '../components.media'
import { posterURL } from 'app/utils/annotation.utils'

export class MediaVideo extends Component {
  state = {
    width: 0,
    ready: false,
  }
  constructor(props) {
    super(props)
    this.handleReady = this.handleReady.bind(this)
    this.handlePlay = this.handlePlay.bind(this)
  }
  handleReady(player) {
    player.getVideoWidth().then(width => {
      this.setState({ width })
    }).catch(error => {
    })
  }
  handlePlay() {
    this.setState({ ready: true })
  }
  render() {
    const { paragraph, media, currentParagraph, onAnnotationClick } = this.props
    const { ready } = this.state
    if (!media.lookup) return <div />
    // const { color } = element
    const className = currentParagraph ? 'media video current' : 'media video'
    const annotation = paragraph.annotations[0]
    const item = media.lookup[annotation.settings.media_id]
    if (!item) return <div>Media not found: {annotation.settings.media_id}</div>
    const color = CURTAIN_COLOR_LOOKUP[annotation.settings.color] || CURTAIN_COLOR_LOOKUP.white
    const height = window.innerHeight - (17 * 16)
    let style = {
      color: color.textColor,
      height: height + 32,
      backgroundColor: color.backgroundColor,
    }

    // if this is a fullscreen video, display the poster image
    if (annotation.settings.fullscreen && !annotation.settings.inline) {
      const colorName = annotation.settings.poster_background_color || annotation.settings.color || 'white'
      const color = CURTAIN_COLOR_LOOKUP[colorName]
      const elementStyle = {
        color: color.textColor,
        backgroundColor: color.backgroundColor,
      }
      style.color = color.textColor
      style.backgroundColor = color.backgroundColor
      // style.backgroundImage = 'url(' + posterURL(item) + ')'
      if (annotation.settings.poster_size) {
        style.backgroundSize = annotation.settings.poster_size
      }
      return (
        <div className={className}>
          <div
            className='videoPoster'
            style={style}
            onClick={e => {
              if (annotation.settings.can_play_full_video) {
                e && e.stopPropagation()
                actions.viewer.openVideoModal(item, color)
              } else {
                onAnnotationClick(e, paragraph, annotation)
              }
            }}
          >
            <div className='posterImage'>
              <img src={posterURL(item)} />
              {annotation.settings.can_play_full_video ? (
                <div className="speaker-icon speaker-msg">
                  <div>
                    {SpeakerIcon}
                    <span>Watch full film</span>
                  </div>
                </div>
              ) : (
                <div className="speaker-icon">
                  {SpeakerIcon}
                </div>
              )}
            </div>
          </div>
          <MediaCitation media={item} />
        </div>
      )
    }

    // otherwise, inline the vimeo player
    const poster = annotation.settings.poster ? {
      backgroundImage: 'url(' + posterURL(item) + ')',
    } : {}
    style.opacity = ready ? 1.0 : 0.0
    return (
      <div className={className}>
        <div className='videoContainer' style={style}>
          <div className='videoPlayer'>
            <VimeoPlayer
              video={item.url}
              autoplay={annotation.settings.autoplay}
              muted={true}
              responsive={true}
              controls={false}
              byline={false}
              style={poster}
              onReady={this.handleReady}
              onPlay={this.handlePlay}
            />
          </div>
          {this.state.width && (
            <div
              className="speaker-icon"
              style={{
                right: '50%',
                marginRight: -1 * (this.state.width / 2 - 48 - 16)
              }}
              onClick={e => onAnnotationClick(e, paragraph, annotation)}
            >{SpeakerIcon}</div>
          )}
        </div>
        <MediaCitation media={item} />
      </div>
    )
  }
}