mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-25 08:01:20 -08:00
添加监听视频卡顿的插件
This commit is contained in:
1 parent
cef60c4d9a
commit
05cbe4dad6
10 files changed
+149
-1
No files matched your search
@@ -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