Over the years it seems YouTube has made it more and more difficult, or tricky shall we say to embed your YouTube channel into your website. It used to be a simple click here and click there and you’re off to the races. Lately, it’s a little more painful. I’ve spent countless hours scouring the internet for ways to accomplish this task only to find thousands upon thousands of articles covering older methods of doing this that do not work anymore.
The other day I happened to stumble upon a great little website that offers the ability to edit code directly online and get immediate feedback for how that code will render. The website I found is known by some and probably unknown to many. It is called JsFiddle and can be found at www.jsfiddle.net I encourage coders to head on over and check it out. It is a great little online testing environment.
The code I found was created by a Simone Gianni using the JsFiddle site to draft it up and test it out. He has two versions online on JsFiddle. One version just shows your channel in a typical YouTube API Player and the other shows your channel with a nifty sidebar / carousel displaying other videos from your YouTube channel.
The sidebar / carousel version is the one that suits the needs for me and so I decided to go with that one. (I should also mention that the first version does not function in Internet Explorer). I thought it could be improved upon, so I added in a little extra code to not only just display thumbnails of the other videos, but also display their title off to the right as illustrated below. The scripting includes CSS, Javascript based on JQuery 1.5.2 and very minimal HTML code to place the container DIV on your page.
I’ve implemented this handy little widget of sorts on the home page of www.mentalwellnesstoday.com so that you can see it in action.
Know of any other cool JsFiddles? Share!
I’m a little confused by the HTML option on that page. It looks a little small. I’m trying to simply cut and paste into the HTML area of my new WordPress.org site. The carousel option would be perfect for me. Could you help a newbie out? I was hoping for an option that would just involve plugging in my YouTube channel name.
Love your code. but im a beginner, so how does it work? can you give me example files to download???
please?
Hi guys. Jack, if you’d like to, send me an email and I’ll package up the files for you.
The implementation of this is easier than it looks. On the JsFiddle page for this code there are 4 boxes, the HTML, Javascript/JQuery, CSS and the Demo – live view of the code in action.
First and foremost, in the Javascript box / frame scroll to the bottom and change the User: “MagpieMedia1” to your YouTube user name.
HTML: Place the content of the HTML box anywhere on your page where you would like the YouTube player to appear. Only include the DIV…./DIV portion, leave out the html and body tags as you’ll already have these tags on your page. They are only there to illustrate a complete, though very basic, HTML document.
Javascript: The code inside this frame should be placed on your document between the head tags, or for a little more of an efficient HTML document, just before the closing body tag. The best thing to do to properly grab this code, is to right click inside the live view frame and choose This Frame > View Source (browser dependent) or a similar function for your internet browser. Then there are 2 things to copy to your HTML document;
1) The call to the Jquery Library:
2) The Javascript code itself:
all the way down to and inlcuding:
The Style content (the CSS) can either be placed in document between the head tags as it will appear in the Live View source code, or in an external style sheet with a reference to it in the head section.
The code works by first retrieving the library of videos from your channel and collecting all required data (thumbnails, title etc…). It then begins to create the content within the [div id=”player”]… [/div] element on your page. It is very important that this div has the ID of “player” as the code explicitly looks for this element ID on the page to place the player inside of. The CSS also styles this based on the “player” ID.
Hope this helps!
Hi
I am a newbee too in html coding.
I tried to follow instrucitons but i am messingup somewhere.
Would it be possible for you to package me the html code with all the javascript and CSS in it ?
Thanks in advance
Dishcolala
Nice code thanks!
One question though:
How do you extend the Carousel to contain all your videos instead for being limited to 25?
Great question, truth is, I don’t exactly know why it limits itself to that. I’ll see if I can’t sort it out though.
Hi, im using the code right in one document, no syntax error. Changing de name on de last javascript line to my own channelname, right?
What’s going wrong? http://dirkfoesenek.nl/youtube.html
Hi. Try the following instead:
Found the solution to my post above: Youtube limits are default 25 vids, but you can change it to 50 by adding: max-results=50
In this line
$.getJSON(‘http://gdata.youtube.com/feeds/users/’ + allopts.user + ‘/uploads?alt=json-in-script&format=5&callback=?&max-results=50’
I’ll try to make a “load more videos” button in the end of the carousel should be possible…
because you can load another 50 with: start-index=51&max-results=50
I add I to this Danish travel site: http://www.albatros-travel.dk/omalbatros/albatrostv/Pages/Default.aspx
Thanks again.
Awesome! Thanks for sharing!
Awesome code! Thanks!
Would it be also possible to change the code to show a number of self defined videos, I mean to add a list of the video-IDs I wand to show, the first showing in the main window, the rest in the side bar?
Thanks!
Emil
This is lovely. GREAT WORK!!! Is there any way we could get one with the video list on the bottom so that the video being played is larger?
Good morning. This looks like the perfect solution to what I require but I am stumped as to how to make this word using a wordpress theme ?
If it isnt too much hassle, could you please explain how to do this ? Many thnks
Is it possible to load a playlist instead of a channel?
Super awesome code 😀 But it really needs some tweaking to do exactly what I need.. Can someone assist me doing a carrousel like this: http://www.ikosweb.com/regio/video.jpg
I need a carrousel *horizontal (with no thumbs, but players) Please if you know how the workaround I-d be extremely grateful!!
Im planning on using this code for my site but have a few questions, what would be the best way to contact you?
This code is absolutely great Tom!
I do have one question though.
My original idea using this code was to load a channel and break thumbnails down into categories (tags). But I couldn’t find any documentation to built that, so I am now trying first to load my channel with all available videos, and then load every single category in a hidden div – by using /-/tag_name in the url as described in Youtube API docs. I am using a variable to store the different category names and then parse them into the $.getJSON url. First call goes fine (all videos), but all calls after that (using my variable) breaks.
Any help would be appreciated. Thanks
Hey! Great code and I find it really useful. But what should I change if I want to have fx the video frame in a column of my webpage and the carousel with the other videos in another column of the same page? like having them in two different divs. I’m trying to understand it but I’m not a JavaScript expert at all.
Thank you for your help!
Hi thanks for that link I have updated it at http://jsfiddle.net/Zbbbv/1068/ to fit a widescreen player,
You can see it in action at my site at http://emptychairfilms.tv
Cheers Geoff
Very cool, good work!
Is there a way to do a similar player with a Vimeo channel ? I’m not keen on the existing Vimeo Hubnut.
This is great! One question though. I want to have two columns for the thumbnails so need to wrap the image and desc inside of a DIV I can float. Tried a couple of methods but nothing really works. Any help would be great.
Here is a much easier way. Go an make a new playlist with every video you have. (select all check box) then make this play list private. play the play list. pause the video, Share the video, making sure the playlist option is selected. Click embedded link, copy past, change your width and high Bam! Done…
Here is mine
(FYI it’s my shitty travel blog, doesnt have to look pretty, just be easy for my family and friends to navigate and see whats up.. hence all the damn widgets.)
http://jaredtravels.blogspot.jp/p/video-gallery.html
I got it to work. Question though. I am using it on a site where I am including it on each of the member pages that I’m building. Is it possible to have php print the youtube channel name instead of manually retyping?
I would imagine so. There may be a way to interact with the API to do it, otherwise it would involve some conditionals such as if pageUrl = page1 channel=thischannel1 elseif pageUrl=page2 channel = thischannel2. Or if you had a series of channels and pages to factor, a switch statement would be more efficient.
Either way you could build it as a function and call the function where the channel name is called in the Javascript. Just insert php tags and then echo the functions result.