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

How can I play/pause video programmaticaly (by click of a button) and get the timecode?

Open lofti198 opened this issue 3 years ago • 10 comments

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 image

How can I do that? Thank you in advance!

lofti198 avatar May 22 '22 03:05 lofti198

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

GabrielCastilhoV avatar Jul 24 '22 14:07 GabrielCastilhoV

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?

lofti198 avatar Jul 29 '22 17:07 lofti198

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 avatar Jul 29 '22 19:07 lofti198

@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

GabrielCastilhoV avatar Jul 30 '22 15:07 GabrielCastilhoV

In case you need something more precise, you can shorten the break time (line 81)

GabrielCastilhoV avatar Jul 30 '22 15:07 GabrielCastilhoV

Oh that is completely cool example! Thank you! Can I somehow donate to thank you?

lofti198 avatar Jul 30 '22 17:07 lofti198

You were the first person I helped on github :)

If possible follow me here on github, I want to improve my network

GabrielCastilhoV avatar Jul 31 '22 13:07 GabrielCastilhoV

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 avatar Jan 06 '23 14:01 chenelias

@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.

GabrielCastilhoV avatar Jan 07 '23 13:01 GabrielCastilhoV

Thanks for the examples, @GabrielCastilhoV . Really helpful.

lcnogueira avatar Jul 13 '23 02:07 lcnogueira