0

This wasn't a problem for me until a few months ago. I thought YouTube had changed something in their API for Iframe Embeds, as they often do, but for this particular case, I am not sure.

I use the following code as suggested by the docs but my problem comes when I try to add a custom playlist using selected IDs.

<div id="player"></div>

<script>
// 2. This code loads the IFrame Player API code asynchronously.
var tag = document.createElement('script');

tag.src = 'https://www.youtube.com/iframe_api';
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);

// 3. This function creates an <iframe> (and YouTube player)
//    after the API code downloads.
var player;

function onYouTubeIframeAPIReady() {
    player = new YT.Player('player', {
        height: '390',
        width: '640',
        videoId: 'M7lc1UVf-VE',
        playerVars: {
            'playsinline': 1,
            'playlist': '$playlist'
        },
        events: {
            'onReady': onPlayerReady,
            'onStateChange': onPlayerStateChange
        }
    });
}
</script>

The iframe loads and plays the videos in some cases but will fail most of the time displaying the message "This video is unavailable".

Forexample, loading a playlist of songs from Imagine Dragon :

fKopy74weus,izhxTx4LVWo,rGlEZpOVjGo,7wtfhZwyrcc,1nv9br7P7g0,dvPfgVGFu6k,1SrEE6zwnW8,LeaydhTew3U,dvuxxVKZ1eQ,It_Ae6XSPzw,f242R8si7qU,z0a9k1gSMsw,trig1MiEo1s,U5x96y4mApI

will not work, but if I load songs from say, Olivia Rodrigo:

hM2U8cb8lhI,6tsu2oeZJgo,ZmDBbnmKpqQ,w-HfMiue7-k,cii6ruuycQA,gNi_6U5Pm_o,AqRXiQkyxvI,ZQFmRXgeR-s,Z-9gQjUZMm0,AyX_LL9nWSE,ZLlsmB1D4Q0

the player will load and play all the videos just fine.

However, If I load a single video from either artist, it will play without any problems.

What could be the issue here?

Thanks.

0 Answers0