@banou/media-player 0.2.1 → 0.2.3
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/build/index.js +613 -602
- package/package.json +2 -2
- package/src/index.tsx +7 -1
- package/src/main.tsx +3 -3
- package/src/utils.ts +13 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@banou/media-player",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
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.
|
|
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,8 +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()
|
|
258
|
+
if (chunk.isTrailer) reachedEnd = true
|
|
255
259
|
chunks = [...chunks, chunk]
|
|
256
260
|
return chunk
|
|
257
261
|
}
|
|
@@ -265,7 +269,7 @@ const FKNVideo = forwardRef<HTMLVideoElement, VideoHTMLAttributes<HTMLInputEleme
|
|
|
265
269
|
const sliceIndex = Math.max(0, currentChunkIndex - PREVIOUS_BUFFER_COUNT)
|
|
266
270
|
|
|
267
271
|
for (let i = 0; i < sliceIndex + BUFFER_COUNT; i++) {
|
|
268
|
-
if (chunks[i]) continue
|
|
272
|
+
if (chunks[i] || reachedEnd) continue
|
|
269
273
|
const chunk = await pull()
|
|
270
274
|
await appendBuffer(chunk.buffer)
|
|
271
275
|
}
|
|
@@ -297,11 +301,13 @@ const FKNVideo = forwardRef<HTMLVideoElement, VideoHTMLAttributes<HTMLInputEleme
|
|
|
297
301
|
let firstSeekPaused: boolean | undefined
|
|
298
302
|
const seek = debounceImmediateAndLatest(250, async (seekTime: number) => {
|
|
299
303
|
try {
|
|
304
|
+
reachedEnd = false
|
|
300
305
|
if (firstSeekPaused === undefined) firstSeekPaused = videoElement.paused
|
|
301
306
|
seeking = true
|
|
302
307
|
chunks = []
|
|
303
308
|
await remuxer.seek(seekTime)
|
|
304
309
|
const chunk1 = await pull()
|
|
310
|
+
// firefox sometimes throws "Uncaught (in promise) DOMException: An attempt was made to use an object that is not, or is no longer, usable"
|
|
305
311
|
sourceBuffer.timestampOffset = chunk1.pts
|
|
306
312
|
await appendBuffer(chunk1.buffer)
|
|
307
313
|
if (firstSeekPaused === false) {
|
package/src/main.tsx
CHANGED
|
@@ -12,7 +12,7 @@ const mountStyle = css`
|
|
|
12
12
|
`
|
|
13
13
|
|
|
14
14
|
const BASE_BUFFER_SIZE = 5_000_000
|
|
15
|
-
const
|
|
15
|
+
const BACKPRESSURE_STREAM_ENABLED = !navigator.userAgent.includes("Firefox")
|
|
16
16
|
|
|
17
17
|
const Mount = () => {
|
|
18
18
|
const [videoElemRef, setVideoElemRef] = useState<HTMLVideoElement | null>()
|
|
@@ -25,10 +25,10 @@ const Mount = () => {
|
|
|
25
25
|
|
|
26
26
|
const onFetch = async (offset: number, end?: number) =>
|
|
27
27
|
fetch(
|
|
28
|
-
'/
|
|
28
|
+
'/video9.mkv',
|
|
29
29
|
{
|
|
30
30
|
headers: {
|
|
31
|
-
Range: `bytes=${offset}-${end ?? ''}`
|
|
31
|
+
Range: `bytes=${offset}-${end ?? (!BACKPRESSURE_STREAM_ENABLED ? Math.min(offset + BASE_BUFFER_SIZE, size!) : '')}`
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
34
|
)
|
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)
|
|
@@ -226,8 +227,18 @@ export const toBufferedStream = (SIZE: number) => (stream: ReadableStream) =>
|
|
|
226
227
|
}
|
|
227
228
|
|
|
228
229
|
await tryToBuffer()
|
|
229
|
-
|
|
230
|
-
|
|
230
|
+
try {
|
|
231
|
+
controller.enqueue(this.buffers.shift())
|
|
232
|
+
tryToBuffer()
|
|
233
|
+
} catch(err) {
|
|
234
|
+
// firefox somehow shits the bed here
|
|
235
|
+
if (!(
|
|
236
|
+
err instanceof TypeError &&
|
|
237
|
+
err.message === 'ReadableStreamDefaultController.enqueue: Cannot enqueue into a stream that has already been requested to close.'
|
|
238
|
+
)) {
|
|
239
|
+
throw err
|
|
240
|
+
}
|
|
241
|
+
}
|
|
231
242
|
},
|
|
232
243
|
cancel() {
|
|
233
244
|
this.reader!.cancel()
|