mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-16 17:46:17 -08:00
update
This commit is contained in:
1 parent
396026f533
commit
f4d3c77c6c
4 files changed
+4
-145
No files matched your search
@@ -3,8 +3,6 @@ import subtitleOffset from './subtitleOffset';
|
||||
import localVideo from './localVideo';
|
||||
import localSubtitle from './localSubtitle';
|
||||
import miniProgressBar from './miniProgressBar';
|
||||
import networkMonitor from './networkMonitor';
|
||||
import log from './log';
|
||||
|
||||
export default class Plugins {
|
||||
constructor(art) {
|
||||
@@ -29,14 +27,6 @@ export default class Plugins {
|
||||
this.add(localSubtitle);
|
||||
}
|
||||
|
||||
if (option.networkMonitor) {
|
||||
this.add(networkMonitor);
|
||||
}
|
||||
|
||||
if (option.log) {
|
||||
this.add(log);
|
||||
}
|
||||
|
||||
art.option.plugins.forEach((plugin) => {
|
||||
this.add(plugin);
|
||||
});
|
||||
|
||||
@@ -1,51 +0,0 @@
|
||||
import { append, setStyle, remove, escape } from '../utils';
|
||||
|
||||
export default function log(art) {
|
||||
const { layers } = art;
|
||||
|
||||
let $log = null;
|
||||
layers.add({
|
||||
name: 'log',
|
||||
style: {
|
||||
bottom: '50px',
|
||||
},
|
||||
mounted($el) {
|
||||
$log = $el;
|
||||
},
|
||||
});
|
||||
|
||||
let timer = null;
|
||||
const max = 5;
|
||||
const timeout = 3000;
|
||||
|
||||
function check() {
|
||||
const count = $log.childElementCount;
|
||||
setStyle($log, 'bottom', art.controls.show ? '50px' : '10px');
|
||||
if (count) {
|
||||
if (count > max) {
|
||||
remove($log.firstElementChild);
|
||||
timer = setTimeout(check, timeout);
|
||||
} else {
|
||||
timer = setTimeout(() => {
|
||||
remove($log.firstElementChild);
|
||||
check();
|
||||
}, timeout);
|
||||
}
|
||||
} else {
|
||||
setStyle($log, 'display', 'none');
|
||||
}
|
||||
}
|
||||
|
||||
art.on('destroy', () => clearTimeout(timer));
|
||||
|
||||
return {
|
||||
name: 'log',
|
||||
emit(msg) {
|
||||
if (typeof msg !== 'string') return;
|
||||
append($log, `<p>${escape(msg)}</p>`);
|
||||
setStyle($log, 'display', 'block');
|
||||
clearTimeout(timer);
|
||||
check();
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
export default function networkMonitor(art) {
|
||||
let sampleTime = 10000;
|
||||
let waitTime = 0;
|
||||
let playTime = 0;
|
||||
let lastTime = 0;
|
||||
let timer = null;
|
||||
|
||||
function resetTime() {
|
||||
waitTime = 0;
|
||||
playTime = 0;
|
||||
lastTime = 0;
|
||||
cancelAnimationFrame(timer);
|
||||
timer = null;
|
||||
}
|
||||
|
||||
function startTime() {
|
||||
if (timer) return;
|
||||
(function loop() {
|
||||
if (art.isDestroy) return;
|
||||
timer = requestAnimationFrame(() => {
|
||||
const nowTime = Date.now();
|
||||
if (lastTime) {
|
||||
const diffTime = nowTime - lastTime;
|
||||
playTime += diffTime;
|
||||
if (!art.player.playing) {
|
||||
waitTime += diffTime;
|
||||
}
|
||||
}
|
||||
lastTime = nowTime;
|
||||
art.emit('networkMonitor', waitTime / playTime);
|
||||
if (playTime >= sampleTime) {
|
||||
waitTime = 0;
|
||||
playTime = 0;
|
||||
}
|
||||
loop();
|
||||
});
|
||||
})();
|
||||
}
|
||||
|
||||
art.on('play', startTime);
|
||||
art.on('pause', resetTime);
|
||||
|
||||
return {
|
||||
name: 'networkMonitor',
|
||||
reset: resetTime,
|
||||
start: startTime,
|
||||
sample: time => {
|
||||
sampleTime = time;
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user