live-sfu-demo/web/src/lib/hls.ts

20 lines
457 B
TypeScript

import Hls from 'hls.js'
export function playHLS(video: HTMLVideoElement, url: string): () => void {
if (Hls.isSupported()) {
const hls = new Hls()
hls.loadSource(url)
hls.attachMedia(video)
video.play().catch(() => {})
return () => hls.destroy()
}
if (video.canPlayType('application/vnd.apple.mpegurl')) {
video.src = url
video.play().catch(() => {})
return () => {
video.src = ''
}
}
return () => {}
}