@banou/media-player 0.2.4 → 0.2.5

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@banou/media-player",
3
- "version": "0.2.4",
3
+ "version": "0.2.5",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "build/index.js",
@@ -37,7 +37,7 @@
37
37
  "dependencies": {
38
38
  "@emotion/react": "^11.10.5",
39
39
  "jassub": "^1.7.1",
40
- "libav-wasm": "^0.3.3",
40
+ "libav-wasm": "^0.3.4",
41
41
  "mp4box": "^0.5.2",
42
42
  "osra": "^0.0.11",
43
43
  "p-queue": "^7.3.4",
package/src/index.tsx CHANGED
@@ -246,7 +246,7 @@ const FKNVideo = forwardRef<HTMLVideoElement, VideoHTMLAttributes<HTMLInputEleme
246
246
  let chunks: Chunk[] = []
247
247
 
248
248
  const PREVIOUS_BUFFER_COUNT = 1
249
- const BUFFER_COUNT = 5
249
+ const NEEDED_TIME_IN_SECONDS = 15
250
250
 
251
251
  await appendBuffer(headerChunk.buffer)
252
252
 
@@ -268,8 +268,13 @@ const FKNVideo = forwardRef<HTMLVideoElement, VideoHTMLAttributes<HTMLInputEleme
268
268
  const currentChunkIndex = chunks.findIndex(({ pts, duration }) => pts <= currentTime && pts + duration >= currentTime)
269
269
  const sliceIndex = Math.max(0, currentChunkIndex - PREVIOUS_BUFFER_COUNT)
270
270
 
271
- for (let i = 0; i < sliceIndex + BUFFER_COUNT; i++) {
272
- if (chunks[i] || reachedEnd) continue
271
+ const getLastChunkEndTime = () => {
272
+ const lastChunk = chunks.at(-1)
273
+ if (!lastChunk) return 0
274
+ return lastChunk.pts + lastChunk.duration
275
+ }
276
+
277
+ while (getLastChunkEndTime() < currentTime + NEEDED_TIME_IN_SECONDS){
273
278
  const chunk = await pull()
274
279
  await appendBuffer(chunk.buffer)
275
280
  }
package/src/utils.ts CHANGED
@@ -15,6 +15,7 @@ export function debounceImmediateAndLatest<T extends (...args: any[]) => any>(
15
15
  let lastArgs: any[] | null = null;
16
16
 
17
17
  const debouncedFunction = function(...args: any[]) {
18
+ // @ts-expect-error
18
19
  const context = this;
19
20
 
20
21
  if (timeoutId === null) {