video + webapi (一)

HTML5视频通过将metadata置于文件开头实现部分加载播放。Web服务器的范围请求(range request)允许按需下载视频片段,实现渐进式加载和快进。在ASP.NET中,IIS原生支持范围请求,但ASPX页面需手动处理。WebAPI的StreamContent可用于处理范围请求,返回状态码206表示部分内容。
摘要由CSDN通过智能技术生成

引自: HTML5 video标签播放视频下载原理

HTML5 video does not work like streaming technologies or Flash. So how does the browser manage to play a long video without downloading the whole file before playing it? Part of the trick is that the video is encoded in such a way that the metadata is at the top of the file. This means once the first chunk of data is returned it is enough to determine whether the browser can play it all the way through. If you are encoding video for use with the video element, you will want to choose the Web optimized option in the encoding software. (See the section on video encoding above.)

video 的metadata 被放到了文件头部,这样可以不用加载整个文件就能判断出浏览器是否播放这个video。

The real trick though is how Web servers allow you to only download the a part of a file you request. The browser requests a chunk of the video at a time which allows HTML5 video to give the appearance of streaming. This behavior of mimicking streaming is called progressive download. This also allows fast seeking through the video by clicking the time rail on an unbuffered portion of the video. In general, requesting just a chunk of a file from a Web server is called a range request or “byte serving.

真正的原因应该是服务器允许每次请求下载文件的一部分。这种被称为“progressive download” 或者 “range request”


引自:mdn: HTTP range requests

If the Accept-Ranges is present in HTTP responses (and its value isn't "none"), the server supports range requests. You can check this by issuing a HEAD request and cURL, for example.
curl -I http://i.imgur.com/z4d4kWk.jpg

HTTP/1.1 200 OK
...
Accept-Ranges: bytes
Content-Length: 146515
In this response, Accept-Ranges: bytes indicates
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值