feat: add error handling for audio, video, and YouTube players
This commit is contained in:
parent
3395bad78b
commit
6eb3bccd38
4 changed files with 38 additions and 3 deletions
|
|
@ -4,6 +4,7 @@ import mediaManager from '@/services/media-manager.service'
|
|||
import { YouTubePlayer } from '@/types/youtube'
|
||||
import { useEffect, useMemo, useRef, useState } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import ExternalLink from '../ExternalLink'
|
||||
|
||||
export default function YoutubeEmbeddedPlayer({
|
||||
url,
|
||||
|
|
@ -19,6 +20,7 @@ export default function YoutubeEmbeddedPlayer({
|
|||
const [display, setDisplay] = useState(autoLoadMedia)
|
||||
const { videoId, isShort } = useMemo(() => parseYoutubeUrl(url), [url])
|
||||
const [initSuccess, setInitSuccess] = useState(false)
|
||||
const [error, setError] = useState(false)
|
||||
const playerRef = useRef<YouTubePlayer | null>(null)
|
||||
const containerRef = useRef<HTMLDivElement>(null)
|
||||
|
||||
|
|
@ -63,7 +65,8 @@ export default function YoutubeEmbeddedPlayer({
|
|||
},
|
||||
onReady: () => {
|
||||
setInitSuccess(true)
|
||||
}
|
||||
},
|
||||
onError: () => setError(true)
|
||||
}
|
||||
})
|
||||
} catch (error) {
|
||||
|
|
@ -79,6 +82,10 @@ export default function YoutubeEmbeddedPlayer({
|
|||
}
|
||||
}, [videoId, display, mustLoad])
|
||||
|
||||
if (error) {
|
||||
return <ExternalLink url={url} />
|
||||
}
|
||||
|
||||
if (!mustLoad && !display) {
|
||||
return (
|
||||
<div
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue