I want to switch playlist with https://jsfiddle.net/g1xfh7rd/ but it does always reload the same initial playlist. I tried all solutions suggested YouTube Player API list with videos and it didn't work
<div id="ytplayer"></div>
<div onClick="loadPlaylist()">load another</div>
<script async src="https://www.youtube.com/iframe_api"></script>
<script>
// 1. ytplayer code: https://developers.google.com/youtube/player_parameters#IFrame_Player_API
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/player_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
var player;
function onYouTubePlayerAPIReady()
{
player = new YT.Player('ytplayer',
{
height: '390',
width: '640',
playerVars:
{
listType:'playlist',
list: 'RDEMe12_MlgO8mGFdeeftZ2nOQ'
}
});
}
function loadPlaylist() {
player.loadPlaylist('PLuvQYuQ7n4rAtqY1dDvhts08zBoisI8xA');
}
</script>
The IFrame player API lets you embed a YouTube video player on your website and control the player using JavaScript. Using the API's JavaScript functions, you can queue videos for playback; play, pause, or stop those videos; adjust the player volume; or retrieve information about the video being played.
Overview. Developers can use the iFrame API to programmatically create and interact with an Embed or with multiple Embeds in the same web app. The iFrame API includes methods that you can use to start playback, change the content rendering in an Embed, or stop playback.
Until and unless you have allow="autoplay;" in your iframe tag you wont be able to unmute the video. Add this attribute and further unMute function will work. Show activity on this post. Usually, you can just click the mute button to unmute it.
It works fine, if you use the object syntax of loadPlaylist() and add a player.stopVideo().
function loadPlaylist() {
player.stopVideo();
player.loadPlaylist({ list: 'PLuvQYuQ7n4rAtqY1dDvhts08zBoisI8xA' });
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With