Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var buffering = true,
- lastPlayPos,
- checkBufferIv = 50,
- element = document.createElement('video');
- element.src = "videosrc";
- element.setAttribute('webkit-playsinline', 'true');
- element.crossOrigin = "Anonymous";
- element.setAttribute('playsinline', 'true');
- element.addEventListener('canplaythrough',function(){
- buffering = false;
- setInterval(checkBuffering,checkBufferIv);
- });
- element.addEventListener('error', function(){}/*handles error*/);
- function checkBuffering() {
- // checking offset, e.g. 1 / 50ms = 0.02
- var offset = 1 / checkBufferIv
- // if no buffering is currently detected,
- // and the position does not seem to increase
- // and the player isn't manually paused...
- if (!buffering &&
- element.currentTime < (lastPlayPos + offset) &&
- Player.getState() === 2){
- buffering = true;
- }
- // if we were buffering but the player has advanced,
- // then there is no buffering
- if (buffering &&
- element.currentTime >= (lastPlayPos + offset)){
- buffering = false;
- }
- lastPlayPos = element.currentTime;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement