Advertisement
Guest User

Untitled

a guest
Aug 26th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. var buffering = true,
  2. lastPlayPos,
  3. checkBufferIv = 50,
  4. element = document.createElement('video');
  5. element.src = "videosrc";
  6. element.setAttribute('webkit-playsinline', 'true');
  7. element.crossOrigin = "Anonymous";
  8. element.setAttribute('playsinline', 'true');
  9. element.addEventListener('canplaythrough',function(){
  10. buffering = false;
  11. setInterval(checkBuffering,checkBufferIv);
  12. });
  13. element.addEventListener('error', function(){}/*handles error*/);
  14.  
  15. function checkBuffering() {
  16. // checking offset, e.g. 1 / 50ms = 0.02
  17. var offset = 1 / checkBufferIv
  18.  
  19. // if no buffering is currently detected,
  20. // and the position does not seem to increase
  21. // and the player isn't manually paused...
  22. if (!buffering &&
  23. element.currentTime < (lastPlayPos + offset) &&
  24. Player.getState() === 2){
  25. buffering = true;
  26. }
  27.  
  28. // if we were buffering but the player has advanced,
  29. // then there is no buffering
  30. if (buffering &&
  31. element.currentTime >= (lastPlayPos + offset)){
  32. buffering = false;
  33. }
  34. lastPlayPos = element.currentTime;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement