2
votes

Question:

Please, can someone explain exactly, clearly, how I can embed a simple Chromeless Youtube player in my page, and control the source of that player dynamically?

Question Explained: I'm working with a page where I need to embed a youtube video with no controls at all. After some research I found that a Chromeless video player is exactly that. But here's my problem:

  1. I have found little to no tutorial content on a Chromeless player, and being relatively new to Javascript, I'm having trouble understanding the documentation provided here in a way that I can apply it to my problem.

  2. I need to change sources of this video based on user interaction. I had originally, not yet being comfortable with the youtube javascript API, simply embedded the videos via static iframe and changed the source of the iframes via JQuery with .attr("src",nameofsource), not loading the embeds with javascript, only changing the sources.

That worked ok, I was able to hide most of the controls via the parameters that youtube accepts attached to the embed url, but there was absolutely no way to mute the video with that method, and the code was plain ugly, and I was not happy with it.

So I've started embedding the videos and changing the source all through the API, which works great, the video is muted, and changes source nicely, but now I'm faced with the issue of having the controls showing up.

According to the documentation I saw on a Chromeless Player, I didn't see that it was a matter of just adding a parameter to the javascript YT API, but something completely different.

Question Restated:

So please, can someone explain exactly, clearly, how I can embed a simple Chromeless Youtube player in my page, and control the source of that player dynamically?

There is no documentation that I have found on the internet that provides a satisfactory, comprehensive (friendly to new javascript developers) explanation of how to do this. As a new developer, I have looked into the documentation, but I am not yet experienced enough to effectively 'use the manual' on this one.

There were a few questions that I found on StackOverflow regarding a chromeless player, but none of them had even remotely satisfactory answers.

Known Documentation:

https://developers.google.com/youtube/flash_api_reference

https://developers.google.com/youtube/iframe_api_reference#Loading_a_Video_Player

http://viget.com/inspire/youtube-chromeless-video-jquery-plugin

Known Related StackOverflow Questions with inadequate answers:

[23K views, Inadequate Answer] : How do I go about embedding a youtube chromeless player without adding controls?

[1.4K views, Inadequate Answer] : How to make a YouTube chromeless player?

2
What exactly do you mean by "Chromeless"? No buttons at all?Pekka
Yes, exactly. No controls directly on the video. @Pekka웃user2700923
Also most ready-made player products should support turning off controls: videojs.com/docs/optionsPekka
Ahh hold on you want Youtube, one secPekka
VideoJS seems to be able to embed Youtube: How to play Youtube videos using Video.js? perhaps you can use that, not sure thoughPekka

2 Answers

3
votes

In your HTML you need:

<script src="https://www.youtube.com/iframe_api"></script>
<div id="player"></div>

Then in your JavaScript

var player;
function onYouTubeIframeAPIReady() {
    player = new YT.Player('player', {
        videoId: 'OJpQgSZ49tk',
        playerVars: {
            controls: 0,
            autoplay: 1,
            disablekb: 1,
            enablejsapi: 1,
            iv_load_policy: 3,
            modestbranding: 1,
            showinfo: 0
        }
    });
}

The onYouTubeIframeAPIReady function is called by YouTube's API when it's done loading. Additional parameters and other examples can be found on the documentation: https://developers.google.com/youtube/iframe_api_reference

0
votes

Youtube won't let you get rid of everything, but you could try http://mediaelementjs.com/ - that allows you to control the display of the controls, and hide them if you want.