@banou/media-player 0.9.0 → 0.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -24,8 +24,19 @@ const fromUrl = async (
24
24
  ) => {
25
25
  const length = _length ?? await probeLength(url, credentials)
26
26
  const read = async (offset: number, size: number) => {
27
+ /*
28
+ * A read that starts at or past the end answers empty, the way slicing a Blob does.
29
+ *
30
+ * Without this the range comes out as `bytes=<offset>-<length-1>` with the last byte before the
31
+ * first, which is not a range a server can satisfy: it answers 416 and the read throws, so the
32
+ * demuxer's ordinary walk into EOF surfaces as "Reading the video file failed" on a file that is
33
+ * perfectly fine. The blob arm has always returned empty here, so this is also what makes the two
34
+ * arms of `inputToRemuxerInput` behave the same.
35
+ */
36
+ const end = Math.min(offset + size, length) - 1
37
+ if (end < offset) return new ArrayBuffer(0)
27
38
  const response = await fetch(url, {
28
- headers: { Range: `bytes=${offset}-${Math.min(offset + size, length) - 1}` },
39
+ headers: { Range: `bytes=${offset}-${end}` },
29
40
  credentials,
30
41
  })
31
42
  if (!response.ok) throw new Error(`The source could not be read: HTTP ${response.status}`)