playing prop not pausing youtube
See original GitHub issueBe sure to search for your issue before opening a new one.
Current Behavior
When playing
prop value changes to false
, the video still plays, however if I pause the video manually then the prop changes to true
it does start playing
So, only the false state is not working as expected
Expected Behavior
When my wrapper component sets the playing
state to false
the video should stop playing
Steps to Reproduce
Environment
- URL attempting to play: https://www.youtube.com/watch?v=YxPRZ9S-qbI
- Browser: chrome 78
- Operating system: mac os
- React 16.8.4
import React, { useEffect } from 'react';
import PropTypes from 'prop-types';
import { __ } from '@wordpress/i18n';
import YouTubePlayer from 'react-player/lib/players/YouTube'
import { Waypoint } from 'react-waypoint';
const Youtube = ( { youtubeId } ) => {
const [ paused, setPaused ] = React.useState( true );
return (
<Waypoint
onLeave={ () => setPaused( true ) }
onEnter={ () => setPaused( false ) }
>
<div>
{console.log(paused)}
<YouTubePlayer
url='https://www.youtube.com/watch?v=YxPRZ9S-qbI'
controls
playing={ ! paused }
// onPause={ () => setPaused( true ) }
// onPlay={ () => setPaused( false ) }
// onStart= { () => setPaused( false ) }
// onReady={ () => setPaused( true ) }
// onEnded={ () => setPaused( true ) }
/>
</div>
</Waypoint>
);
};
Youtube.propTypes = {
youtubeId: PropTypes.string.isRequired,
};
Other Information
I see the playing
prop change correctly when scrolling in the React devtools.
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (1 by maintainers)
Top Results From Across the Web
playing prop not pausing youtube · Issue #749 - GitHub
When playing prop value changes to false , the video still plays, however if I pause the video manually then the prop changes...
Read more >How To FIX YouTube Auto Pause Problem
... Pause Problem || YouTube Video Paused. Continue Watching? SOLVEDIsn't it annoying when YouTube pauses the video when it's playing for...
Read more >Youtube randomly pauses on pc? - Reddit
The only way to resolve this issue is to tap onto another open tab, go back to the tab where the video on...
Read more >how to play/pause video in React without external library?
So my first suggestion would be to consider refactoring. You can still technically do this with refs by giving your video component a...
Read more >YouTube Player API Reference for iframe Embeds
This function should be reserved for rare situations when you know that the user will not be watching additional video in the player....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This works, from a stackoverflow answer
I experienced the same behavior, a way to circumvent this is by getting the internal player instance and then pausing it that way:
this.player.getInternalPlayer().pauseVideo();