Public
Edited
Dec 26, 2022
9 stars
Insert cell
Insert cell
video = html`<video controls src="${bbb}"/>`
Insert cell
Insert cell
Insert cell
fetch(bbb) // 🌶
Insert cell
Insert cell
fetch(
'https://ia600301.us.archive.org/7/items/BigBuckBunnyProjectile/big_buck_bunny_projectile_512kb.mp4'
) // 🌶
Insert cell
Insert cell
canvas = {
await ready(video, invalidation); // to be sure the video is ready to provide a frame
const canvas = DOM.canvas(video.videoWidth, video.videoHeight);
canvas.getContext('2d').drawImage(video, 0, 0);
return canvas;
}
Insert cell
Insert cell
canvas.getContext('2d').getImageData(0, 0, canvas.width, canvas.height) // 🌶
Insert cell
Insert cell
blob = new Promise((resolve, reject) => {
try {
canvas.toBlob(resolve);
} catch (e) {
reject(e);
}
}) // 🌶
Insert cell
Insert cell
dataURL = canvas.toDataURL() // 🌶
Insert cell
Insert cell
response = await fetch(bbb, { mode: 'no-cors' })
Insert cell
Insert cell
response.status
Insert cell
Insert cell
response.body
Insert cell
Insert cell
Insert cell
opaqueBlob = response.blob()
Insert cell
opaqueBlob.size
Insert cell
opaqueUrl = URL.createObjectURL(opaqueBlob)
Insert cell
Insert cell
html`<video controls src="${opaqueUrl}" />` // 🌶
Insert cell
Insert cell
caches
Insert cell
Insert cell
cache = caches.open('videos')
Insert cell
Insert cell
wait = {
const response2 = await fetch(bbb, { mode: 'no-cors' });
await cache.put(bbb, response2);
}
Insert cell
Insert cell
{
wait; // to be sure response2 has been cached
const r = await cache.match(bbb);
return {
status: r.status,
headersArray: [...r.headers.entries()],
type: r.type,
url: r.url
};
}
Insert cell
Insert cell
Insert cell
Insert cell
proxiedResponse = await fetch(corsProxy + bbb) // no more 'no-cors' mode
Insert cell
Insert cell
({
status: proxiedResponse.status,
headersArray: [...proxiedResponse.headers.entries()],
type: proxiedResponse.type,
url: proxiedResponse.url
})
Insert cell
Insert cell
proxiedBlob = proxiedResponse.blob()
Insert cell
proxiedSize = (proxiedBlob.size / 1024 / 1024).toFixed(1) + ' MB'
Insert cell
Insert cell
proxiedUrl = {
const url = URL.createObjectURL(proxiedBlob);
invalidation.then(() => URL.revokeObjectURL(url));
return url;
}
Insert cell
html`<video controls src="${proxiedUrl}">`
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more