Last active
August 8, 2017 06:31
-
-
Save 303182519/54dc0a5e8e61dd6dc675c88aa1c3e08e to your computer and use it in GitHub Desktop.
播放器卡顿检测
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var checkVideoBuffer = (function(){ | |
var timer = null; | |
var timerOut = null; | |
var timerNum = 2000; | |
function checkBufferIng(oParam){ | |
var checkInterval = 50; | |
var lastPlayPos = 0; | |
var currentPlayPos = 0; | |
var bufferingDetected = false; | |
var checkBuffer = function(){ | |
currentPlayPos = oParam.videoDom.currentTime; | |
var offset = (checkInterval - 20) / 1000; | |
if ( | |
!bufferingDetected | |
&& currentPlayPos < (lastPlayPos + offset) | |
&& !oParam.videoDom.paused | |
) { | |
console.log("缓冲中..."); | |
tafReport({ | |
sMetricName: 'wap.hls.buffer', | |
guid: oParam.guid, | |
auid: oParam.auid, | |
errorCode: 1 | |
}); | |
bufferingDetected = true; | |
} | |
if ( | |
bufferingDetected | |
&& currentPlayPos > (lastPlayPos + offset) | |
&& !oParam.videoDom.paused | |
) { | |
console.log("没有缓存了"); | |
bufferingDetected = false; | |
} | |
lastPlayPos = currentPlayPos; | |
} | |
timer && clearInterval(timer); | |
timer = setInterval(checkBuffer, checkInterval); | |
} | |
return function(oParam){ | |
console.log(timerNum/1000 + 'S之后才开始检测') | |
timerOut && clearTimeout(timerOut); | |
timerOut = setTimeout(function() { | |
console.log('开始检测') | |
checkBufferIng(oParam); | |
}, timerNum) | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment