Skip to content

Commit

Permalink
fixes video mobile bugs...
Browse files Browse the repository at this point in the history
  • Loading branch information
california authored and california committed Feb 13, 2025
1 parent 30487c2 commit b2c6f57
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/components/RouteVideoPlayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,22 @@ const RouteVideoPlayer: VoidComponent<RouteVideoPlayerProps> = (props) => {
function setupVideoEventListeners() {
const handleTimeUpdate = () => props.onProgress?.(video.currentTime)
video.addEventListener('timeupdate', handleTimeUpdate)
onCleanup(() => video.removeEventListener('timeupdate', handleTimeUpdate))

video.addEventListener('stalled', () => {
if (isPlaying()) {
void video.play().catch(() => {
})
}
})

video.addEventListener('loadedmetadata', () => {
setDuration(video.duration)
void video.play().catch(() => setIsPlaying(false))
})

onCleanup(() => {
video.removeEventListener('timeupdate', handleTimeUpdate)
video.removeEventListener('stalled', () => {})
})

props.ref?.(video)
Expand All @@ -103,6 +115,9 @@ const RouteVideoPlayer: VoidComponent<RouteVideoPlayerProps> = (props) => {
class="absolute inset-0 size-full object-cover"
autoplay
muted
playsinline
controls={false}
disablepictureinpicture
onPlay={startProgressTracking}
onTimeUpdate={(e) => {
updateProgressOnTimeUpdate()
Expand Down

0 comments on commit b2c6f57

Please sign in to comment.