mirror of
https://github.com/bytedream/stream-bypass.git
synced 2025-05-12 05:35:12 +02:00
Enable error message on non hls streams
This commit is contained in:
parent
fd5a532d0f
commit
175862b098
@ -8,33 +8,13 @@ function show_message(message: string) {
|
|||||||
document.getElementById('video').hidden = true
|
document.getElementById('video').hidden = true
|
||||||
}
|
}
|
||||||
|
|
||||||
async function play_native(url: string, match: Match) {
|
async function check_loaded(match: Match, check: () => boolean) {
|
||||||
const video = document.getElementById('video') as HTMLVideoElement
|
|
||||||
video.controls = true
|
|
||||||
video.src = url
|
|
||||||
}
|
|
||||||
|
|
||||||
async function play_hls(url: string, match: Match) {
|
|
||||||
const video = document.getElementById('video') as HTMLVideoElement
|
|
||||||
video.controls = true
|
|
||||||
|
|
||||||
if (video.canPlayType('application/vnd.apple.mpegurl')) {
|
|
||||||
video.src = url
|
|
||||||
} else if (Hls.isSupported()) {
|
|
||||||
const hls = new Hls({
|
|
||||||
enableWorker: false
|
|
||||||
})
|
|
||||||
hls.loadSource(url)
|
|
||||||
hls.attachMedia(video)
|
|
||||||
|
|
||||||
const loaded = await new Promise((resolve, reject) => {
|
const loaded = await new Promise((resolve, reject) => {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
resolve(false)
|
resolve(false)
|
||||||
}, match.reliability * 3000)
|
}, match.reliability * 3000)
|
||||||
|
|
||||||
hls.on(Hls.Events.MANIFEST_PARSED, () => {
|
check() ? resolve(true) : resolve(false)
|
||||||
resolve(true)
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
||||||
if (!loaded) {
|
if (!loaded) {
|
||||||
@ -56,6 +36,30 @@ async function play_hls(url: string, match: Match) {
|
|||||||
}
|
}
|
||||||
show_message(`Could not load video. ${message}`)
|
show_message(`Could not load video. ${message}`)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function play_native(url: string, match: Match) {
|
||||||
|
const video = document.getElementById('video') as HTMLVideoElement
|
||||||
|
video.controls = true
|
||||||
|
video.src = url
|
||||||
|
|
||||||
|
await check_loaded(match, () => { return video.readyState >= 3 })
|
||||||
|
}
|
||||||
|
|
||||||
|
async function play_hls(url: string, match: Match) {
|
||||||
|
const video = document.getElementById('video') as HTMLVideoElement
|
||||||
|
video.controls = true
|
||||||
|
|
||||||
|
if (video.canPlayType('application/vnd.apple.mpegurl')) {
|
||||||
|
video.src = url
|
||||||
|
} else if (Hls.isSupported()) {
|
||||||
|
const hls = new Hls({
|
||||||
|
enableWorker: false
|
||||||
|
})
|
||||||
|
hls.loadSource(url)
|
||||||
|
hls.attachMedia(video)
|
||||||
|
|
||||||
|
await check_loaded(match, () => { return video.readyState >= 3 })
|
||||||
} else {
|
} else {
|
||||||
show_message('Failed to play m3u8 video (hls is not supported). Try again or create a new issue <a href="https://github.com/ByteDream/stream-bypass/issues/new">here</a>')
|
show_message('Failed to play m3u8 video (hls is not supported). Try again or create a new issue <a href="https://github.com/ByteDream/stream-bypass/issues/new">here</a>')
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user