2017-04-23 11:56:50 +02:00
|
|
|
import React from 'react';
|
|
|
|
import FilePrice from 'component/filePrice'
|
|
|
|
import Link from 'component/link';
|
|
|
|
import Modal from 'component/modal';
|
|
|
|
|
2017-05-15 05:50:59 +02:00
|
|
|
class VideoPlayButton extends React.Component {
|
2017-05-19 01:14:26 +02:00
|
|
|
onPurchaseConfirmed() {
|
2017-05-02 15:58:35 +02:00
|
|
|
this.props.closeModal()
|
|
|
|
this.props.startPlaying()
|
2017-05-15 05:50:59 +02:00
|
|
|
this.props.loadVideo(this.props.uri)
|
2017-05-02 15:58:35 +02:00
|
|
|
}
|
|
|
|
|
2017-05-17 23:52:45 +02:00
|
|
|
onWatchClick() {
|
|
|
|
this.props.purchaseUri(this.props.uri).then(() => {
|
|
|
|
if (!this.props.modal) {
|
|
|
|
this.props.startPlaying()
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-05-02 15:58:35 +02:00
|
|
|
render() {
|
|
|
|
const {
|
|
|
|
button,
|
|
|
|
label,
|
|
|
|
className,
|
|
|
|
metadata,
|
|
|
|
metadata: {
|
|
|
|
title,
|
|
|
|
},
|
|
|
|
uri,
|
|
|
|
modal,
|
|
|
|
closeModal,
|
|
|
|
isLoading,
|
|
|
|
costInfo,
|
|
|
|
fileInfo,
|
|
|
|
} = this.props
|
|
|
|
|
2017-05-15 05:50:59 +02:00
|
|
|
/*
|
|
|
|
title={
|
|
|
|
isLoading ? "Video is Loading" :
|
|
|
|
!costInfo ? "Waiting on cost info..." :
|
|
|
|
fileInfo === undefined ? "Waiting on file info..." : ""
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2017-05-26 20:36:18 +02:00
|
|
|
const disabled = isLoading || fileInfo === undefined || (fileInfo === null && (!costInfo || costInfo.cost === undefined))
|
|
|
|
|
2017-05-02 15:58:35 +02:00
|
|
|
return (<div>
|
|
|
|
<Link button={ button ? button : null }
|
2017-05-26 20:36:18 +02:00
|
|
|
disabled={disabled}
|
2017-05-02 15:58:35 +02:00
|
|
|
label={label ? label : ""}
|
|
|
|
className="video__play-button"
|
|
|
|
icon="icon-play"
|
2017-05-18 19:58:28 +02:00
|
|
|
onClick={this.onWatchClick.bind(this)} />
|
2017-05-02 15:58:35 +02:00
|
|
|
{modal}
|
2017-05-18 03:37:39 +02:00
|
|
|
<Modal contentLabel="Not enough credits" isOpen={modal == 'notEnoughCredits'} onConfirmed={() => { this.closeModal() }}>
|
2017-05-02 15:58:35 +02:00
|
|
|
You don't have enough LBRY credits to pay for this stream.
|
|
|
|
</Modal>
|
|
|
|
<Modal
|
|
|
|
type="confirm"
|
|
|
|
isOpen={modal == 'affirmPurchase'}
|
|
|
|
contentLabel="Confirm Purchase"
|
2017-05-19 01:14:26 +02:00
|
|
|
onConfirmed={this.onPurchaseConfirmed.bind(this)}
|
2017-05-02 15:58:35 +02:00
|
|
|
onAborted={closeModal}>
|
2017-05-15 18:34:33 +02:00
|
|
|
This will purchase <strong>{title}</strong> for <strong><FilePrice uri={uri} look="plain" /></strong> credits.
|
2017-05-02 15:58:35 +02:00
|
|
|
</Modal>
|
|
|
|
<Modal
|
2017-05-18 03:37:39 +02:00
|
|
|
isOpen={modal == 'timedOut'} onConfirmed={() => { this.closeModal() }} contentLabel="Timed Out">
|
2017-05-02 15:58:35 +02:00
|
|
|
Sorry, your download timed out :(
|
|
|
|
</Modal>
|
|
|
|
</div>);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-23 11:56:50 +02:00
|
|
|
const plyr = require('plyr')
|
|
|
|
|
|
|
|
class Video extends React.Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props)
|
2017-05-12 01:28:43 +02:00
|
|
|
this.state = { isPlaying: false }
|
2017-04-23 11:56:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
startPlaying() {
|
|
|
|
this.setState({
|
|
|
|
isPlaying: true
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const {
|
|
|
|
metadata,
|
|
|
|
isLoading,
|
|
|
|
isDownloading,
|
|
|
|
fileInfo,
|
|
|
|
} = this.props
|
|
|
|
const {
|
|
|
|
isPlaying = false,
|
|
|
|
} = this.state
|
|
|
|
|
2017-05-15 18:34:33 +02:00
|
|
|
const isReadyToPlay = fileInfo && fileInfo.written_bytes > 0
|
|
|
|
|
2017-04-23 11:56:50 +02:00
|
|
|
let loadStatusMessage = ''
|
|
|
|
|
|
|
|
if (isLoading) {
|
|
|
|
loadStatusMessage = "Requesting stream... it may sit here for like 15-20 seconds in a really awkward way... we're working on it"
|
|
|
|
} else if (isDownloading) {
|
|
|
|
loadStatusMessage = "Downloading stream... not long left now!"
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2017-05-19 01:14:26 +02:00
|
|
|
<div className={"video " + this.props.className + (isPlaying ? " video--active" : " video--hidden")}>{
|
|
|
|
isPlaying || isLoading ?
|
2017-05-15 18:34:33 +02:00
|
|
|
(!isReadyToPlay ?
|
2017-05-15 05:50:59 +02:00
|
|
|
<span>this is the world's worst loading screen and we shipped our software with it anyway... <br /><br />{loadStatusMessage}</span> :
|
2017-05-17 23:52:45 +02:00
|
|
|
<VideoPlayer poster={metadata.thumbnail} autoplay={isPlaying} downloadPath={fileInfo.download_path} />) :
|
2017-04-23 11:56:50 +02:00
|
|
|
<div className="video__cover" style={{backgroundImage: 'url("' + metadata.thumbnail + '")'}}>
|
2017-05-17 23:52:45 +02:00
|
|
|
<VideoPlayButton startPlaying={this.startPlaying.bind(this)} {...this.props} />
|
2017-04-23 11:56:50 +02:00
|
|
|
</div>
|
|
|
|
}</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-17 23:52:45 +02:00
|
|
|
class VideoPlayer extends React.Component {
|
2017-04-23 11:56:50 +02:00
|
|
|
componentDidMount() {
|
|
|
|
const elem = this.refs.video
|
|
|
|
const {
|
2017-05-17 23:52:45 +02:00
|
|
|
autoplay,
|
2017-04-23 11:56:50 +02:00
|
|
|
downloadPath,
|
|
|
|
contentType,
|
|
|
|
} = this.props
|
|
|
|
const players = plyr.setup(elem)
|
2017-05-17 23:52:45 +02:00
|
|
|
if (autoplay) {
|
|
|
|
players[0].play()
|
|
|
|
}
|
2017-04-23 11:56:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const {
|
|
|
|
downloadPath,
|
|
|
|
contentType,
|
2017-05-17 23:52:45 +02:00
|
|
|
poster,
|
2017-04-23 11:56:50 +02:00
|
|
|
} = this.props
|
|
|
|
|
|
|
|
return (
|
2017-05-17 23:52:45 +02:00
|
|
|
<video controls id="video" ref="video" style={{backgroundImage: "url('" + poster + "')"}} >
|
2017-05-18 19:58:28 +02:00
|
|
|
<source src={downloadPath} type={contentType} />
|
2017-04-23 11:56:50 +02:00
|
|
|
</video>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Video
|