|
@@ -323,26 +323,73 @@ class DPlayer {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // HTTP Live Streaming
|
|
|
- if (this.type === 'hls' && Hls && Hls.isSupported()) {
|
|
|
- const hls = new Hls();
|
|
|
- hls.loadSource(video.src);
|
|
|
- hls.attachMedia(video);
|
|
|
- }
|
|
|
-
|
|
|
- // FLV
|
|
|
- if (this.type === 'flv' && flvjs && flvjs.isSupported()) {
|
|
|
- const flvPlayer = flvjs.createPlayer({
|
|
|
- type: 'flv',
|
|
|
- url: video.src
|
|
|
- });
|
|
|
- flvPlayer.attachMediaElement(video);
|
|
|
- flvPlayer.load();
|
|
|
- }
|
|
|
+ switch (this.type) {
|
|
|
+ // https://github.com/video-dev/hls.js
|
|
|
+ case 'hls':
|
|
|
+ if (Hls) {
|
|
|
+ if (Hls.isSupported()) {
|
|
|
+ const hls = new Hls();
|
|
|
+ hls.loadSource(video.src);
|
|
|
+ hls.attachMedia(video);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ this.notice('Error: Hls is not supported.');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ this.notice('Error: Can\'t find Hls.');
|
|
|
+ }
|
|
|
+ break;
|
|
|
+
|
|
|
+ // https://github.com/Bilibili/flv.js
|
|
|
+ case 'flv':
|
|
|
+ if (flvjs && flvjs.isSupported()) {
|
|
|
+ if (flvjs.isSupported()) {
|
|
|
+ const flvPlayer = flvjs.createPlayer({
|
|
|
+ type: 'flv',
|
|
|
+ url: video.src
|
|
|
+ });
|
|
|
+ flvPlayer.attachMediaElement(video);
|
|
|
+ flvPlayer.load();
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ this.notice('Error: flvjs is not supported.');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ this.notice('Error: Can\'t find flvjs.');
|
|
|
+ }
|
|
|
+ break;
|
|
|
|
|
|
- // MPEG DASH
|
|
|
- if (this.type === 'dash' && dashjs) {
|
|
|
- dashjs.MediaPlayer().create().initialize(video, video.src, false);
|
|
|
+ // https://github.com/Dash-Industry-Forum/dash.js
|
|
|
+ case 'dash':
|
|
|
+ if (dashjs) {
|
|
|
+ dashjs.MediaPlayer().create().initialize(video, video.src, false);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ this.notice('Error: Can\'t find dashjs.');
|
|
|
+ }
|
|
|
+ break;
|
|
|
+
|
|
|
+ // https://github.com/webtorrent/webtorrent
|
|
|
+ case 'webtorrent':
|
|
|
+ if (WebTorrent) {
|
|
|
+ this.container.classList.add('dplayer-loading');
|
|
|
+ const client = new WebTorrent();
|
|
|
+ const torrentId = video.src;
|
|
|
+ client.add(torrentId, (torrent) => {
|
|
|
+ const file = torrent.files.find((file) => file.name.endsWith('.mp4'));
|
|
|
+ file.renderTo(this.video, {
|
|
|
+ autoplay: this.options.autoplay
|
|
|
+ }, () => {
|
|
|
+ this.container.classList.remove('dplayer-loading');
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ this.notice('Error: Can\'t find Webtorrent.');
|
|
|
+ }
|
|
|
+ break;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -367,7 +414,7 @@ class DPlayer {
|
|
|
|
|
|
// video download error: an error occurs
|
|
|
this.on('error', () => {
|
|
|
- this.tran && this.notice && this.notice(this.tran('This video fails to load'), -1);
|
|
|
+ this.tran && this.notice && this.type !== 'webtorrent' & this.notice(this.tran('This video fails to load'), -1);
|
|
|
});
|
|
|
|
|
|
// video end
|