react-vimeo
react-vimeo copied to clipboard
Events
Hello, How can I use events? I am trying to do this
<Vimeo video="3718294" autoplay onProgress={console.log("hey")}/>
but the even is not getting triggered
Event callbacks take a function that is called. So replace console.log("hey") with () => console.log("hey").
I was try onPlay, onPlaying all event is not working but I found work around here my code try this
const [player, setPlayer] = useState<any>(undefined)
const isMount = useRef(false)
useEffect(() => {
if (player && !isMount.current) {
try {
player.on('play', () => {
onPlay && onPlay()
})
player.on('pause', () => { // pause and finish
onPauseOrEnd && onPauseOrEnd()
})
onPlayerReady && onPlayerReady()
isMount.current = true
} catch (e) {
console.log('fail to load player event e:', e)
}
}
}, [player])
return (
<Vimeo
onReady={setPlayer}
video={videoId}
...
/>
)
<VimeoPlayer
video={video}
responsive={true}
onPlay={() => {console.log('play');}}
onPlaying={() => {console.log('playing');}}
/>
onPlay and onPlaying callbacks are not triggered.