2017-06-07 07:36:12 +02:00
|
|
|
import React from "react";
|
|
|
|
import FilePrice from "component/filePrice";
|
|
|
|
import Link from "component/link";
|
2017-08-18 19:09:40 +02:00
|
|
|
import Modal from "modal/modal";
|
2017-06-07 07:36:12 +02:00
|
|
|
|
2017-06-09 01:41:44 +02:00
|
|
|
class VideoPlayButton extends React.PureComponent {
|
2017-07-01 22:48:12 +02:00
|
|
|
componentDidMount() {
|
2017-07-01 23:57:14 +02:00
|
|
|
this.keyDownListener = this.onKeyDown.bind(this);
|
|
|
|
document.addEventListener("keydown", this.keyDownListener);
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
document.removeEventListener("keydown", this.keyDownListener);
|
2017-07-01 22:48:12 +02:00
|
|
|
}
|
|
|
|
|
2017-06-07 07:36:12 +02:00
|
|
|
onPurchaseConfirmed() {
|
|
|
|
this.props.closeModal();
|
|
|
|
this.props.startPlaying();
|
|
|
|
this.props.loadVideo(this.props.uri);
|
|
|
|
}
|
|
|
|
|
2017-07-01 22:48:12 +02:00
|
|
|
onKeyDown(event) {
|
2017-07-02 20:33:07 +02:00
|
|
|
if (
|
|
|
|
"input" !== event.target.tagName.toLowerCase() &&
|
|
|
|
"Space" === event.code
|
|
|
|
) {
|
2017-07-01 22:48:12 +02:00
|
|
|
event.preventDefault();
|
|
|
|
this.onWatchClick();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-07 07:36:12 +02:00
|
|
|
onWatchClick() {
|
|
|
|
this.props.purchaseUri(this.props.uri).then(() => {
|
|
|
|
if (!this.props.modal) {
|
|
|
|
this.props.startPlaying();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const {
|
|
|
|
button,
|
|
|
|
label,
|
|
|
|
metadata,
|
|
|
|
metadata: { title },
|
|
|
|
uri,
|
|
|
|
modal,
|
|
|
|
closeModal,
|
|
|
|
isLoading,
|
|
|
|
fileInfo,
|
|
|
|
mediaType,
|
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
/*
|
|
|
|
title={
|
|
|
|
isLoading ? "Video is Loading" :
|
|
|
|
!costInfo ? "Waiting on cost info..." :
|
|
|
|
fileInfo === undefined ? "Waiting on file info..." : ""
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
|
2017-07-30 21:57:22 +02:00
|
|
|
const disabled = isLoading || fileInfo === undefined;
|
2017-07-01 23:57:14 +02:00
|
|
|
const icon = ["audio", "video"].indexOf(mediaType) !== -1
|
|
|
|
? "icon-play"
|
|
|
|
: "icon-folder-o";
|
2017-06-07 07:36:12 +02:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<Link
|
|
|
|
button={button ? button : null}
|
|
|
|
disabled={disabled}
|
|
|
|
label={label ? label : ""}
|
|
|
|
className="video__play-button"
|
|
|
|
icon={icon}
|
|
|
|
onClick={this.onWatchClick.bind(this)}
|
|
|
|
/>
|
|
|
|
<Modal
|
|
|
|
type="confirm"
|
|
|
|
isOpen={modal == "affirmPurchaseAndPlay"}
|
|
|
|
contentLabel={__("Confirm Purchase")}
|
|
|
|
onConfirmed={this.onPurchaseConfirmed.bind(this)}
|
|
|
|
onAborted={closeModal}
|
|
|
|
>
|
2017-07-01 22:48:12 +02:00
|
|
|
{__("This will purchase")} <strong>{title}</strong> {__("for")}{" "}
|
|
|
|
<strong>
|
2017-08-23 02:59:36 +02:00
|
|
|
<FilePrice uri={uri} showFullPrice={true} look="plain" />
|
2017-07-01 22:48:12 +02:00
|
|
|
</strong>{" "}
|
|
|
|
{__("credits")}.
|
2017-06-07 07:36:12 +02:00
|
|
|
</Modal>
|
|
|
|
<Modal
|
|
|
|
isOpen={modal == "timedOut"}
|
|
|
|
onConfirmed={closeModal}
|
|
|
|
contentLabel={__("Timed Out")}
|
|
|
|
>
|
|
|
|
{__("Sorry, your download timed out :(")}
|
|
|
|
</Modal>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default VideoPlayButton;
|