@banou/media-player 0.2.0 → 0.2.2

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.0",
3
+ "version": "0.2.2",
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.1",
40
+ "libav-wasm": "^0.3.3",
41
41
  "mp4box": "^0.5.2",
42
42
  "osra": "^0.0.11",
43
43
  "p-queue": "^7.3.4",
package/src/index.tsx CHANGED
@@ -250,9 +250,12 @@ const FKNVideo = forwardRef<HTMLVideoElement, VideoHTMLAttributes<HTMLInputEleme
250
250
 
251
251
  await appendBuffer(headerChunk.buffer)
252
252
 
253
+ let reachedEnd = false
254
+
253
255
  const pull = async () => {
256
+ if (reachedEnd) throw new Error('end')
254
257
  const chunk = await remuxer.read()
255
- // @ts-expect-error
258
+ if (chunk.isTrailer) reachedEnd = true
256
259
  chunks = [...chunks, chunk]
257
260
  return chunk
258
261
  }
@@ -266,9 +269,8 @@ const FKNVideo = forwardRef<HTMLVideoElement, VideoHTMLAttributes<HTMLInputEleme
266
269
  const sliceIndex = Math.max(0, currentChunkIndex - PREVIOUS_BUFFER_COUNT)
267
270
 
268
271
  for (let i = 0; i < sliceIndex + BUFFER_COUNT; i++) {
269
- if (chunks[i]) continue
272
+ if (chunks[i] || reachedEnd) continue
270
273
  const chunk = await pull()
271
- // @ts-expect-error
272
274
  await appendBuffer(chunk.buffer)
273
275
  }
274
276
 
@@ -299,14 +301,13 @@ const FKNVideo = forwardRef<HTMLVideoElement, VideoHTMLAttributes<HTMLInputEleme
299
301
  let firstSeekPaused: boolean | undefined
300
302
  const seek = debounceImmediateAndLatest(250, async (seekTime: number) => {
301
303
  try {
304
+ reachedEnd = false
302
305
  if (firstSeekPaused === undefined) firstSeekPaused = videoElement.paused
303
306
  seeking = true
304
307
  chunks = []
305
308
  await remuxer.seek(seekTime)
306
309
  const chunk1 = await pull()
307
- // @ts-expect-error
308
310
  sourceBuffer.timestampOffset = chunk1.pts
309
- // @ts-expect-error
310
311
  await appendBuffer(chunk1.buffer)
311
312
  if (firstSeekPaused === false) {
312
313
  await videoElement.play()
@@ -323,7 +324,6 @@ const FKNVideo = forwardRef<HTMLVideoElement, VideoHTMLAttributes<HTMLInputEleme
323
324
  })
324
325
 
325
326
  const firstChunk = await pull()
326
- // @ts-expect-error
327
327
  appendBuffer(firstChunk.buffer)
328
328
 
329
329
  videoElement.addEventListener('timeupdate', () => {
package/src/main.tsx CHANGED
@@ -25,7 +25,7 @@ const Mount = () => {
25
25
 
26
26
  const onFetch = async (offset: number, end?: number) =>
27
27
  fetch(
28
- '/video6.mkv',
28
+ '/video9.mkv',
29
29
  {
30
30
  headers: {
31
31
  Range: `bytes=${offset}-${end ?? ''}`
package/src/utils.ts CHANGED
@@ -200,6 +200,7 @@ export const toBufferedStream = (SIZE: number) => (stream: ReadableStream) =>
200
200
  this.currentPullPromise = undefined
201
201
  if (done) {
202
202
  try {
203
+ for (const buffer of this.buffers) controller.enqueue(buffer)
203
204
  controller.close()
204
205
  } catch (err) {
205
206
  // console.error(err)