If we wanted to make an HTTP/1.0
or HTTP/1.1
request, for example bytes 20000 to 100000 or seconds 20 through 35 seconds of a given media resource for example, .webm
or .ogg
audio or .mp4
video, where the response would be a discrete media fragment capable of playback without other portions of the media resource, how would we achieve this?
For example
let headers = new Headers();
let range = 1024 * 1024;
headers.append("Range", "bytes=0-" + range);
let request = new Request(url, {headers:headers});
fetch(request)
.then(response => response.blob())
.then(data => audio.src = URL.createObjectURL(data));
loads and media plays
let headers = new Headers();
let range = 1024 * 1024;
headers.append("Range", "bytes=" + range + "-" + range * 2);
let request = new Request(url, {headers:headers});
fetch(request)
.then(response => response.blob())
.then(data => audio.src = URL.createObjectURL(data));
logs successful 200
and 206
response statuses, though does not render media playback at <audio>
element.
How to create a range request for a given media, which returns only the requested range of the resource as a discrete resource capable of playback without other portions of the media, where requested media fragment can be any discrete portion of the media resource?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…