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

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 = {
    ready: false,
  }
  constructor(props) {
    super(props)
    this.handlePlay = this.handlePlay.bind(this)
  }
  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 => onAnnotationClick(e, paragraph, annotation)}
          >
            <div className="speaker-icon">{SpeakerIcon}</div>
          </div>
          <MediaCitation media={item} />
        </div>
      )
    }

    const poster = annotation.settings.poster ? {
      backgroundImage: 'url(' + posterURL(item) + ')',
    } : {}
    style.opacity = ready ? 1.0 : 0.0
    return (
      <div className={className}>
        <div className='videoPlayer' style={style}>
          <VimeoPlayer
            video={item.url}
            autoplay={annotation.settings.autoplay}
            muted={true}
            responsive={true}
            controls={false}
            byline={false}
            style={poster}
            onPlay={this.handlePlay}
          />
        </div>
        <MediaCitation media={item} />
      </div>
    )
  }
}