Skip to content

Instantly share code, notes, and snippets.

@wizage
Created April 27, 2020 18:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wizage/1523dd1f6928e0d852042e6adbaf54cd to your computer and use it in GitHub Desktop.
Save wizage/1523dd1f6928e0d852042e6adbaf54cd to your computer and use it in GitHub Desktop.
Signed URL Example for UnicornFlix
// Replace overlayMovie() with this one:
overlayMovie = () => {
const { displayingMovie, sources, choosenItem: { title, description }, token } = this.state;
return (
<Modal id="popup" style={{ maxWidth: 755 }} isOpen={displayingMovie} toggle={this.hideMovie}>
<ModalHeader toggle={this.hideMovie}>{title}</ModalHeader>
<ModalBody>
{description}
<VideoPlayer
controls
sources={sources}
width={720}
height={420}
bigPlayButton={false}
autoplay
token={token}
/>
</ModalBody>
</Modal>
);
}
//Replace Location 13 with this: (Please note that this is using not best practices of GraphQL) Contact sampatze@ if you want to know how to update.
const region = Amplify._config.aws_project_region;
this.setState({
sources: [{
src: `https://${awsvideo.awsOutputVideo}/${item.video.id}/${item.video.id}.m3u8`,
type: 'application/x-mpegURL',
}],
displayingMovie: true,
choosenItem: item,
token: item.video.token,
});
/* eslint-disable jsx-a11y/media-has-caption */
import React from 'react';
import videojs from 'video.js';
import './index.css';
export default class VideoPlayer extends React.Component {
componentDidMount() {
videojs.Hls.xhr.beforeRequest = function (options) {
options.uri = `${options.uri}${videojs.getAllPlayers()[0].options().token}`;
return options;
};
this.player = videojs(this.videoNode, this.props);
}
componentWillUnmount() {
if (this.player) {
this.player.dispose();
}
}
render() {
return (
<div>
<div data-vjs-player>
<video ref={(node) => { this.videoNode = node; }} className="video-js" />
</div>
</div>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment