@banou/media-player 0.10.5 → 0.10.6

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.
@@ -134,13 +134,13 @@ var t = [
134
134
  },
135
135
  set: (e, t, r) => {
136
136
  let i = p.get(e);
137
- if (!(!i || !n.includes(t))) try {
137
+ if (i && n.includes(t)) try {
138
138
  i[t] = r;
139
139
  } catch {}
140
140
  },
141
141
  call: async (e, t) => {
142
142
  let n = p.get(e);
143
- if (!(!n || !r.includes(t))) try {
143
+ if (n && r.includes(t)) try {
144
144
  t === "play" ? await n.play() : t === "pause" ? n.pause() : n.load?.();
145
145
  } finally {
146
146
  C(e, "timeupdate");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@banou/media-player",
3
- "version": "0.10.5",
3
+ "version": "0.10.6",
4
4
  "description": "A video player for containers and codecs the browser cannot play natively, remuxed on the fly",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -60,21 +60,22 @@
60
60
  "@types/react": "^19.0.0",
61
61
  "@types/react-dom": "^19.0.0",
62
62
  "@vitejs/plugin-react": "^6.0.3",
63
- "@vitest/browser-playwright": "^4.1.10",
63
+ "@vitest/browser-playwright": "4.1.11",
64
64
  "playwright": "^1.62.1",
65
65
  "react": "^19.0.0",
66
66
  "react-dom": "^19.0.0",
67
67
  "shx": "^0.3.4",
68
68
  "typescript": "^7.0.2",
69
- "vite": "npm:@voidzero-dev/vite-plus-core@0.2.4",
70
- "vite-plus": "0.2.4",
69
+ "vite": "npm:@voidzero-dev/vite-plus-core@0.3.3",
70
+ "vite-plus": "0.3.3",
71
71
  "vitest-browser-react": "^2.2.0"
72
72
  },
73
73
  "overrides": {
74
- "vite": "npm:@voidzero-dev/vite-plus-core@0.2.4"
74
+ "vite": "npm:@voidzero-dev/vite-plus-core@0.3.3",
75
+ "vitest": "4.1.11"
75
76
  },
76
77
  "repository": {
77
78
  "type": "git",
78
- "url": "git+https://github.com/Banou26/media-player.git"
79
+ "url": "git+https://github.com/banou26/media-player.git"
79
80
  }
80
81
  }
@@ -241,6 +241,7 @@ export const ProgressBar = () => {
241
241
  const duration = usePlayer((state) => state.duration)
242
242
  const size = usePlayer((state) => state.size)
243
243
  const downloadedRanges = usePlayer((state) => state.downloadedRanges)
244
+ const buffered = usePlayer((state) => state.buffered)
244
245
  const indexes = usePlayer((state) => state.indexes)
245
246
  const thumbnails = usePlayer((state) => state.thumbnails)
246
247
  const thumbnailAt = usePlayer((state) => state.thumbnailAt)
@@ -357,25 +358,30 @@ export const ProgressBar = () => {
357
358
  // duration is 0 until metadata lands, which is never a divisor
358
359
  const timePercentage = (time: number) => duration ? (time / duration) * 100 : 0
359
360
 
361
+ const loadedPart = (key: number, start: number, end: number) => {
362
+ const rangeDuration = Number((end - start).toFixed(4)) // to prevent cases like `0.9995140832939585`
363
+ const left = start * 100
364
+ return (
365
+ <div key={key} className="loaded-part" style={{ transform: `scaleX(${rangeDuration})`, marginLeft: `${left}%` }}></div>
366
+ )
367
+ }
368
+
360
369
  // download percentage is not time percentage: headers and fonts can run to tens of megabytes
361
370
  const loadedParts = useMemo(() =>
362
- downloadedRanges
363
- ?.map((range, i) => {
364
- if (!size || !duration) return null
365
- const matchingIndexes = indexes.filter(index => range.startByteOffset <= index.pos && index.pos <= range.endByteOffset)
366
- const firstIndex = matchingIndexes.at(0)
367
- const lastIndex = matchingIndexes.at(-1)
368
- if (!firstIndex || !lastIndex) return null
369
- const start = firstIndex.timestamp / duration
370
- const end = lastIndex.timestamp / duration
371
- const rangeDuration = Number((end - start).toFixed(2)) // to prevent cases like `0.9995140832939585`
372
- const left = start * 100
373
- return (
374
- <div key={i} className="loaded-part" style={{ transform: `scaleX(${rangeDuration})`, marginLeft: `${left}%` }}></div>
375
- )
376
- })
377
- ?? [],
378
- [duration, indexes.length, downloadedRanges?.map(({ startByteOffset, endByteOffset }) => `${startByteOffset}/${endByteOffset}`).join(',')]
371
+ // a media the player does not own brings no bytes, so the element's own buffered time is all there is
372
+ size === undefined
373
+ ? (duration ? buffered.map(([start, end], i) => loadedPart(i, start / duration, end / duration)) : [])
374
+ : downloadedRanges
375
+ ?.map((range, i) => {
376
+ if (!size || !duration) return null
377
+ const matchingIndexes = indexes.filter(index => range.startByteOffset <= index.pos && index.pos <= range.endByteOffset)
378
+ const firstIndex = matchingIndexes.at(0)
379
+ const lastIndex = matchingIndexes.at(-1)
380
+ if (!firstIndex || !lastIndex) return null
381
+ return loadedPart(i, firstIndex.timestamp / duration, lastIndex.timestamp / duration)
382
+ })
383
+ ?? [],
384
+ [duration, size, size === undefined ? buffered : undefined, indexes.length, downloadedRanges?.map(({ startByteOffset, endByteOffset }) => `${startByteOffset}/${endByteOffset}`).join(',')]
379
385
  )
380
386
 
381
387