mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-27 01:21:20 -08:00
添加监听视频卡顿的插件
This commit is contained in:
1 parent
cef60c4d9a
commit
05cbe4dad6
10 files changed
+149
-1
No files matched your search
@@ -11,4 +11,8 @@ export default function autoPip(art) {
|
||||
}
|
||||
}, 300);
|
||||
events.proxy(window, 'scroll', scrollDebounce);
|
||||
|
||||
return {
|
||||
name: 'autoPip',
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ import { errorHandle, hasOwnProperty } from '../utils';
|
||||
import subtitleOffset from './subtitleOffset';
|
||||
import localPreview from './localPreview';
|
||||
import miniProgressBar from './miniProgressBar';
|
||||
import networkMonitor from './networkMonitor';
|
||||
import autoPip from './autoPip';
|
||||
|
||||
export default class Plugins {
|
||||
@@ -23,6 +24,10 @@ export default class Plugins {
|
||||
this.add(localPreview);
|
||||
}
|
||||
|
||||
if (option.networkMonitor) {
|
||||
this.add(networkMonitor);
|
||||
}
|
||||
|
||||
if (option.autoPip) {
|
||||
this.add(autoPip);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
export default function networkMonitor(art) {
|
||||
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 calculatingTime() {
|
||||
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);
|
||||
loop();
|
||||
});
|
||||
})();
|
||||
}
|
||||
|
||||
art.on('play', calculatingTime);
|
||||
art.on('pause', resetTime);
|
||||
|
||||
return {
|
||||
name: 'networkMonitor',
|
||||
reset: resetTime,
|
||||
calculating: calculatingTime,
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user