Browse Source

MSE in switchVideo

DIYgod 7 years ago
parent
commit
38c10cbd5a
5 changed files with 12 additions and 8 deletions
  1. 4 5
      demo/index.html
  2. 0 0
      dist/DPlayer.min.js
  3. 0 0
      dist/DPlayer.min.js.map
  4. 1 1
      package.json
  5. 7 2
      src/DPlayer.js

+ 4 - 5
demo/index.html

@@ -75,11 +75,10 @@
                 ]
             });
             function switchDPlayer() {
-                if (dp2.option.danmaku.id !== '5rGf5Y2X55qu6Z2p') {
+                if (dp2.danmaku.options.api.id !== '5rGf5Y2X55qu6Z2p') {
                     dp2.switchVideo({
-                        url: 'http://devtest.qiniudn.com/微小微-江南皮革厂倒闭了.mp4',
-                        pic: 'http://devtest.qiniudn.com/微小微-江南皮革厂倒闭了.jpg',
-                        type: 'auto',
+                        url: 'http://devtest.qiniudn.com/若能绽放光芒5.m3u8',
+                        type: 'hls'
                     },
                         {
                             id: '5rGf5Y2X55qu6Z2p',
@@ -95,7 +94,7 @@
                         type: 'auto',
                     },
                         {
-                            id: '9E2E3368B56CDBB42',
+                            id: '9E2E3368B56CDBB4',
                             api: 'https://api.prprpr.me/dplayer/',
                             maximum: 3000,
                             user: 'DIYgod'

File diff suppressed because it is too large
+ 0 - 0
dist/DPlayer.min.js


File diff suppressed because it is too large
+ 0 - 0
dist/DPlayer.min.js.map


+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
   "name": "dplayer",
-  "version": "1.8.0",
+  "version": "1.8.1",
   "description": "Wow, such a lovely HTML5 danmaku video player",
   "main": "dist/DPlayer.min.js",
   "style": "dist/DPlayer.min.css",

+ 7 - 2
src/DPlayer.js

@@ -920,9 +920,10 @@ class DPlayer {
      * @param {Object} danmaku - new danmaku info
      */
     switchVideo (video, danmakuAPI) {
+        this.pause();
         this.video.poster = video.pic ? video.pic : '';
         this.video.src = video.url;
-        this.pause();
+        this.initMSE(this.video, video.type || 'auto');
         if (danmakuAPI) {
             this.element.getElementsByClassName('dplayer-danloading')[0].style.display = 'block';
             this.updateBar('played', 0, 'width');
@@ -942,7 +943,7 @@ class DPlayer {
         }
     }
 
-    initVideo (video, type) {
+    initMSE (video, type) {
         this.type = type;
         if (this.type === 'auto') {
             if (/m3u8(#|\?|$)/i.exec(video.src)) {
@@ -973,6 +974,10 @@ class DPlayer {
             flvPlayer.attachMediaElement(video);
             flvPlayer.load();
         }
+    }
+
+    initVideo (video, type) {
+        this.initMSE(video, type);
 
         /**
          * video events

Some files were not shown because too many files changed in this diff