How does Youtube's HTML5 video player control buffering?

前端 未结 4 533
小鲜肉
小鲜肉 2021-01-29 20:49

I was watching a youtube video and I decided to investigate some parts of its video player. I noticed that unlike most HTML5 video I have seen, Youtube\'s video player does not

相关标签:
4条回答
  • 2021-01-29 21:10

    When you look at the AppData of GoogleChrome, while playing a youtube video, you will see that it buffers in segmented files. The videos uploaded to youtube are segmented, which is why you can't perfectly pinpoint a timeframe in the first click on the bar if that timeframe is outside of the current segment.

    The amount of segments depends on the length of the video, and the time from which you start and stop playing back the video.

    When you are linked to a timeframe of a video, it will simply skip the buffering of the segments that come before that timeframe.

    Unfortunately I don't know much about the coding for video playback, but I hope this points you in the right direction.

    0 讨论(0)
  • 2021-01-29 21:12

    there is a canvas element in the page ,Maybe This Will Help http://html5doctor.com/video-canvas-magic/

    we knew the video is been segmented,the question is how to stitch them together.i think the real video element doesn't do the play work,it support the datasource,and draw the seagments each frame to the canvas element。

    var v = document.getElementById('v'); 
    var canvas = document.getElementById('c');
    v.addEventListener('play', function(){ 
       if(v.paused || v.ended) return false; 
       c.drawImage(v,0,0,w,h); 
       setTimeout(draw,20,v,c,w,h); 
    },false);
    

    0 讨论(0)
  • 2021-01-29 21:18

    Okay, so few things you need to know is that YouTube is based on this great open source Project. It behaves different for every browser and if your browser supports more intensive decoding like WEBM it will use that to save Google's bandwidth. Also if you look at this Demo Then you will find a section which downloads the entire video into a thing called "offline storage". I know chrome has it and some other browsers not every in some cases they do have to use the entire video source instead of a blob. So that blob is streaming depending on the user interaction with the video. Yes the video is just 1 file and they have metadata for that video like a little database that tells the time of the video and the points at which chunks can be divided in.

    You can find out more by reading the Project's documentation. I really recommend you have a look at the demo.

    0 讨论(0)
  • 2021-01-29 21:31

    Youtube is using this feature only in browsers that support Media Source Extensions so it is up to the browser decide about all the rest because of this feature.

    0 讨论(0)
提交回复
热议问题