[Video] 🫧 Move logic around by platform (#5003)
This commit is contained in:
parent
9aa2b2d14e
commit
5ae0d40a14
9 changed files with 77 additions and 95 deletions
40
src/view/com/util/post-embeds/ActiveVideoNativeContext.tsx
Normal file
40
src/view/com/util/post-embeds/ActiveVideoNativeContext.tsx
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
import React from 'react'
|
||||
import {useVideoPlayer, VideoPlayer} from 'expo-video'
|
||||
|
||||
import {isNative} from '#/platform/detection'
|
||||
|
||||
const Context = React.createContext<{
|
||||
activeSource: string | null
|
||||
setActiveSource: (src: string) => void
|
||||
player: VideoPlayer
|
||||
} | null>(null)
|
||||
|
||||
export function Provider({children}: {children: React.ReactNode}) {
|
||||
if (!isNative) {
|
||||
throw new Error('ActiveVideoProvider may only be used on native.')
|
||||
}
|
||||
|
||||
const [activeSource, setActiveSource] = React.useState('')
|
||||
|
||||
const player = useVideoPlayer(activeSource, p => {
|
||||
p.muted = true
|
||||
p.loop = true
|
||||
p.play()
|
||||
})
|
||||
|
||||
return (
|
||||
<Context.Provider value={{activeSource, setActiveSource, player}}>
|
||||
{children}
|
||||
</Context.Provider>
|
||||
)
|
||||
}
|
||||
|
||||
export function useActiveVideoNative() {
|
||||
const context = React.useContext(Context)
|
||||
if (!context) {
|
||||
throw new Error(
|
||||
'useActiveVideoNative must be used within a ActiveVideoNativeProvider',
|
||||
)
|
||||
}
|
||||
return context
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue