Play more file types #185

Merged
6ea86b96 merged 4 commits from play-more-file-types into master 2017-06-02 14:56:22 +02:00
5 changed files with 38 additions and 14 deletions
Showing only changes of commit 8505959c22 - Show all commits

View file

@ -73,6 +73,8 @@ class FileActions extends React.Component {
let content let content
console.log(fileInfo)
if (downloading) { if (downloading) {
const const

View file

@ -13,7 +13,8 @@ import {
doLoadVideo, doLoadVideo,
} from 'actions/content' } from 'actions/content'
import { import {
makeSelectMetadataForUri makeSelectMetadataForUri,
makeSelectContentTypeForUri,
} from 'selectors/claims' } from 'selectors/claims'
import { import {
makeSelectFileInfoForUri, makeSelectFileInfoForUri,
@ -32,6 +33,7 @@ const makeSelect = () => {
const selectIsLoading = makeSelectLoadingForUri() const selectIsLoading = makeSelectLoadingForUri()
const selectIsDownloading = makeSelectDownloadingForUri() const selectIsDownloading = makeSelectDownloadingForUri()
const selectMetadata = makeSelectMetadataForUri() const selectMetadata = makeSelectMetadataForUri()
const selectContentType = makeSelectContentTypeForUri()
const select = (state, props) => ({ const select = (state, props) => ({
costInfo: selectCostInfo(state, props), costInfo: selectCostInfo(state, props),
@ -40,6 +42,7 @@ const makeSelect = () => {
modal: selectCurrentModal(state), modal: selectCurrentModal(state),
isLoading: selectIsLoading(state, props), isLoading: selectIsLoading(state, props),
isDownloading: selectIsDownloading(state, props), isDownloading: selectIsDownloading(state, props),
contentType: selectContentType(state, props),
}) })
return select return select

View file

@ -2,6 +2,10 @@ import React from 'react';
import FilePrice from 'component/filePrice' import FilePrice from 'component/filePrice'
import Link from 'component/link'; import Link from 'component/link';
import Modal from 'component/modal'; import Modal from 'component/modal';
import lbry from 'lbry'
import {
Thumbnail,
} from 'component/common'
class VideoPlayButton extends React.Component { class VideoPlayButton extends React.Component {
onPurchaseConfirmed() { onPurchaseConfirmed() {
@ -33,6 +37,7 @@ class VideoPlayButton extends React.Component {
isLoading, isLoading,
costInfo, costInfo,
fileInfo, fileInfo,
mediaType,
} = this.props } = this.props
/* /*
@ -44,13 +49,14 @@ class VideoPlayButton extends React.Component {
*/ */
const disabled = isLoading || fileInfo === undefined || (fileInfo === null && (!costInfo || costInfo.cost === undefined)) const disabled = isLoading || fileInfo === undefined || (fileInfo === null && (!costInfo || costInfo.cost === undefined))
const icon = mediaType == "image" ? "icon-folder-o" : "icon-play"
return (<div> return (<div>
<Link button={ button ? button : null } <Link button={ button ? button : null }
disabled={disabled} disabled={disabled}
label={label ? label : ""} label={label ? label : ""}
className="video__play-button" className="video__play-button"
icon="icon-play" icon={icon}
onClick={this.onWatchClick.bind(this)} /> onClick={this.onWatchClick.bind(this)} />
<Modal contentLabel="Not enough credits" isOpen={modal == 'notEnoughCredits'} onConfirmed={closeModal}> <Modal contentLabel="Not enough credits" isOpen={modal == 'notEnoughCredits'} onConfirmed={closeModal}>
You don't have enough LBRY credits to pay for this stream. You don't have enough LBRY credits to pay for this stream.
@ -89,12 +95,14 @@ class Video extends React.Component {
isLoading, isLoading,
isDownloading, isDownloading,
fileInfo, fileInfo,
contentType,
} = this.props } = this.props
const { const {
isPlaying = false, isPlaying = false,
} = this.state } = this.state
const isReadyToPlay = fileInfo && fileInfo.written_bytes > 0 const isReadyToPlay = fileInfo && fileInfo.written_bytes > 0
const mediaType = lbry.getMediaType(contentType, fileInfo && fileInfo.file_name)
let loadStatusMessage = '' let loadStatusMessage = ''
@ -106,14 +114,24 @@ class Video extends React.Component {
loadStatusMessage = "Downloading stream... not long left now!" loadStatusMessage = "Downloading stream... not long left now!"
} }
let klassName = ""
if (isLoading || isDownloading) klassName += "video-embedded video"
if (mediaType === "video") {
klassName += "video-embedded video"
klassName += isPlaying ? " video--active" : " video--hidden"
} else {
if (!isPlaying) klassName += "video-embedded"
}
const poster = metadata.thumbnail
return ( return (
<div className={"video " + this.props.className + (isPlaying ? " video--active" : " video--hidden")}>{ <div className={klassName}>{
isPlaying || isLoading ? isPlaying || isLoading ?
(!isReadyToPlay ? (!isReadyToPlay ?
<span>this is the world's worst loading screen and we shipped our software with it anyway... <br /><br />{loadStatusMessage}</span> : <span>this is the world's worst loading screen and we shipped our software with it anyway... <br /><br />{loadStatusMessage}</span> :
<VideoPlayer filename={fileInfo.file_name} poster={metadata.thumbnail} downloadPath={fileInfo.download_path} />) : <VideoPlayer filename={fileInfo.file_name} poster={poster} downloadPath={fileInfo.download_path} mediaType={mediaType} poster={poster} />) :
<div className="video__cover" style={{backgroundImage: 'url("' + metadata.thumbnail + '")'}}> <div className="video__cover" style={{backgroundImage: 'url("' + metadata.thumbnail + '")'}}>
<VideoPlayButton startPlaying={this.startPlaying.bind(this)} {...this.props} /> <VideoPlayButton startPlaying={this.startPlaying.bind(this)} {...this.props} mediaType={mediaType} />
</div> </div>
}</div> }</div>
); );
@ -126,10 +144,9 @@ const fs = require('fs')
class VideoPlayer extends React.Component { class VideoPlayer extends React.Component {
componentDidMount() { componentDidMount() {
const elem = this.refs.video const elem = this.refs.media
const { const {
downloadPath, downloadPath,
contentType,
filename, filename,
} = this.props } = this.props
const file = { const file = {
@ -138,7 +155,7 @@ class VideoPlayer extends React.Component {
return fs.createReadStream(downloadPath, opts) return fs.createReadStream(downloadPath, opts)
} }
} }
player.render(file, elem, { player.append(file, elem, {
autoplay: true, autoplay: true,
controls: true, controls: true,
}) })
@ -147,14 +164,15 @@ class VideoPlayer extends React.Component {
render() { render() {
const { const {
downloadPath, downloadPath,
contentType, mediaType,
poster, poster,
} = this.props } = this.props
return ( return (
<video controls ref="video" style={{backgroundImage: "url('" + poster + "')"}} > <div>
<source src={downloadPath} type={contentType} /> {mediaType === "audio" && <Thumbnail src={poster} className="video-embedded" />}
</video> <div ref="media" />
</div>
) )
} }
} }

View file

@ -286,7 +286,7 @@ lbry.imagePath = function(file)
lbry.getMediaType = function(contentType, fileName) { lbry.getMediaType = function(contentType, fileName) {
if (contentType) { if (contentType) {
return /^[^/]+/.exec(contentType); return /^[^/]+/.exec(contentType)[0];
} else if (fileName) { } else if (fileName) {
var dotIndex = fileName.lastIndexOf('.'); var dotIndex = fileName.lastIndexOf('.');
if (dotIndex == -1) { if (dotIndex == -1) {

View file

@ -92,11 +92,12 @@ class FilePage extends React.Component{
const channelClaimId = claim.value && claim.value.publisherSignature ? claim.value.publisherSignature.certificateId : null; const channelClaimId = claim.value && claim.value.publisherSignature ? claim.value.publisherSignature.certificateId : null;
const channelUri = signatureIsValid && hasSignature && channelName ? lbryuri.build({channelName, claimId: channelClaimId}, false) : null const channelUri = signatureIsValid && hasSignature && channelName ? lbryuri.build({channelName, claimId: channelClaimId}, false) : null
const uriIndicator = <UriIndicator uri={uri} /> const uriIndicator = <UriIndicator uri={uri} />
const mediaType = lbry.getMediaType(contentType)
return ( return (
<main className="main--single-column"> <main className="main--single-column">
<section className="show-page-media"> <section className="show-page-media">
{ contentType && contentType.startsWith('video/') ? { ["video", "audio", "image"].indexOf(mediaType) !== -1 ?
<Video className="video-embedded" uri={uri} /> : <Video className="video-embedded" uri={uri} /> :
(metadata && metadata.thumbnail ? <Thumbnail src={metadata.thumbnail} /> : <Thumbnail />) } (metadata && metadata.thumbnail ? <Thumbnail src={metadata.thumbnail} /> : <Thumbnail />) }
</section> </section>