@banou/media-player 0.2.4 → 0.2.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.
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.6",
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",
@@ -30,6 +30,7 @@ overflow: hidden;
30
30
  `
31
31
 
32
32
  export type ChromeOptions = {
33
+ publicPath: string
33
34
  customOverlay?: ReactNode
34
35
  isPlaying?: boolean
35
36
  loading?: boolean
@@ -54,6 +55,7 @@ export type ChromeOptions = {
54
55
 
55
56
  export default ({
56
57
  customOverlay,
58
+ publicPath,
57
59
  isPlaying,
58
60
  loading,
59
61
  duration,
@@ -137,7 +139,7 @@ export default ({
137
139
  canvas: canvasElement,
138
140
  subContent: subtitleTrack.data,
139
141
  fonts: fonts.filter(Boolean).map(([,filename]) => filename as string),
140
- availableFonts: { ...Object.fromEntries(fonts), 'liberation sans': new URL('/build/default.woff2', new URL(window.location.toString()).origin).toString() },
142
+ availableFonts: { ...Object.fromEntries(fonts), 'liberation sans': `${publicPath}default.woff2` },
141
143
  workerUrl: libassWorkerUrl, // Link to WebAssembly-based file "libassjs-worker.js",
142
144
  modernWasmUrl: wasmUrl
143
145
  })
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
  }
@@ -442,6 +447,7 @@ const FKNVideo = forwardRef<HTMLVideoElement, VideoHTMLAttributes<HTMLInputEleme
442
447
  <Chrome
443
448
  className="chrome"
444
449
  customOverlay={customOverlay}
450
+ publicPath={publicPath}
445
451
  isPlaying={isPlaying}
446
452
  video={videoRef}
447
453
  needsInitialInteraction={needsInitialInteraction}
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) {