Enable error message on non hls streams

This commit is contained in:
bytedream 2022-08-23 22:07:58 +02:00
parent fd5a532d0f
commit 175862b098

View File

@ -8,33 +8,13 @@ function show_message(message: string) {
document.getElementById('video').hidden = true
}
async function play_native(url: string, match: Match) {
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)
async function check_loaded(match: Match, check: () => boolean) {
const loaded = await new Promise((resolve, reject) => {
setTimeout(() => {
resolve(false)
}, match.reliability * 3000)
hls.on(Hls.Events.MANIFEST_PARSED, () => {
resolve(true)
})
check() ? resolve(true) : resolve(false)
})
if (!loaded) {
@ -56,6 +36,30 @@ async function play_hls(url: string, match: Match) {
}
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 {
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>')
}