Skip to content

Instantly share code, notes, and snippets.

@303182519
Last active August 8, 2017 06:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 303182519/54dc0a5e8e61dd6dc675c88aa1c3e08e to your computer and use it in GitHub Desktop.
Save 303182519/54dc0a5e8e61dd6dc675c88aa1c3e08e to your computer and use it in GitHub Desktop.
播放器卡顿检测
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