79733390

Date: 2025-08-12 15:26:18
Score: 0.5
Natty:
Report link

The reason your code isn’t working is because YouTube’s getPlayerState() and Vimeo’s getPaused() don’t return results instantly — you need to use their APIs properly.

YouTube Example:

<script src="https://www.youtube.com/iframe_api"></script>
<iframe id="yt-player" width="560" height="315"
    src="https://www.youtube.com/embed/n1tswFfg-Ig?enablejsapi=1"
    frameborder="0" allowfullscreen>
</iframe>

<script>
let ytPlayer;

function onYouTubeIframeAPIReady() {
    ytPlayer = new YT.Player('yt-player', {
        events: {
            onReady: checkYTState
        }
    });
}

function checkYTState() {
    // 1 = playing, 2 = paused
    const state = ytPlayer.getPlayerState();
    console.log('YouTube state:', state);
}
</script>

Vimeo Example:

<script src="https://player.vimeo.com/api/player.js"></script>
<iframe id="vimeo-player" src="https://player.vimeo.com/video/237596019"
    width="640" height="360" frameborder="0" allowfullscreen>
</iframe>

<script>
const vimeoPlayer = new Vimeo.Player('vimeo-player');

function checkVimeoState() {
    vimeoPlayer.getPaused().then(function(paused) {
        console.log('Vimeo paused:', paused);
    });
}

checkVimeoState();
</script>
Reasons:
  • Blacklisted phrase (1): youtube.com
  • Long answer (-1):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: Asfand Yar