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

This commit is contained in:
DIYgod
2017-09-24 06:52:02 +08:00
parent 3d5ea2c68a
commit 74eab49a8d
6 changed files with 16 additions and 4 deletions
+1
View File
@@ -57,6 +57,7 @@
hotkey: true,
logo: 'http://devtest.qiniudn.com/DPlayer.png',
volume: 0.2,
mutex: false,
video: {
url: 'http://devtest.qiniudn.com/若能绽放光芒.mp4',
pic: 'http://devtest.qiniudn.com/若能绽放光芒.png',
+1 -1
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "dplayer",
"version": "1.14.1",
"version": "1.15.0",
"description": "Wow, such a lovely HTML5 danmaku video player",
"main": "dist/DPlayer.min.js",
"style": "dist/DPlayer.min.css",
+10
View File
@@ -13,6 +13,7 @@ import User from './user';
import Subtitle from './subtitle';
let index = 0;
const instances = [];
class DPlayer {
@@ -788,6 +789,7 @@ class DPlayer {
this.initVideo(this.video, this.quality && this.quality.type || this.options.video.type);
index++;
instances.push(this);
}
/**
@@ -832,6 +834,13 @@ class DPlayer {
if (this.danmaku) {
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 () {
instances.splice(instances.indexOf(this), 1);
this.pause();
clearTimeout(this.hideTime);
this.video.src = '';
+2 -1
View File
@@ -88,7 +88,8 @@ module.exports = (options) => {
]
},
iconsColor: '#ffffff',
contextmenu: []
contextmenu: [],
mutex: true
};
for (const defaultKey in defaultOption) {
if (defaultOption.hasOwnProperty(defaultKey) && !options.hasOwnProperty(defaultKey)) {