react-youtube
react-youtube copied to clipboard
How can I play/pause video programmaticaly (by click of a button) and get the timecode?
I need to play/pause video by button click (without event access like the one we get in onready). Also I need to get the current time being played

How can I do that? Thank you in advance!
Hello Lotfi, I created an example to play/pause using an external button.
I hope I helped, any questions I'm at your disposal
https://codesandbox.io/s/runtime-hill-c77o1v?file=/src/App.tsx
Hello Lotfi, I created an example to play/pause using an external button.
I hope I helped, any questions I'm at your disposal
https://codesandbox.io/s/runtime-hill-c77o1v?file=/src/App.tsx
Gabriel, thanks a lot!!! Just one follow-up: is there any way to find out (is video running or not at the moment)? Just for the case user instead of clicking my button is using Youtube controls to switch play/pause?
Another interesting thing - how can I hook the particular timepoint of the video? I mean - can I catch event, when user is watching the particular timepoint of the video?
@lofti198 I updated the code in the sandbox, added these functionalities:
- Current time when pause/play video;
- Current time in real time
- Get video status in real time
https://codesandbox.io/s/runtime-hill-c77o1v?file=/src/App.tsx
In case you need something more precise, you can shorten the break time (line 81)
Oh that is completely cool example! Thank you! Can I somehow donate to thank you?
You were the first person I helped on github :)
If possible follow me here on github, I want to improve my network
Hello Lotfi, I created an example to play/pause using an external button. I hope I helped, any questions I'm at your disposal https://codesandbox.io/s/runtime-hill-c77o1v?file=/src/App.tsx
Gabriel, thanks a lot!!! Just one follow-up: is there any way to find out (is video running or not at the moment)? Just for the case user instead of clicking my button is using Youtube controls to switch play/pause?
Hi, can i do this in the .jsx file
@chenelias Hi, yes you can do it in the .jsx file. Just remove the typing from the typescript.
If you can't, I can help you.
Thanks for the examples, @GabrielCastilhoV . Really helpful.