Video should be in the off state

That issue is fixed by:

Replacing this:

 function shufflePlaylist(player) {
        player.setShuffle(true);
        player.playVideoAt(0);
        player.pauseVideo();
    }

    function onPlayerReady(event) {
        player = event.target;
        player.setVolume(100); // percent
        shufflePlaylist(player);
    }

    function onPlayerStateChange(event) {
        player = event.target;

With this:
https://jsfiddle.net/knrb1w09/

    function onPlayerReady(event) {
        player = event.target;
        player.setVolume(100); // percent
    }

    let hasShuffled = false;

    function onPlayerStateChange(event) {
        player = event.target;
        const shufflePlaylist = true;

        if (!hasShuffled) {
            player.setShuffle(shufflePlaylist);
            player.playVideoAt(0);
            hasShuffled = true;
        }

Which issue?

The first set of code is much better than the second set of code.

This one:
https://jsfiddle.net/quabrytc/1/

When the cover is clicked on the playlist player, the video should be in the off state.

    function shufflePlaylist(player) {
        player.setShuffle(true);
        player.playVideoAt(0);
        player.pauseVideo();
    }

    function onPlayerReady(event) {
        player = event.target;
        player.setVolume(100); // percent
        shufflePlaylist(player);
    }

The single player on the right is in the off state when it is clicked on.

The playlist player on the left is in the on state when it is clicked on when it should be off , looking the same as the right player.

I tried moving stuff around but I wasn’t able to figure it out.

We can stop the video instead of pausing it.

    function shufflePlaylist(player) {
        player.setShuffle(true);
        player.playVideoAt(0);
        player.stopVideo();
    }

That’s an option, but I find the other way more beneficial.

The other way, that one being where on every changing event of the player the need to shuffle is checked all over again?

This way
Trying to get Shuffle Playlist to work

I find it useful in certain situations.

For instance, if autoplay is being used, or if it is not being used.

Works good for both instances.
https://jsfiddle.net/knrb1w09/

    function onPlayerReady(event) {
        player = event.target;
        player.setVolume(100); // percent
    }

    let hasShuffled = false;

    function onPlayerStateChange(event) {
        player = event.target;
        const shufflePlaylist = true;

        if (!hasShuffled) {
            player.setShuffle(shufflePlaylist);
            player.playVideoAt(0);
            hasShuffled = true;
        }

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.