diff --git a/src/view/com/util/post-embeds/VideoEmbed.tsx b/src/view/com/util/post-embeds/VideoEmbed.tsx index 82d8772723..44be475543 100644 --- a/src/view/com/util/post-embeds/VideoEmbed.tsx +++ b/src/view/com/util/post-embeds/VideoEmbed.tsx @@ -27,7 +27,7 @@ export function VideoEmbed({source}: {source: string}) { a.my_xs, ]}> {active ? ( - + ) : ( new Hls()) - const hasLoaded = useRef(false) - const ref = useRef(null) + const t = useTheme() + const ref = useRef(null) const {active, setActive} = useActiveVideoView({ source, - measure: useCallback(() => { + measure: () => { if (ref.current) { return ref.current.getBoundingClientRect() } - }, []), + }, }) - const t = useTheme() + const [hasBeenActive, setHasBeenActive] = useState(false) + const {_} = useLingui() + + const onPress = useCallback(() => setActive(), [setActive]) useEffect(() => { - if (ref.current && active && !hasLoaded.current) { - hasLoaded.current = true - if (ref.current.canPlayType('application/vnd.apple.mpegurl')) { - ref.current.src = source - } else if (Hls.isSupported()) { - hls.loadSource(source) - } else { - // TODO: fallback - } + if (active) { + setHasBeenActive(true) } - }, [source, active, hls]) - - useEffect(() => { - if (ref.current) { - if ( - !ref.current.canPlayType('application/vnd.apple.mpegurl') && - Hls.isSupported() - ) { - hls.attachMedia(ref.current) - } - } - }, [source, active, hls]) + }, [active]) return ( - { - if (!active) { - setActive() - } - }} - /> + + {hasBeenActive ? ( + + ) : ( + + + + )} + ) } diff --git a/src/view/com/util/post-embeds/VideoEmbedInner.tsx b/src/view/com/util/post-embeds/VideoEmbedInner.tsx index ef06787097..07d111d1ba 100644 --- a/src/view/com/util/post-embeds/VideoEmbedInner.tsx +++ b/src/view/com/util/post-embeds/VideoEmbedInner.tsx @@ -13,7 +13,7 @@ import {atoms as a} from '#/alf' import {Text} from '#/components/Typography' import {useVideoPlayer} from './VideoPlayerContext' -export const VideoEmbedInner = ({}: {source: string}) => { +export function VideoEmbedInner({}: {source: string; active: boolean}) { const player = useVideoPlayer() const aref = useAnimatedRef() const {height: windowHeight} = useWindowDimensions() diff --git a/src/view/com/util/post-embeds/VideoEmbedInner.web.tsx b/src/view/com/util/post-embeds/VideoEmbedInner.web.tsx new file mode 100644 index 0000000000..05c45af74d --- /dev/null +++ b/src/view/com/util/post-embeds/VideoEmbedInner.web.tsx @@ -0,0 +1,63 @@ +import React, {useEffect, useRef, useState} from 'react' +import {View} from 'react-native' +import Hls from 'hls.js' + +import {atoms as a, useTheme} from '#/alf' + +export function VideoEmbedInner({ + source, + active, +}: { + source: string + active: boolean +}) { + const [hls] = useState(() => new Hls()) + const ref = useRef(null) + const t = useTheme() + + useEffect(() => { + if (ref.current) { + if (ref.current.canPlayType('application/vnd.apple.mpegurl')) { + ref.current.src = source + } else if (Hls.isSupported()) { + hls.loadSource(source) + } else { + // TODO: fallback + } + } + }, [source, hls]) + + useEffect(() => { + if (ref.current) { + if ( + !ref.current.canPlayType('application/vnd.apple.mpegurl') && + Hls.isSupported() + ) { + hls.attachMedia(ref.current) + } + } + }, [source, hls]) + + return ( + + + + ) +}