From c74629f5d31e7890aa8fab9712346766e383fae0 Mon Sep 17 00:00:00 2001 From: Alex Liebowitz Date: Thu, 5 May 2016 06:55:15 -0400 Subject: [PATCH] Pre-render video hidden, then launch when it reports it can play --- js/page/watch.js | 47 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 15 deletions(-) diff --git a/js/page/watch.js b/js/page/watch.js index e9cc05ed6..ed77944d0 100644 --- a/js/page/watch.js +++ b/js/page/watch.js @@ -10,6 +10,7 @@ var WatchPage = React.createClass({ }, getInitialState: function() { return { + downloadStarted: false, readyToPlay: false, loadStatusMessage: "Requesting stream", }; @@ -18,32 +19,48 @@ var WatchPage = React.createClass({ lbry.getStream(this.props.name); this.updateLoadStatus(); }, + onCanPlay: function() { + this.setState({ + readyToPlay: true + }); + }, updateLoadStatus: function() { lbry.getFileStatus(this.props.name, (status) => { - if (status.code != 'running') { - this.loadStatusMessage = status.message; + if (!status || status.code != 'running' || status.written_bytes == 0) { + // Download hasn't started yet, so update status message (if available) then try again + if (status) { + this.setState({ + loadStatusMessage: status.message + }); + } setTimeout(() => { this.updateLoadStatus() }, 250); } else { this.setState({ - readyToPlay: true + loadStatusMessage: "Buffering", + downloadStarted: true, }); } }); }, render: function() { - if (!this.state.readyToPlay) { - return ( -
-

Loading lbry://{this.props.name}

- {this.state.loadStatusMessage} -
- ); + if (!this.state.downloadStarted) { + var video = null; } else { - return ( -
-
- ); + // If the download has started, render the