Skip to content

Youtube video is not pausing when change the slide #192

Answered by igordanchenko
aalampalli asked this question in Q&A
Discussion options

You must be logged in to vote

I do not see you even trying to obtain the player object. Calling a method of an undefined object is not going to magically work.

Here is how you can solve this problem:

  1. Load YouTube Iframe API in advance (either on a page load or add it as a global script in your app)
  2. Implement YouTube slide as a functional component instead of an inline render function. Create YouTube player object by passing it an iframe ref. Create an effect that runs when offset !== 0 and pause video if it's playing.

Alternatively, you can use a 3rd-party library like react-youtube as you may find it easier to use.

p.s. Please consider formatting your code in the future, as good manners can go a long way.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by igordanchenko
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants