Browse Source

new option: mutex, pause other players when this player start play

DIYgod 7 years ago
parent
commit
74eab49a8d
6 changed files with 14 additions and 2 deletions
  1. 1 0
      demo/index.html
  2. 0 0
      dist/DPlayer.min.js
  3. 0 0
      dist/DPlayer.min.js.map
  4. 1 1
      package.json
  5. 10 0
      src/DPlayer.js
  6. 2 1
      src/options.js

+ 1 - 0
demo/index.html

@@ -57,6 +57,7 @@
                 hotkey: true,
                 hotkey: true,
                 logo: 'http://devtest.qiniudn.com/DPlayer.png',
                 logo: 'http://devtest.qiniudn.com/DPlayer.png',
                 volume: 0.2,
                 volume: 0.2,
+                mutex: false,
                 video: {
                 video: {
                     url: 'http://devtest.qiniudn.com/若能绽放光芒.mp4',
                     url: 'http://devtest.qiniudn.com/若能绽放光芒.mp4',
                     pic: 'http://devtest.qiniudn.com/若能绽放光芒.png',
                     pic: 'http://devtest.qiniudn.com/若能绽放光芒.png',

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",
   "name": "dplayer",
-  "version": "1.14.1",
+  "version": "1.15.0",
   "description": "Wow, such a lovely HTML5 danmaku video player",
   "description": "Wow, such a lovely HTML5 danmaku video player",
   "main": "dist/DPlayer.min.js",
   "main": "dist/DPlayer.min.js",
   "style": "dist/DPlayer.min.css",
   "style": "dist/DPlayer.min.css",

+ 10 - 0
src/DPlayer.js

@@ -13,6 +13,7 @@ import User from './user';
 import Subtitle from './subtitle';
 import Subtitle from './subtitle';
 
 
 let index = 0;
 let index = 0;
+const instances = [];
 
 
 class DPlayer {
 class DPlayer {
 
 
@@ -788,6 +789,7 @@ class DPlayer {
         this.initVideo(this.video, this.quality && this.quality.type || this.options.video.type);
         this.initVideo(this.video, this.quality && this.quality.type || this.options.video.type);
 
 
         index++;
         index++;
+        instances.push(this);
     }
     }
 
 
     /**
     /**
@@ -832,6 +834,13 @@ class DPlayer {
         if (this.danmaku) {
         if (this.danmaku) {
             this.danmaku.play();
             this.danmaku.play();
         }
         }
+        if (this.options.mutex) {
+            for (let i = 0; i < instances.length; i++) {
+                if (this !== instances[i]) {
+                    instances[i].pause();
+                }
+            }
+        }
     }
     }
 
 
     /**
     /**
@@ -1167,6 +1176,7 @@ class DPlayer {
     }
     }
 
 
     destroy () {
     destroy () {
+        instances.splice(instances.indexOf(this), 1);
         this.pause();
         this.pause();
         clearTimeout(this.hideTime);
         clearTimeout(this.hideTime);
         this.video.src = '';
         this.video.src = '';

+ 2 - 1
src/options.js

@@ -88,7 +88,8 @@ module.exports = (options) => {
             ]
             ]
         },
         },
         iconsColor: '#ffffff',
         iconsColor: '#ffffff',
-        contextmenu: []
+        contextmenu: [],
+        mutex: true
     };
     };
     for (const defaultKey in defaultOption) {
     for (const defaultKey in defaultOption) {
         if (defaultOption.hasOwnProperty(defaultKey) && !options.hasOwnProperty(defaultKey)) {
         if (defaultOption.hasOwnProperty(defaultKey) && !options.hasOwnProperty(defaultKey)) {

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