How to embed youtube videos as playlist [closed] - youtube

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I have numerous youtube video clips, and I was wondering if it is possible to embed them on the site as youtube playlist, so that the next video starts playing automatically once the clip finishes. Is there such functionality either with YouTube API or without. If not possible, what would be the best approach. Thanks in advance.

Actually there are two ways to embed playlists from youtube.
In the first method you can directly specify all the videos that you want to play in the embed player.
<iframe width="720" height="405" src="https://www.youtube.com/embed/VIDEO_ID?playlist=VIDEOID_1,VIDEOID_2"frameborder="0" allowfullscreen>
Each video ID must be separated by using comma.
Secondly, you can embed a playlist that is already present in youtube using the playlist ID
<iframe width="720" height="405" src="https://www.youtube.com/embed/?listType=playlist&list=PLAYLIST_ID" frameborder="0" allowfullscreen>

I found the solution,
http://www.youtube.com/v/PRIMARYVIDEO_ID?version=3&loop=1&playlist=VIDEO_ID1,VIDEO_ID2
Where the VIDEO_ID1, and VIDEO_ID2... are the videos i want to include in the playlist.

https://developers.google.com/youtube/youtube_player_demo
<iframe id="ytplayer" type="text/html" width="100%" height="405"
src="https://www.youtube.com/embed/?listType=playlist&list=PL590L5WQmH8eYTXiTTjzo4YnK7vkCqZTI"
frameborder="0" allowfullscreen>

You can simply use embedded playlists.
Here is an example of one of my playlists!
<iframe width="560" height="315" src="http://www.youtube.com/embed/videoseries?list=PLZtX_kbNpbDjYSUj-huH5pOKxifUNDi1O" frameborder="0" allowfullscreen></iframe>
In addition you could use the Javascript Player API to create custom behavior.

From the youtube docs
Embed a playlist
Sign in to your YouTube account on a computer.
On the left side of
the page, select the playlist you want to embed.
Copy the playlist ID from the URL.
Modify the embed code for an individual video by doing the following: In the place of the video ID (after "embed/"), substitute "videoseries?list=". Then paste the playlist ID after the "=".
Paste the code into your blog or website HTML.
Example:
<iframe width="560" height="315" src="https://www.youtube.com/embed/videoseries?list=PLx0sYbCqOb8TBPRdmBHs5Iftvv9TPboYG" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>

Related

how to loop two videos using youtube iframe code

I use the following code in my web page to successfully autoplay and loop one video. Now, I'd like to add another video, essentially looping two videos. So, after one video is finished playing, the second video will start to play, and then the first video, and so on, and so froth. How should the code be modified to do that?
<iframe width="560" height="315" src=
"https://www.youtube.com/embed/51xS4yXbryc?
rel=0&version=3&playlist=51xS4yXbryc&loop=1
&autoplay=1" frameborder="0" allowfullscreen=""></iframe>
That is a one-line code. I break it into four lines so it's easier to read.
For add more than one video in your iframe, you can use the following code:
https://www.youtube.com/embed/<VIDEO_ID_1>?rel=0&version=3&playlist=<VIDEO_ID_2>,<VIDEO_ID_3>,<VIDEO_ID_N>&loop=1&autoplay=1
Where:
VIDEO_ID_1: is the first videoId to reproduce.
VIDEO_ID_2, VIDEO_ID_3, VIDEO_ID_N and so on will be the videoIds you want include.
In this way, you can include a max of 196 or 200 videos in the same iframe1 that will autoplay and loop once the final videoId is reached.
This is a small sample with 4 videos on it.
This is another sample with 93 videos on it.
If you check this playlist, you'll see that it has more than 1000 videos on it - (1653 videos to be exact), but, the iframe resets the threshold to 196 or 200 videos approximately.
1 I discover this threshold when I tried to answer this question in Stack Overflow and you can check it by yourself if you enter to the Youtube website - this playlist and check that it will show only the first 200 videos on it.
This might be a threshold set (and undocumented) by YouTube.
A similar question was asked before about iframe and looping. I found this from another question on stackoverflow, a youtube link has a special ? parameter: autoplay. For example in this link
src="https://www.youtube.com/embed/M7lc1UVf-VE ?&autoplay=1& loop=1&rel=0&showinfo=0&color=white&iv_load_policy=3&playlist=M7lc1UVf-VE"
Try adding ?&autoplay=1& considering that worked for someone else.
I found it from
here
Update
If you wanna play multiple videos you can do it simply and embed a
playlist. You can find how to do so in this article at the
Embed a playlist section. Hope this helps.

Embed recently uploaded youtube video

