mirror of
https://github.com/arcodange-org/mediabunny.git
synced 2026-09-27 10:53:50 +02:00
Add workaround for Chromium range request caching bug
This commit is contained in:
@@ -8,6 +8,15 @@
|
||||
document.body.append(fileInput);
|
||||
|
||||
fileInput.addEventListener('change', async () => {
|
||||
const videoUrl = "https://upload.wikimedia.org/wikipedia/commons/5/53/1941._%D0%9A%D0%BE%D0%BD%D1%91%D0%BA-%D0%B3%D0%BE%D1%80%D0%B1%D1%83%D0%BD%D0%BE%D0%BA.webm"
|
||||
const source = new Mediabunny.UrlSource(videoUrl)
|
||||
const input = new Mediabunny.Input({ formats: Mediabunny.ALL_FORMATS, source });
|
||||
|
||||
const videoTrack = await input.getPrimaryVideoTrack();
|
||||
|
||||
console.log(videoTrack);
|
||||
|
||||
/*
|
||||
const file = fileInput.files[0];
|
||||
const source = new Mediabunny.BlobSource(file);
|
||||
|
||||
@@ -20,6 +29,7 @@
|
||||
const sink = new Mediabunny.EncodedPacketSink(audioTrack);
|
||||
|
||||
console.log(await sink.getPacket(100))
|
||||
*/
|
||||
|
||||
/*
|
||||
for await (const packet of sink.packets()) {
|
||||
|
||||
Generated
+6
-6
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "mediabunny",
|
||||
"version": "1.7.0",
|
||||
"version": "1.7.1",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "mediabunny",
|
||||
"version": "1.7.0",
|
||||
"version": "1.7.1",
|
||||
"license": "MPL-2.0",
|
||||
"workspaces": [
|
||||
"packages/*"
|
||||
@@ -5900,9 +5900,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/mediabunny": {
|
||||
"version": "1.6.2",
|
||||
"resolved": "https://registry.npmjs.org/mediabunny/-/mediabunny-1.6.2.tgz",
|
||||
"integrity": "sha512-c0z6lfeYHYk5M6V9kLaXD/7HqW8UjjsDhoZUwLConxHCrL/pPMnZwX5tXjXz/T8DIeuXYYbjYR9X43LnEmWacA==",
|
||||
"version": "1.7.0",
|
||||
"resolved": "https://registry.npmjs.org/mediabunny/-/mediabunny-1.7.0.tgz",
|
||||
"integrity": "sha512-QcTdptOtvjAHb4KQpgWWWHRS0+DgGwTXelTwPWaZwQu85iYy11bzsLS4e29rfH4nLL/eq8K/dBsjj1LuApc2Qw==",
|
||||
"license": "MPL-2.0",
|
||||
"peer": true,
|
||||
"workspaces": [
|
||||
@@ -9017,7 +9017,7 @@
|
||||
},
|
||||
"packages/mp3-encoder": {
|
||||
"name": "@mediabunny/mp3-encoder",
|
||||
"version": "1.7.0",
|
||||
"version": "1.7.1",
|
||||
"license": "MPL-2.0",
|
||||
"devDependencies": {
|
||||
"@types/emscripten": "^1.40.1"
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "mediabunny",
|
||||
"author": "Vanilagy",
|
||||
"version": "1.7.0",
|
||||
"version": "1.7.1",
|
||||
"description": "Pure TypeScript media toolkit for reading, writing, and converting media files, directly in the browser.",
|
||||
"type": "module",
|
||||
"workspaces": [
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@mediabunny/mp3-encoder",
|
||||
"author": "Vanilagy",
|
||||
"version": "1.7.0",
|
||||
"version": "1.7.1",
|
||||
"description": "MP3 encoder extension for Mediabunny, based on LAME.",
|
||||
"main": "./dist/bundles/mediabunny-mp3-encoder.mjs",
|
||||
"module": "./dist/bundles/mediabunny-mp3-encoder.mjs",
|
||||
|
||||
+22
-2
@@ -164,11 +164,13 @@ export type UrlSourceOptions = {
|
||||
*/
|
||||
export class UrlSource extends Source {
|
||||
/** @internal */
|
||||
private _url: string | URL;
|
||||
private _url: URL;
|
||||
/** @internal */
|
||||
private _options: UrlSourceOptions;
|
||||
/** @internal */
|
||||
private _fullData: ArrayBuffer | null = null;
|
||||
/** @internal */
|
||||
private _nextUrlVersion: number | null = null;
|
||||
|
||||
constructor(
|
||||
url: string | URL,
|
||||
@@ -189,7 +191,7 @@ export class UrlSource extends Source {
|
||||
|
||||
super();
|
||||
|
||||
this._url = url;
|
||||
this._url = url instanceof URL ? url : new URL(url);
|
||||
this._options = options;
|
||||
}
|
||||
|
||||
@@ -203,6 +205,11 @@ export class UrlSource extends Source {
|
||||
headers['Range'] = `bytes=${range.start}-${range.end - 1}`;
|
||||
}
|
||||
|
||||
if (this._nextUrlVersion !== null) {
|
||||
this._url.searchParams.set('mediabunny_version', this._nextUrlVersion.toString());
|
||||
this._nextUrlVersion++;
|
||||
}
|
||||
|
||||
const response = await retriedFetch(
|
||||
this._url,
|
||||
mergeObjectsDeeply(this._options.requestInit ?? {}, {
|
||||
@@ -218,6 +225,19 @@ export class UrlSource extends Source {
|
||||
|
||||
const buffer = await response.arrayBuffer();
|
||||
|
||||
if (
|
||||
response.status === 206
|
||||
&& range
|
||||
&& buffer.byteLength !== range.end - range.start
|
||||
&& this._nextUrlVersion === null
|
||||
) {
|
||||
// We did a range request but it resolved with the wrong range; in Chromium, this can be due to a caching
|
||||
// bug (https://issues.chromium.org/issues/436025873). Let's circumvent the cache for the rest of the
|
||||
// session by appending a version to the URL.
|
||||
this._nextUrlVersion = 1;
|
||||
return this._makeRequest(range);
|
||||
}
|
||||
|
||||
if (response.status === 200) {
|
||||
// The server didn't return 206 Partial Content, so it's not a range response
|
||||
this._fullData = buffer;
|
||||
|
||||
Reference in New Issue
Block a user