Impressive, i was also looking for the same. Thanks for sharing about it.
Update:
I have a question towards the bottom.
I had come upon this:
Custom Playlist
To load your own (database driven or hand edited) playlist in a player you need an embed code similar to this:
Note that you need to specify a video id â which acts as the first video â and the playlist parameter, which needs to be a comma-separated list of video ids.
<iframe width="560" height="315" src="https://www.youtube.com/embed/wyejXA9sZtE?playlist=,mnfmQe8Mv1g,ZPz3wzPlruA,-Xgi_way56U,CHahce95B1g,PEJpJ1UKQpg,u8hvzxYSPjQ,qYEooPeyz5M,Nbp8XZnzfT8,pIuWymsUuk0" frameborder="0" allowfullscreen></iframe>
So, it turns out this would be an acceptable way of doing it also.
This parameter specifies a comma-separated list of video IDs to play. If you specify a value, the first video that plays will be the VIDEO_ID specified in the URL path, and the videos specified in the playlist parameter will play thereafter.
I tried it here and it works:
https://jsfiddle.net/qnbyg5x9/169/
How would I be able to make this line less than 80 characters?
Would I be able to put this into an array somehow?
playlist: "mnfmQe8Mv1g,ZPz3wzPlruA,-Xgi_way56U,CHahce95B1g,PEJpJ1UKQpg,u8hvzxYSPjQ,qYEooPeyz5M,Nbp8XZnzfT8,pIuWymsUuk0"
Yes, thatâs because your newRandomNumber function is out of scope. Move it somewhere else so that itâs in scope, and things will be well.
By splitting up the string. For example:
var together = "This, that, and the other.";
var separated = "This, " +
"that, " +
"and the other.";
Where would this go:
var separated = "mnfmQe8Mv1g," "ZPz3wzPlruA,"
"-Xgi_way56U, "CHahce95B1g," "PEJpJ1UKQpg," "u8hvzxYSPjQ,"
"qYEooPeyz5M, "Nbp8XZnzfT8," "pIuWymsUuk0,";
In here?
Where am I placing it?
That wouldnât go anywhere, as itâs broken and syntactically invalid.
When you edit a post to add significantly more information, that information is most likely going to be unseen, because notifications do not get sent out about edited posts.
You told me this though.
var together = "This, that, and the other.";
var separated = "This, " +
"that, " +
"and the other.";
How would I make this valid?
var separated = "mnfmQe8Mv1g," "ZPz3wzPlruA,"
"-Xgi_way56U, "CHahce95B1g," "PEJpJ1UKQpg," "u8hvzxYSPjQ,"
"qYEooPeyz5M, "Nbp8XZnzfT8," "pIuWymsUuk0,";
Yes - which is quite different from what you posted.
How would I fix this, what did I do wrong here?
var separated = "mnfmQe8Mv1g," "ZPz3wzPlruA,"
"-Xgi_way56U," "CHahce95B1g," "PEJpJ1UKQpg," "u8hvzxYSPjQ,"
"qYEooPeyz5M," "Nbp8XZnzfT8," "pIuWymsUuk0,";
Look at the syntax highlighting, where red is for used to denote strings. Can you see whatâs wrong there?
Fixed here:
var separated = "mnfmQe8Mv1g," "ZPz3wzPlruA,"
"-Xgi_way56U," "CHahce95B1g," "PEJpJ1UKQpg," "u8hvzxYSPjQ,"
"qYEooPeyz5M," "Nbp8XZnzfT8," "pIuWymsUuk0,";
Those are still not syntactically valid.
Like this?
var separated = ["mnfmQe8Mv1g," "ZPz3wzPlruA,""-Xgi_way56U,"
"CHahce95B1g," "PEJpJ1UKQpg," "u8hvzxYSPjQ,"
"qYEooPeyz5M," "Nbp8XZnzfT8," "pIuWymsUuk0,"];
Throwing stuff at the wall to see what sticks, is not usually a useful technique.
I shall return in a while.
I got it working here:
Did I do this right?
Would const playlist go right underneath function addvideo?
function addVideo(video) {
const playlist = ["Nbp8XZnzfT8", "mnfmQe8Mv1g",
"ZPz3wzPlruA","-Xgi_way56U", "CHahce95B1g", "u8hvzxYSPjQ",
"PEJpJ1UKQpg", "pIuWymsUuk0", "qYEooPeyz5M"];
new YT.Player(video, {
videoId: video.dataset.id,
width: 606,
height: 344,
playerVars: {
autoplay: 1,
controls: 1,
rel: 0,
iv_load_policy: 3,
cc_load_policy: 0,
fs: 0,
disablekb: 1,
playlist: playlist.join(",")
},
events: {
"onReady": onPlayerReady,
"onStateChange": onPlayerStateChange
}
});
}
You could create an array the join it:
var str = [
"qwertyuiop",
"asdfghjkl",
"zxcvbnm"
].join(",");
but, when you have no need for the array, itâs much better to just concatenate the strings instead
var str = "qwertyuiop," +
"asdfghjkl," +
"zxcvbnm";
How would I get it working?
const playlist = "Nbp8XZnzfT8," +
"mnfmQe8Mv1g," +
"-Xgi_way56U," +
"CHahce95B1g," +
"u8hvzxYSPjQ," +
"qwertyuiop," +
"PEJpJ1UKQpg," +
"pIuWymsUuk0," +
"qYEooPeyz5M";
new YT.Player(video, {
videoId: video.dataset.id,
width: 606,
height: 344,
playerVars: {
autoplay: 1,
controls: 1,
rel: 0,
iv_load_policy: 3,
cc_load_policy: 0,
fs: 0,
disablekb: 1,
playlist: playlist.join(",")
},
events: {
"onReady": onPlayerReady,
"onStateChange": onPlayerStateChange
}
});
}
Or like this:
const playlist = ["Nbp8XZnzfT8," +
"mnfmQe8Mv1g," +
"-Xgi_way56U," +
"CHahce95B1g," +
"u8hvzxYSPjQ," +
"qwertyuiop," +
"PEJpJ1UKQpg," +
"pIuWymsUuk0," +
"qYEooPeyz5M"];
Do you know how to concatenate strings? Itâs a fundamental part of JavaScript that has already been demonstrated in this thread for you, many times over.
What youâre asking me to do seems confusing.
I donât understand how this:
const playlist = "Nbp8XZnzfT8," +
"mnfmQe8Mv1g," +
"-Xgi_way56U," +
"CHahce95B1g," +
"u8hvzxYSPjQ," +
"qwertyuiop," +
"PEJpJ1UKQpg," +
"pIuWymsUuk0," +
"qYEooPeyz5M";
Connects with this:
playlist: playlist.join(",")
Hereâs a good piece all about it then. You would do well to study this article carefully.