From 183a98792189a3c600363d27b0e22ef61c230979 Mon Sep 17 00:00:00 2001 From: lqzhgood <9134671+lqzhgood@users.noreply.github.com> Date: Thu, 25 Jul 2019 15:45:21 +0800 Subject: [PATCH 1/7] =?UTF-8?q?=E6=9A=B4=E9=9C=B2=20Hls=20=E5=AE=9E?= =?UTF-8?q?=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://github.com/MoePlayer/DPlayer/issues/446 暴露 Hls 实例 用来绑定事件等操作 --- src/js/player.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/js/player.js b/src/js/player.js index ffafa40..f018524 100644 --- a/src/js/player.js +++ b/src/js/player.js @@ -344,8 +344,10 @@ class DPlayer { if (Hls) { if (Hls.isSupported()) { const hls = new Hls(); + this.hls = hls; hls.loadSource(video.src); - hls.attachMedia(video); + + .attachMedia(video); this.events.on('destroy', () => { hls.destroy(); }); From e5be8fad4dd9846ebf45bb4e6402945c8c36d31c Mon Sep 17 00:00:00 2001 From: lqzhgood <9134671+lqzhgood@users.noreply.github.com> Date: Thu, 25 Jul 2019 16:01:49 +0800 Subject: [PATCH 2/7] Update player.js --- src/js/player.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/js/player.js b/src/js/player.js index f018524..98c01b3 100644 --- a/src/js/player.js +++ b/src/js/player.js @@ -114,6 +114,7 @@ class DPlayer { } this.setting = new Setting(this); + this.plugins = {}; document.addEventListener('click', () => { this.focus = false; @@ -344,7 +345,7 @@ class DPlayer { if (Hls) { if (Hls.isSupported()) { const hls = new Hls(); - this.hls = hls; + this.plugins.Hls = hls; hls.loadSource(video.src); .attachMedia(video); From ba7ca3243911cfea8cd35122cfd7de52ed517e1e Mon Sep 17 00:00:00 2001 From: lqzhgood <9134671+lqzhgood@users.noreply.github.com> Date: Thu, 25 Jul 2019 16:03:37 +0800 Subject: [PATCH 3/7] Update player.js --- src/js/player.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/js/player.js b/src/js/player.js index 98c01b3..415159e 100644 --- a/src/js/player.js +++ b/src/js/player.js @@ -347,8 +347,7 @@ class DPlayer { const hls = new Hls(); this.plugins.Hls = hls; hls.loadSource(video.src); - - .attachMedia(video); + hls.attachMedia(video); this.events.on('destroy', () => { hls.destroy(); }); From e56e64ee41d74d2f92479f2d53bd56e5c5082b31 Mon Sep 17 00:00:00 2001 From: lqzhgood <9134671+lqzhgood@users.noreply.github.com> Date: Thu, 25 Jul 2019 16:22:54 +0800 Subject: [PATCH 4/7] =?UTF-8?q?=E6=8C=82=E8=BD=BD=204=E4=B8=AA=20=E6=8F=92?= =?UTF-8?q?=E4=BB=B6=E5=AE=9E=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/js/player.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/js/player.js b/src/js/player.js index 415159e..5b3205e 100644 --- a/src/js/player.js +++ b/src/js/player.js @@ -350,6 +350,7 @@ class DPlayer { hls.attachMedia(video); this.events.on('destroy', () => { hls.destroy(); + delete this.plugins.Hls; }); } else { @@ -369,12 +370,14 @@ class DPlayer { type: 'flv', url: video.src }); + this.plugins.flvjs = flvPlayer; flvPlayer.attachMediaElement(video); flvPlayer.load(); this.events.on('destroy', () => { flvPlayer.unload(); flvPlayer.detachMediaElement(); flvPlayer.destroy(); + delete this.plugins.flvjs; }); } else { @@ -389,9 +392,11 @@ class DPlayer { // https://github.com/Dash-Industry-Forum/dash.js case 'dash': if (dashjs) { - dashjs.MediaPlayer().create().initialize(video, video.src, false); + const dashjsPlayer = dashjs.MediaPlayer().create().initialize(video, video.src, false); + this.plugins.dash = dashjsPlayer; this.events.on('destroy', () => { dashjs.MediaPlayer().reset(); + delete this.plugins.dash; }); } else { @@ -401,10 +406,12 @@ class DPlayer { // https://github.com/webtorrent/webtorrent case 'webtorrent': - if (WebTorrent) { + if ( + ) { if (WebTorrent.WEBRTC_SUPPORT) { this.container.classList.add('dplayer-loading'); const client = new WebTorrent(); + this.plugins.webtorrent = client; const torrentId = video.src; client.add(torrentId, (torrent) => { const file = torrent.files.find((file) => file.name.endsWith('.mp4')); @@ -417,6 +424,7 @@ class DPlayer { this.events.on('destroy', () => { client.remove(torrentId); client.destroy(); + delete this.plugins.webtorrent; }); } else { From f95c7dce3eee60571ad65286c45dbac397858350 Mon Sep 17 00:00:00 2001 From: lqzh Date: Mon, 29 Jul 2019 11:51:25 +0800 Subject: [PATCH 5/7] add plugins options support --- src/js/options.js | 3 ++- src/js/player.js | 16 ++++++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/js/options.js b/src/js/options.js index 87da20d..e55d40d 100644 --- a/src/js/options.js +++ b/src/js/options.js @@ -18,7 +18,8 @@ export default (options) => { apiBackend: defaultApiBackend, video: {}, contextmenu: [], - mutex: true + mutex: true, + pluginsOption:{hls:{},flvjs:{},dash:{},webtorrent:{}} }; for (const defaultKey in defaultOption) { if (defaultOption.hasOwnProperty(defaultKey) && !options.hasOwnProperty(defaultKey)) { diff --git a/src/js/player.js b/src/js/player.js index 5b3205e..353a8d8 100644 --- a/src/js/player.js +++ b/src/js/player.js @@ -344,8 +344,9 @@ class DPlayer { case 'hls': if (Hls) { if (Hls.isSupported()) { - const hls = new Hls(); - this.plugins.Hls = hls; + const options = this.options.pluginsOption.hls; + const hls = new Hls(options); + this.plugins.hls = hls; hls.loadSource(video.src); hls.attachMedia(video); this.events.on('destroy', () => { @@ -366,10 +367,11 @@ class DPlayer { case 'flv': if (flvjs) { if (flvjs.isSupported()) { - const flvPlayer = flvjs.createPlayer({ + const options = Object.assign(this.options.pluginsOption.flvjs,{ type: 'flv', url: video.src }); + const flvPlayer = flvjs.createPlayer(options); this.plugins.flvjs = flvPlayer; flvPlayer.attachMediaElement(video); flvPlayer.load(); @@ -393,6 +395,8 @@ class DPlayer { case 'dash': if (dashjs) { const dashjsPlayer = dashjs.MediaPlayer().create().initialize(video, video.src, false); + const options = this.options.pluginsOption.dash; + dashjsPlayer.updateSettings(options); this.plugins.dash = dashjsPlayer; this.events.on('destroy', () => { dashjs.MediaPlayer().reset(); @@ -406,11 +410,11 @@ class DPlayer { // https://github.com/webtorrent/webtorrent case 'webtorrent': - if ( - ) { + if (WebTorrent) { if (WebTorrent.WEBRTC_SUPPORT) { this.container.classList.add('dplayer-loading'); - const client = new WebTorrent(); + const options = this.options.pluginsOption.webtorrent; + const client = new WebTorrent(options); this.plugins.webtorrent = client; const torrentId = video.src; client.add(torrentId, (torrent) => { From 8dc853de4e3ada7cd59e0b5c79e9a72fbe3770d9 Mon Sep 17 00:00:00 2001 From: lqzh Date: Mon, 29 Jul 2019 12:44:02 +0800 Subject: [PATCH 6/7] pluginsOption -> pluginOptions --- src/js/options.js | 2 +- src/js/player.js | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/js/options.js b/src/js/options.js index e55d40d..7da017a 100644 --- a/src/js/options.js +++ b/src/js/options.js @@ -19,7 +19,7 @@ export default (options) => { video: {}, contextmenu: [], mutex: true, - pluginsOption:{hls:{},flvjs:{},dash:{},webtorrent:{}} + pluginOptions:{hls:{},flvjs:{},dash:{},webtorrent:{}} }; for (const defaultKey in defaultOption) { if (defaultOption.hasOwnProperty(defaultKey) && !options.hasOwnProperty(defaultKey)) { diff --git a/src/js/player.js b/src/js/player.js index 353a8d8..c78b537 100644 --- a/src/js/player.js +++ b/src/js/player.js @@ -344,7 +344,7 @@ class DPlayer { case 'hls': if (Hls) { if (Hls.isSupported()) { - const options = this.options.pluginsOption.hls; + const options = this.options.pluginOptions.hls; const hls = new Hls(options); this.plugins.hls = hls; hls.loadSource(video.src); @@ -367,7 +367,7 @@ class DPlayer { case 'flv': if (flvjs) { if (flvjs.isSupported()) { - const options = Object.assign(this.options.pluginsOption.flvjs,{ + const options = Object.assign(this.options.pluginOptions.flvjs,{ type: 'flv', url: video.src }); @@ -395,7 +395,7 @@ class DPlayer { case 'dash': if (dashjs) { const dashjsPlayer = dashjs.MediaPlayer().create().initialize(video, video.src, false); - const options = this.options.pluginsOption.dash; + const options = this.options.pluginOptions.dash; dashjsPlayer.updateSettings(options); this.plugins.dash = dashjsPlayer; this.events.on('destroy', () => { @@ -413,7 +413,7 @@ class DPlayer { if (WebTorrent) { if (WebTorrent.WEBRTC_SUPPORT) { this.container.classList.add('dplayer-loading'); - const options = this.options.pluginsOption.webtorrent; + const options = this.options.pluginOptions.webtorrent; const client = new WebTorrent(options); this.plugins.webtorrent = client; const torrentId = video.src; From ea1bf3341751ba641c1caecf8d047ef30f665f0e Mon Sep 17 00:00:00 2001 From: lqzhgood <9134671+lqzhgood@users.noreply.github.com> Date: Mon, 29 Jul 2019 13:09:37 +0800 Subject: [PATCH 7/7] Update player.js --- src/js/player.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/js/player.js b/src/js/player.js index c78b537..701b9b6 100644 --- a/src/js/player.js +++ b/src/js/player.js @@ -351,7 +351,7 @@ class DPlayer { hls.attachMedia(video); this.events.on('destroy', () => { hls.destroy(); - delete this.plugins.Hls; + delete this.plugins.hls; }); } else {