mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-28 02:01:20 -08:00
refactor(mediabunny): [PKG-MB-03] type inputs and cancel owned loads
This commit is contained in:
1 parent
03451c029b
commit
adba8a3d12
35 files changed
+11260
-3327
No files matched your search
@@ -0,0 +1,37 @@
|
||||
import type { InputOptions } from 'mediabunny'
|
||||
import {
|
||||
ALL_FORMATS,
|
||||
BlobSource,
|
||||
HLS_FORMATS,
|
||||
Input,
|
||||
ReadableStreamSource,
|
||||
UrlSource,
|
||||
} from 'mediabunny'
|
||||
|
||||
const M3U8_RE = /\.m3u8(?:$|[?#])/i
|
||||
|
||||
export function isHlsSource(src: unknown): boolean {
|
||||
return typeof src === 'string' && M3U8_RE.test(src)
|
||||
}
|
||||
|
||||
export function normalizeSource(src: unknown): unknown {
|
||||
if (typeof src === 'string')
|
||||
return new UrlSource(src)
|
||||
if (src instanceof Blob)
|
||||
return new BlobSource(src)
|
||||
if (typeof ReadableStream !== 'undefined' && src instanceof ReadableStream)
|
||||
return new ReadableStreamSource(src)
|
||||
return src ?? null
|
||||
}
|
||||
|
||||
export function createInput(src: unknown): Input | null {
|
||||
const source = normalizeSource(src)
|
||||
if (!source)
|
||||
return null
|
||||
|
||||
return new Input({
|
||||
// Preserve SDK Source/SourceRef pass-through and its historical validation errors.
|
||||
source: source as InputOptions['source'],
|
||||
formats: isHlsSource(src) ? HLS_FORMATS : ALL_FORMATS,
|
||||
})
|
||||
}
|
||||
Reference in new issue
Block a user