react-vimeo icon indicating copy to clipboard operation
react-vimeo copied to clipboard

Restart Video

Open bennik88 opened this issue 3 years ago • 1 comments

Problem

I want to restart the video and can't find a way to make it work.

I'm trying to make an on hover video player, so as soon as you hover over the video it starts playing and when you leave the mouse the thumbnail will appear again and it starts from new as soon as you hover again.

What I've tried

Set the start prop to 0 as soon as the video is paused. But it seems to have no effect. Is this prop refreshing? I've also tried to use the onPause prop to set the setStart state to 0.

bennik88 avatar Sep 20 '22 14:09 bennik88

The start prop is a bit unusual, changing it doesn't really do anything. It's only used when the video ID changes as well. For granular/direct control like this, you need to use the methods on the underlying @vimeo/player instance, which you can access in onReady.

const [player, setPlayer] = useState(null)

const restartVideo = useCallback(() => {
  player.setCurrentTime(0)
}, [player])

return <Vimeo onReady={setPlayer} />

goto-bus-stop avatar Oct 12 '22 08:10 goto-bus-stop