add html5 video playback
This commit is contained in:
parent
c5da3de3c1
commit
1ab1684b2d
3 changed files with 23 additions and 10 deletions
|
@ -2,6 +2,10 @@ import React from 'react';
|
||||||
import lbry from '../lbry.js';
|
import lbry from '../lbry.js';
|
||||||
import LoadScreen from '../component/load_screen.js'
|
import LoadScreen from '../component/load_screen.js'
|
||||||
|
|
||||||
|
const fs = require('fs');
|
||||||
|
const VideoStream = require('videostream');
|
||||||
|
|
||||||
|
|
||||||
var WatchPage = React.createClass({
|
var WatchPage = React.createClass({
|
||||||
propTypes: {
|
propTypes: {
|
||||||
name: React.PropTypes.string,
|
name: React.PropTypes.string,
|
||||||
|
@ -22,6 +26,7 @@ var WatchPage = React.createClass({
|
||||||
lbry.getFileStatus(this.props.name, (status) => {
|
lbry.getFileStatus(this.props.name, (status) => {
|
||||||
if (!status || !['running', 'stopped'].includes(status.code) || status.written_bytes == 0) {
|
if (!status || !['running', 'stopped'].includes(status.code) || status.written_bytes == 0) {
|
||||||
// Download hasn't started yet, so update status message (if available) then try again
|
// Download hasn't started yet, so update status message (if available) then try again
|
||||||
|
// TODO: Would be nice to check if we have the MOOV before starting playing
|
||||||
if (status) {
|
if (status) {
|
||||||
this.setState({
|
this.setState({
|
||||||
loadStatusMessage: status.message
|
loadStatusMessage: status.message
|
||||||
|
@ -33,11 +38,17 @@ var WatchPage = React.createClass({
|
||||||
readyToPlay: true,
|
readyToPlay: true,
|
||||||
mimeType: status.mime_type,
|
mimeType: status.mime_type,
|
||||||
})
|
})
|
||||||
var player = new MediaElementPlayer(this.refs.player, {
|
const mediaFile = {
|
||||||
mode: 'shim',
|
createReadStream: function (opts) {
|
||||||
plugins: ['flash'],
|
// Return a readable stream that provides the bytes
|
||||||
setDimensions: false,
|
// between offsets "start" and "end" inclusive
|
||||||
});
|
console.log('Stream between ' + opts.start + ' and ' + opts.end + '.');
|
||||||
|
return fs.createReadStream(status.download_path, opts)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var elem = this.refs.video;
|
||||||
|
var videostream = VideoStream(mediaFile, elem);
|
||||||
|
elem.play();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -46,8 +57,7 @@ var WatchPage = React.createClass({
|
||||||
!this.state.readyToPlay
|
!this.state.readyToPlay
|
||||||
? <LoadScreen message={'Loading video...'} details={this.state.loadStatusMessage} />
|
? <LoadScreen message={'Loading video...'} details={this.state.loadStatusMessage} />
|
||||||
: <main className="full-screen">
|
: <main className="full-screen">
|
||||||
<video ref="player" width="100%" height="100%">
|
<video controls width="100%" height="100%" id="video" ref="video">
|
||||||
<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} />
|
|
||||||
</video>
|
</video>
|
||||||
</main>
|
</main>
|
||||||
);
|
);
|
||||||
|
|
|
@ -27,7 +27,8 @@
|
||||||
"node-sass": "^3.8.0",
|
"node-sass": "^3.8.0",
|
||||||
"react": "^15.4.0",
|
"react": "^15.4.0",
|
||||||
"react-dom": "^15.4.0",
|
"react-dom": "^15.4.0",
|
||||||
"react-modal": "^1.5.2"
|
"react-modal": "^1.5.2",
|
||||||
|
"videostream": "^2.4.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"babel": "^6.5.2",
|
"babel": "^6.5.2",
|
||||||
|
@ -45,6 +46,7 @@
|
||||||
"eslint-plugin-jsx-a11y": "^2.2.3",
|
"eslint-plugin-jsx-a11y": "^2.2.3",
|
||||||
"eslint-plugin-react": "^6.7.1",
|
"eslint-plugin-react": "^6.7.1",
|
||||||
"node-sass": "^3.13.0",
|
"node-sass": "^3.13.0",
|
||||||
"webpack": "^1.13.3"
|
"webpack": "^1.13.3",
|
||||||
|
"webpack-target-electron-renderer": "^0.4.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,5 +33,6 @@ module.exports = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
},
|
||||||
|
target: 'electron-main',
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue