Add videos to be played across all pages. #1523
5 changed files with 51 additions and 12 deletions
|
@ -2,14 +2,12 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
showOverlay: ?boolean,
|
|
||||||
children: ?React.node,
|
children: ?React.node,
|
||||||
};
|
};
|
||||||
|
|
||||||
class Overlay extends React.PureComponent<Props> {
|
class Overlay extends React.PureComponent<Props> {
|
||||||
render() {
|
render() {
|
||||||
const { showOverlay, children } = this.props;
|
const { children } = this.props;
|
||||||
if (!showOverlay) return '';
|
|
||||||
return <div className="overlay">{children}</div>;
|
return <div className="overlay">{children}</div>;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -118,7 +118,7 @@ class VideoPlayer extends React.PureComponent {
|
||||||
if (mediaElement) {
|
if (mediaElement) {
|
||||||
mediaElement.removeEventListener('click', this.togglePlayListener);
|
mediaElement.removeEventListener('click', this.togglePlayListener);
|
||||||
}
|
}
|
||||||
this.props.doPause();
|
// this.props.doPause();
|
||||||
}
|
}
|
||||||
|
|
||||||
toggleFullScreen(event) {
|
toggleFullScreen(event) {
|
||||||
|
|
|
@ -6,6 +6,7 @@ import type { Claim } from 'types/claim';
|
||||||
import VideoPlayer from './internal/player';
|
import VideoPlayer from './internal/player';
|
||||||
import VideoPlayButton from './internal/play-button';
|
import VideoPlayButton from './internal/play-button';
|
||||||
import LoadingScreen from './internal/loading-screen';
|
import LoadingScreen from './internal/loading-screen';
|
||||||
|
import ReactDOM from 'react-dom';
|
||||||
|
|
||||||
const SPACE_BAR_KEYCODE = 32;
|
const SPACE_BAR_KEYCODE = 32;
|
||||||
|
|
||||||
|
@ -59,7 +60,6 @@ class Video extends React.PureComponent<Props> {
|
||||||
window.addEventListener('keydown', this.handleKeyDown);
|
window.addEventListener('keydown', this.handleKeyDown);
|
||||||
|
|
||||||
const { showOverlay, doHideOverlay, uri, playingUri, overlayed } = this.props;
|
const { showOverlay, doHideOverlay, uri, playingUri, overlayed } = this.props;
|
||||||
// debugger;
|
|
||||||
if (showOverlay && uri === playingUri && !overlayed) {
|
if (showOverlay && uri === playingUri && !overlayed) {
|
||||||
doHideOverlay();
|
doHideOverlay();
|
||||||
}
|
}
|
||||||
|
@ -80,10 +80,27 @@ class Video extends React.PureComponent<Props> {
|
||||||
const { overlayed, doShowOverlay, mediaPaused } = this.props;
|
const { overlayed, doShowOverlay, mediaPaused } = this.props;
|
||||||
if (!overlayed && !mediaPaused) {
|
if (!overlayed && !mediaPaused) {
|
||||||
doShowOverlay();
|
doShowOverlay();
|
||||||
|
this.moveVideoToOverlay();
|
||||||
}
|
}
|
||||||
window.removeEventListener('keydown', this.handleKeyDown);
|
window.removeEventListener('keydown', this.handleKeyDown);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
moveVideoToOverlay() {
|
||||||
|
const topContainer = document.getElementById('video__overlay_id_top_container');
|
||||||
|
const container = document.getElementById('video__overlay_id');
|
||||||
|
const video = this.mediaContainer.media.getElementsByTagName("video")[0];
|
||||||
|
topContainer.classList.remove('hiddenContainer');
|
||||||
|
container.appendChild(video);
|
||||||
|
video.play();
|
||||||
|
}
|
||||||
|
|
||||||
|
destroyVideoOnOverlay() {
|
||||||
|
const topContainer = document.getElementById('video__overlay_id_top_container');
|
||||||
|
const videoContainer = document.getElementById('video__overlay_id');
|
||||||
|
topContainer.classList.add('hiddenContainer');
|
||||||
|
videoContainer.innerHTML = '';
|
||||||
|
}
|
||||||
|
|
||||||
handleKeyDown(event: SyntheticKeyboardEvent<*>) {
|
handleKeyDown(event: SyntheticKeyboardEvent<*>) {
|
||||||
const { searchBarFocused } = this.props;
|
const { searchBarFocused } = this.props;
|
||||||
if (!searchBarFocused && event.keyCode === SPACE_BAR_KEYCODE) {
|
if (!searchBarFocused && event.keyCode === SPACE_BAR_KEYCODE) {
|
||||||
|
@ -126,6 +143,7 @@ class Video extends React.PureComponent<Props> {
|
||||||
playContent() {
|
playContent() {
|
||||||
const { play, uri, showOverlay, playingUri, doHideOverlay } = this.props;
|
const { play, uri, showOverlay, playingUri, doHideOverlay } = this.props;
|
||||||
if (playingUri && showOverlay) {
|
if (playingUri && showOverlay) {
|
||||||
|
this.destroyVideoOnOverlay();
|
||||||
doHideOverlay();
|
doHideOverlay();
|
||||||
}
|
}
|
||||||
play(uri);
|
play(uri);
|
||||||
|
@ -205,6 +223,7 @@ class Video extends React.PureComponent<Props> {
|
||||||
hiddenControls={hiddenControls}
|
hiddenControls={hiddenControls}
|
||||||
overlayed={overlayed}
|
overlayed={overlayed}
|
||||||
doHideOverlay={doHideOverlay}
|
doHideOverlay={doHideOverlay}
|
||||||
|
ref={mediaContainer => this.mediaContainer = mediaContainer }
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -29,33 +29,52 @@ class VideoOverlay extends React.Component<Props> {
|
||||||
const { doCancelPlay, doHideOverlay } = this.props;
|
const { doCancelPlay, doHideOverlay } = this.props;
|
||||||
doCancelPlay();
|
doCancelPlay();
|
||||||
doHideOverlay();
|
doHideOverlay();
|
||||||
|
this.destroyMediaPlayer();
|
||||||
}
|
}
|
||||||
|
|
||||||
returnToMedia() {
|
returnToMedia() {
|
||||||
const { navigate, playingUri, doHideOverlay } = this.props;
|
const { navigate, playingUri, doHideOverlay } = this.props;
|
||||||
doHideOverlay();
|
doHideOverlay();
|
||||||
|
this.destroyMediaPlayer();
|
||||||
navigate('/show', { uri: playingUri });
|
navigate('/show', { uri: playingUri });
|
||||||
}
|
}
|
||||||
|
|
||||||
renderPlayOrPauseButton() {
|
renderPlayOrPauseButton() {
|
||||||
const { mediaPaused, doPause, doPlay } = this.props;
|
const { mediaPaused, doPause, doPlay } = this.props;
|
||||||
if (mediaPaused) {
|
if (mediaPaused) {
|
||||||
return <Button noPadding button="secondary" icon={icons.PLAY} onClick={() => doPlay()} />;
|
return <Button noPadding button="secondary" icon={icons.PLAY} onClick={() => this.getPlayer().play()} />;
|
||||||
}
|
}
|
||||||
return <Button noPadding button="secondary" icon={icons.PAUSE} onClick={() => doPause()} />;
|
return <Button noPadding button="secondary" icon={icons.PAUSE} onClick={() => this.getPlayer().pause()} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
getPlayer() {
|
||||||
|
return document.getElementById('video__overlay_id').getElementsByTagName("video")[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
destroyMediaPlayer(){
|
||||||
|
const topContainer = document.getElementById('video__overlay_id_top_container')
|
||||||
|
const videoContainer = document.getElementById('video__overlay_id');
|
||||||
|
topContainer.classList.add('hiddenContainer');
|
||||||
|
videoContainer.innerHTML = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { playingUri, showOverlay } = this.props;
|
const { playingUri, showOverlay } = this.props;
|
||||||
if (!showOverlay) return '';
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Overlay>
|
<Overlay>
|
||||||
<VideoOverlayHeader uri={playingUri} onClose={this.closeVideo} />
|
{(showOverlay && <VideoOverlayHeader uri={playingUri} onClose={this.closeVideo} />)}
|
||||||
|
|
||||||
<div className="video__overlay">
|
<div className="video__overlay">
|
||||||
<Video className="content__embedded" uri={playingUri} overlayed hiddenControls />
|
{/* <Video className="content__embedded" uri={playingUri} overlayed hiddenControls /> */}
|
||||||
<div className="video__mask">
|
{/* <div id="asdf"></div> */}
|
||||||
|
<div className="video content__embedded hiddenContainer" id="video__overlay_id_top_container">
|
||||||
|
<div className="content__view">
|
||||||
|
<div className="content__view--container" id="video__overlay_id">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{(showOverlay && <div className="video__mask" id="video_mask">
|
||||||
{this.renderPlayOrPauseButton()}
|
{this.renderPlayOrPauseButton()}
|
||||||
<Button
|
<Button
|
||||||
noPadding
|
noPadding
|
||||||
|
@ -63,7 +82,7 @@ class VideoOverlay extends React.Component<Props> {
|
||||||
icon={icons.MAXIMIZE}
|
icon={icons.MAXIMIZE}
|
||||||
onClick={() => this.returnToMedia()}
|
onClick={() => this.returnToMedia()}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>)}
|
||||||
</div>
|
</div>
|
||||||
</Overlay>
|
</Overlay>
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
.hiddenContainer {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
.overlay {
|
.overlay {
|
||||||
position: fixed;
|
position: fixed;
|
||||||
max-height: 50%;
|
max-height: 50%;
|
||||||
|
|
Loading…
Reference in a new issue