2016-11-22 21:19:08 +01:00
|
|
|
import React from 'react';
|
|
|
|
import lbry from '../lbry.js';
|
2017-01-03 03:21:23 +01:00
|
|
|
import LoadScreen from '../component/load_screen.js'
|
|
|
|
|
2016-04-21 11:51:27 +02:00
|
|
|
var WatchPage = React.createClass({
|
|
|
|
propTypes: {
|
|
|
|
name: React.PropTypes.string,
|
|
|
|
},
|
2016-05-05 10:12:23 +02:00
|
|
|
getInitialState: function() {
|
|
|
|
return {
|
2016-05-05 12:55:15 +02:00
|
|
|
downloadStarted: false,
|
2016-05-05 10:12:23 +02:00
|
|
|
readyToPlay: false,
|
|
|
|
loadStatusMessage: "Requesting stream",
|
2016-06-03 12:05:14 +02:00
|
|
|
mimeType: null,
|
2016-05-05 10:12:23 +02:00
|
|
|
};
|
|
|
|
},
|
|
|
|
componentDidMount: function() {
|
|
|
|
lbry.getStream(this.props.name);
|
|
|
|
this.updateLoadStatus();
|
2016-05-05 14:10:19 +02:00
|
|
|
},
|
2016-05-05 10:12:23 +02:00
|
|
|
updateLoadStatus: function() {
|
|
|
|
lbry.getFileStatus(this.props.name, (status) => {
|
2017-02-16 06:19:10 +01:00
|
|
|
if (!status || !['running', 'stopped'].includes(status.code) || status.written_bytes == 0) {
|
2016-05-05 12:55:15 +02:00
|
|
|
// Download hasn't started yet, so update status message (if available) then try again
|
|
|
|
if (status) {
|
|
|
|
this.setState({
|
|
|
|
loadStatusMessage: status.message
|
|
|
|
});
|
|
|
|
}
|
2016-05-05 10:12:23 +02:00
|
|
|
setTimeout(() => { this.updateLoadStatus() }, 250);
|
|
|
|
} else {
|
|
|
|
this.setState({
|
2016-06-03 12:05:14 +02:00
|
|
|
readyToPlay: true,
|
|
|
|
mimeType: status.mime_type,
|
2016-05-13 13:46:39 +02:00
|
|
|
})
|
2016-06-06 10:51:29 +02:00
|
|
|
var player = new MediaElementPlayer(this.refs.player, {
|
2017-01-13 03:03:07 +01:00
|
|
|
mode: 'shim',
|
2016-09-28 11:42:38 +02:00
|
|
|
plugins: ['flash'],
|
2016-06-06 10:51:29 +02:00
|
|
|
setDimensions: false,
|
2016-06-03 12:05:14 +02:00
|
|
|
});
|
2016-05-05 10:12:23 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
2016-04-21 11:51:27 +02:00
|
|
|
render: function() {
|
2016-05-05 12:55:15 +02:00
|
|
|
return (
|
2016-09-21 07:37:43 +02:00
|
|
|
!this.state.readyToPlay
|
2016-09-24 21:27:07 +02:00
|
|
|
? <LoadScreen message={'Loading video...'} details={this.state.loadStatusMessage} />
|
2016-09-21 07:37:43 +02:00
|
|
|
: <main className="full-screen">
|
|
|
|
<video ref="player" width="100%" height="100%">
|
2016-12-06 20:58:51 +01:00
|
|
|
<source type={(this.state.mimeType == 'audio/m4a' || this.state.mimeType == 'audio/mp4a-latm') ? 'video/mp4' : this.state.mimeType} src={lbry.webUiUri + '/view?name=' + this.props.name} />
|
2016-09-21 07:37:43 +02:00
|
|
|
</video>
|
|
|
|
</main>
|
2016-05-05 12:55:15 +02:00
|
|
|
);
|
2016-04-21 11:51:27 +02:00
|
|
|
}
|
|
|
|
});
|
2016-11-22 21:19:08 +01:00
|
|
|
|
|
|
|
export default WatchPage;
|