I want to automatically embed my recently uploaded video from my YouTube channel in the sidebar of my website.
I got a good answer but it include user id they asked for
youtube.com/user/SomeName but in my case, it's like youtube.com/CHANNEL/name. I tried replacing "SomeName" with my channel id, but it didn't work for me
Thanks everyone for your answer. I found a pretty easy way to do this
All you need is id for your upload playlist and to find that visit google API explorer
Services > YouTube Data API v3 > youtube.channels.list
fill in the part section with "contentDetails"
and id section with youtube channel id (the one starts with UC)
scroll down and click on execute
you will find
"uploads": "UUIprTMT-TDysEDx03YMcS5Q",
in ** "relatedPlaylists"** section
copy that tag and now use this code to embed
<div style="position:relative;height:0;padding-bottom:56.25%"><iframe src="https://www.youtube.com/embed/videoseries?list=YOUR_UPLOAD_TAG" width="640" height="360" frameborder="0" style="position:absolute;width:100%;height:100%;left:0" allowfullscreen></iframe></div>
Test on fiddle
And you are done :)
You can embed youtube channels or playlists, as said here:
https://stackoverflow.com/a/30089630/7733026
Here is how to embed a channel
<iframe width="600" height="340" src="http://www.youtube.com/embed?max-results=1&controls=0&showinfo=0&rel=0&listType=user_uploads&list=YOUR_CHANNEL_NAME_HERE" frameborder="0" allowfullscreen></iframe>
To get your channel name click "My Channel" and its the line of text
after "/user/".
You can also embed playlists with this:
<iframe width="600" height="340" src="https://www.youtube.com/embed/+lastest?list=PLAYLIST_ID" frameborder="0" allowfullscreen></iframe>
Firstly, many options have been removed from the API from V2 to V3.
A few things still remain, but are not going to help unless you know that it will be used.
One is the user name. Legacy Usernames are still around for channels that are old enough, but newer ones will not have them.
This is normally the Title of the page, but the title can now be changed.
This is where the ID's come into it. Everyone has a unique ID, but can have the same Tile as another page. (even if confusing some times)
Example of an old channel is Google
https://www.youtube.com/user/Google
The "user" name is a Legacy name.
But all channels old and new will have a "Channel" as well
https://www.youtube.com/channel/UCK8sQmJBp8GCxrOtXWBpyEA
Note that it will give you an ID rather than a name.
So to get you what you are looking for, will need to be thought through.
Will the channel have a legacy user name? Do you need to show a name? or do you only want to find the last uploaded video regardless of name?
Best practice today will be to use the ID. Then with the API, get the relevant information that you need.
Step one is to call
https://www.googleapis.com/youtube/v3/channels?part=contentDetails,id,snippet&id=[THE_CHANNEL_ID]&key=[apiKey]
The contentDetails section will contain an uploads portion.
This will be the user uploads to the channel and will start with UU
Though a short cut will be to take the channel ID starting with UC and change it to UU. But I would recommend the API approach for security and peace of mind.
Then with the uploads playlist ID (the one starting with UU), you can call
https://www.googleapis.com/youtube/v3/playlistItems?part=id,snippet,contentDetails&maxResults=1&playlistId=[PLAYLIST_ID]&key=[api-key]
Normally the first in the array will be the last one in. The newest one. So setting results to 1 will give only the first in the array.
If you want to do further checks to make sure, then set results to 50 and use the contentDetails to dig the uploaded time of the video and select the newest that way.

Youtube embedded player - show no recommendations (videos) at the end?

I have an am bedded youtube video in my site, but at the end of it, Youtube displays a set of recommendations (other videos) which I'd like to remove since they have nothing to do with my video.
Is that possible? Can't seem to find anything gin the Youtube embedded API :(
Just add ?rel=0 at the end of your video, &rel=0 no longer works
Example:
<iframe src="https://www.youtube.com/embed/hy9Cbp_yV5Y?rel=0"
width="100%" height="100%" frameborder="0"></iframe>
The trick is to attach to the player URL (http://www.youtube.com/v/Yc_J_kXaFSw) the rel=0 parameter.
The player URL will became http://www.youtube.com/v/Yc_J_kXaFSw&rel=0
The source of this information:
http://www.varesano.net/blog/fabio/disable%20related%20videos%20embedded%20youtube%20player
Just add &rel=0 at the end of your video url, this should remove the recommendations.

Play music on background , Ruby on rails

What is SIMPLE and good practice to play background music in Rails App.
It's a really simple rails website. It has several static pages.
How do I playing music on background?
thanks!
I am not looking for detailed answer or code.
I just want somebody kindly point me some links, or some keywords I can search.
I googled around and did not find what I want/ Or I didnt realize that was I need.
with HTML 5, you can now use the tag like this. You can place this on any page that you want your music to play on. (layouts/application.html.erb if you want site-wide)
<audio src="public/my_audio_file.mp3" autoplay controls loop>
<p>Your browser does not support HTML5 audio playback</p>
</audio>
This link provides further details and options
https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Using_HTML5_audio_and_video
Add this to the pages on which you want the sound
<embed src="path/to/background.mp3" autostart="true" loop="true" hidden="true"><embed>
Add it to the layout if you want it in all the pages

Change language for YouTube embed

Does anyone know if it's possible to change the language of the Youtube embed player. For example, to change things like "Full Screen", "Change Quality" etc into German?
Thank you.
How are you embedding it? If it's simply with the embed url, you can do something like adding the parameters "hl=de" and "persist_hl=1" to the url. Like so:
<iframe id="ytplayer" type="text/html" width="640" height="360" src="https://www.youtube.com/embed/M7lc1UVf-VE?hl=de&persist_hl=1" frameborder="0" allowfullscreen>
I've only found out about "persist_hl" by adding "hl=de" to a basic youtube page and checking what the url to display youtube in german was. I haven't found any info about it and what it does.
Edit:
I doubt my answer is valid. The "persist_hl" parameter will change the user's cookies for youtube's site and force the new language.
Edit 2:
Looks like you shouldn't force the language anyways as it should depend on the user's preference: https://stackoverflow.com/a/12696747/1372543
The answer's from Jeff Posnick, who works for Google. I feel it applies to your question.

Resources