Skip to content

Commit

Permalink
try this...
Browse files Browse the repository at this point in the history
  • Loading branch information
california authored and california committed Feb 13, 2025
1 parent 9dcd7ae commit 4c9dad2
Showing 1 changed file with 6 additions and 18 deletions.
24 changes: 6 additions & 18 deletions src/components/RouteVideoPlayer.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createEffect, createResource, onCleanup, onMount, type VoidComponent, createSignal } from 'solid-js'
import clsx from 'clsx'
import Icon from '~/components/material/Icon'
import { formatDuration } from '~/utils/format'
import Icon from '~/components/material/Icon'
import clsx from 'clsx'

import { getQCameraStreamUrl } from '~/api/route'

Expand All @@ -18,32 +18,18 @@ const RouteVideoPlayer: VoidComponent<RouteVideoPlayerProps> = (props) => {
const [progress, setProgress] = createSignal(0)
const [currentTime, setCurrentTime] = createSignal(0)
const [duration, setDuration] = createSignal(0)
const [hlsInstance, setHlsInstance] = createSignal<typeof import('hls.js/dist/hls.light.mjs')>()
let video!: HTMLVideoElement

function initializeHlsLoader() {
if (window.MediaSource !== undefined && !hlsInstance()) {
void import('hls.js/dist/hls.light.mjs')
.then(module => setHlsInstance(module))
.catch(error => {
console.error('Failed to load HLS.js:', error)
})
}
}

function setupVideoSource() {
if (!streamUrl()) return

// Try native HLS first - no extra code needed
if (video.canPlayType('application/vnd.apple.mpegurl')) {
video.src = streamUrl()!
return
}

// Only import HLS.js if we absolutely need it
if (window.MediaSource !== undefined) {
// This should be the rare case for older browsers
import('hls.js/dist/hls.light.mjs')
void import('hls.js/dist/hls.light.mjs')
.then(({ default: Hls }) => {
if (Hls.isSupported()) {
const player = new Hls()
Expand All @@ -52,6 +38,9 @@ const RouteVideoPlayer: VoidComponent<RouteVideoPlayerProps> = (props) => {
onCleanup(() => player.destroy())
}
})
.catch(error => {
console.error('Failed to load HLS.js:', error)
})
}
}

Expand Down Expand Up @@ -99,7 +88,6 @@ const RouteVideoPlayer: VoidComponent<RouteVideoPlayerProps> = (props) => {
}

onMount(setupVideoEventListeners)
createEffect(initializeHlsLoader)
createEffect(setupVideoSource)

return (
Expand Down

0 comments on commit 4c9dad2

Please sign in to comment.