浏览代码

Merge pull request #533 from Copay/master

Fix #531
DIYgod 5 年之前
父节点
当前提交
3eea68f2c3
共有 7 个文件被更改,包括 7 次插入6 次删除
  1. 1 1
      .eslintrc
  2. 0 0
      dist/DPlayer.min.css
  3. 0 0
      dist/DPlayer.min.css.map
  4. 0 0
      dist/DPlayer.min.js
  5. 0 0
      dist/DPlayer.min.js.map
  6. 5 4
      src/js/player.js
  7. 1 1
      src/js/subtitle.js

+ 1 - 1
.eslintrc

@@ -1,7 +1,7 @@
 {
     "extends": "eslint:recommended",
     "parserOptions": {
-        "ecmaVersion": 6,
+        "ecmaVersion": 10,
         "sourceType": "module"
     },
     "env": {

文件差异内容过多而无法显示
+ 0 - 0
dist/DPlayer.min.css


文件差异内容过多而无法显示
+ 0 - 0
dist/DPlayer.min.css.map


文件差异内容过多而无法显示
+ 0 - 0
dist/DPlayer.min.js


文件差异内容过多而无法显示
+ 0 - 0
dist/DPlayer.min.js.map


+ 5 - 4
src/js/player.js

@@ -33,7 +33,7 @@ class DPlayer {
      * @constructor
      */
     constructor (options) {
-        this.options = handleOption(options);
+        this.options = handleOption({preload:options.video.type === 'webtorrent' ? 'none' : 'metadata', ...options});
 
         if (this.options.video.quality) {
             this.qualityIndex = this.options.video.defaultQuality;
@@ -404,12 +404,13 @@ class DPlayer {
                         this.container.classList.add('dplayer-loading');
                         const client = new WebTorrent();
                         const torrentId = video.src;
+                        video.src = '';
+                        video.preload = 'metadata';
+                        video.addEventListener('durationchange', () => this.container.classList.remove('dplayer-loading'), {once: true});
                         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');
                             });
                         });
                         this.events.on('destroy', () => {
@@ -455,7 +456,7 @@ class DPlayer {
                 // Not a video load error, may be poster load failed, see #307
                 return;
             }
-            this.tran && this.notice && this.type !== 'webtorrent' & this.notice(this.tran('Video load failed'), -1);
+            this.tran && this.notice && this.type !== 'webtorrent' && this.notice(this.tran('Video load failed'), -1);
         });
 
         // video end

+ 1 - 1
src/js/subtitle.js

@@ -22,7 +22,7 @@ class Subtitle {
                 if (cue) {
                     const template = document.createElement('div');
                     template.appendChild(cue.getCueAsHTML());
-                    const trackHtml = template.innerHTML.split(/\r?\n/).map(item => `<p>${item}</p>`).join('');
+                    const trackHtml = template.innerHTML.split(/\r?\n/).map((item) => `<p>${item}</p>`).join('');
                     this.container.innerHTML = trackHtml;
                 }
                 this.events.trigger('subtitle_change');

部分文件因为文件数量过多而无法显示