Make embedded YouTube Playlist start at random index

Najm

I've been searching for a way to make my embedded playlist start with a random video.

This is what I tried:

<iframe src="https://www.youtube.com/embed/videoseries?list=PLPmj00V6sF0s0k3Homcg1jkP0mLjddPgJ&index=<?php print(rand(1,11)) ?>?rel=0&autoplay=1&showinfo=0&controls=0&authide=0&iv_load_policy=3&?modestbranding=1" frameborder="0"  allowfullscreen></iframe>

Sadly, this does not work for some reason. Neither did it with echo. Other solutions (as well few on stackoverflow https://shrty.top/j) did not work either. Any ideas?

Najm

Got it. This works:

<html>

<head>
    <script>
        var videos = ["https://www.youtube.com/embed/9bZkp7q19f0", "https://www.youtube.com/embed/dQw4w9WgXcQ"];
        window.onload = function () {
            var playerDiv = document.getElementById("random_player");
            var player = document.createElement("IFRAME");
            var randomVideoUrl = videos[Math.floor(Math.random() * videos.length)];
            player.setAttribute('width', '640');
            player.setAttribute('height', '390');
            player.setAttribute('src', randomVideoUrl);
            playerDiv.appendChild(player);
        };
    </script>
</head>

<body>
    <div id="random_player" />
</body>

</html>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

How to disable "related videos" from an embedded youtube playlist

From Dev

Youtube embedded playlist diplays playall button instead of the first video

From Dev

Make a playlist (start next song) in swift

From Dev

How can I download a youtube playlist with youtube-dl and make it a mp3-playlist?

From Dev

Download YouTube videos from start of batch to end of batch that is part of a playlist

From Dev

Download YouTube videos from start of batch to end of batch that is part of a playlist

From Dev

Embed youtube playlist with index; thumbnail is always first video

From Dev

how to make playlist of youtube links in my activity in android?

From Dev

How can I make youtube-dl return the creator of a playlist?

From Dev

Youtube embedded video won't start

From Dev

Youtube embedded video won't start

From Dev

Background Playlist Youtube Videos

From Dev

YouTube playlist length

From Dev

SublimeVideo Youtube and playlist

From Dev

Get reference to youtube playlist

From Dev

YouTube playlist length

From Dev

Extract youtube playlist videos

From Dev

Order of the youtube Playlist api

From Dev

Get Youtube playlist by Title

From Dev

YouTube Playlist Download

From Dev

Random, shuffle JavaScript playlist

From Dev

No play button in embedded Spotify playlist

From Dev

How to make a YouTube embedded video a full page width one?

From Dev

How to make youtube embedded video load only when box appears

From Dev

Youtube.Playlist.list ReferenceError

From Dev

Adding video to playlist with Youtube API

From Dev

Youtube API create playlist and embed

From Dev

Youtube Playlist to Listview in Android Studio

From Dev

Get YouTube playlist videos anonymously

Related Related

HotTag

Archive