Question

I've been working on embedding a youtube playlist with Javascript and I can't change the theme to light. All the other parameters work but this one doesn't come through.

This is how think it should work:

  var defoptions = {
        autoplay: false,
        user: null,
        playlist: null,
        carousel: createCarousel,
        player: createPlayer,
        thumbnail: createThumbnail,
        max_results: 25, // does not apply to playlists
        loaded: function () {},
        playopts: {
            autoplay: 0,
            egm: 1,
            autohide: 1,
            fs: 1,
            showinfo: 0,
            rel: 0,
            theme: light
        }
    };

Any thoughts?

Thanks!

Here you have the whole thing, it's far from finished but first I need to find out how to change the theme.

<style>

#container{
    background-color: #F1F1F1;
    padding: 20px;
}

.yt-descript{
    max-width: 100px;
    font-family: verdana;
    font-weight: bold;
    font-size: 9pt;
    margin: 2px;
}


.player {
    width: 100%;
    height: 305px;
    overflow: hidden;
    background-color: #F1F1F1 ;
    position: relative;
}



.youtube .carousel {
    width: 20%;
    height: 100%;
    overflow-y: auto;
    overflow-x: hidden;
    position: absolute;
    right: 0px;
    z-index: 3;
}
.youtube .thumbnail {
    margin-left: 2px;
    width: 90%;
    border: 1px solid black;
}
.youtube iframe.player {
    width: 80%;
    height: 100%;
    overflow: auto;
    border: 0;
}

</style>

<script>

(function () {
    function createPlayer(jqe, video, options) {
        var ifr = $('iframe', jqe);
        if (ifr.length === 0) {
            ifr = $('<iframe scrolling="no">');
            ifr.addClass('player');
        }
        var src = 'http://www.youtube.com/embed/' + video.id;
        if (options.playopts) {
            src += '?';
            for (var k in options.playopts) {
                src += k + '=' + options.playopts[k] + '&';
            }
            src += '_a=b';
        }
        ifr.attr('src', src);
        jqe.append(ifr);
    }

    function createCarousel(jqe, videos, options) {
        var car = $('div.carousel', jqe);
        if (car.length === 0) {
            car = $('<div>');
            car.addClass('carousel');
            jqe.append(car);

        }
        $.each(videos, function (i, video) {
            options.thumbnail(car, video, options);
        });
    }

    function createThumbnail(jqe, video, options) {
        var imgurl = video.thumbnails[0].url;
        var img = $('img[src="' + imgurl + '"]');
        var desc;
        var container;
        if (img.length !== 0) return;
        img = $('<img align="left">');
        img.addClass('thumbnail');
        jqe.append(img);
        img.attr('src', imgurl);
        img.attr('title', video.title);
        img.click(function () {
            options.player(options.maindiv, video, $.extend(true, {}, options, {
                playopts: {
                    autoplay: 1
                }
            }));
        });
        desk = $('<p class="yt-descript">' + video.title + '</p>');
        jqe.append(desk);
        desk.click(function () {
            options.player(options.maindiv, video, $.extend(true, {}, options, {
                playopts: {
                    autoplay: 1
                }
            }));
        });
    }

    var defoptions = {
        autoplay: false,
        user: null,
        playlist: null,
        carousel: createCarousel,
        player: createPlayer,
        thumbnail: createThumbnail,
        max_results: 25, // does not apply to playlists
        loaded: function () {},
        playopts: {
            autoplay: 0,
            egm: 1,
            autohide: 1,
            fs: 1,
            showinfo: 0,
            rel: 0
        }
    };


    $.fn.extend({
        youTubeChannel: function (options) {
            var md = $(this);
            md.addClass('youtube');
            md.addClass('youtube-channel');
            var allopts = $.extend(true, {}, defoptions, options);
            allopts.maindiv = md;
            var JSONurl = "";
            if (allopts.playlist) {
                JSONurl = 'http://gdata.youtube.com/feeds/api/playlists/' + allopts.playlist + '?alt=json-in-script&format=5&callback=?';
            } else if (allopts.user) {
                JSONurl = 'http://gdata.youtube.com/feeds/users/' + allopts.user + '/uploads?alt=json-in-script&max-results=' + allopts.max_results.toString() + '&format=5&callback=?';
            } else {
                console.log('user or playlist must be specified');
            }
            $.getJSON(JSONurl, null, function (data) {
                var feed = data.feed;
                var videos = [];
                $.each(feed.entry, function (i, entry) {
                    var video = {
                        title: entry.title.$t,
                        id: entry.link[3].href.match('[^/]*$'),
                        thumbnails: entry.media$group.media$thumbnail
                    };
                    videos.push(video);
                });
                allopts.allvideos = videos;
                allopts.carousel(md, videos, allopts);
                allopts.player(md, videos[0], allopts);
                allopts.loaded(videos, allopts);
            });
        }
    });

})();


// Playlist
$(function () {
    $('#player1').youTubeChannel({
        playlist: 'PLFE3E2A9A3BDD70BE'
    });
});



// Channel
$(function () {
    $('#player3').youTubeChannel({
        user: 'YTusername',
        max_results: 50
    });
});
</script>

<div id="container">
<h1>Latest Videos</h1>
<div id="player1" class="player"></div>
</div>
Was it helpful?

Solution

Theme needs to value string values, so try this:

var defoptions = {
    autoplay: false,
    user: null,
    playlist: null,
    carousel: createCarousel,
    player: createPlayer,
    thumbnail: createThumbnail,
    max_results: 25, // does not apply to playlists
    loaded: function () {},
    playopts: {
        autoplay: 0,
        egm: 1,
        autohide: 1,
        fs: 1,
        showinfo: 0,
        rel: 0,
        theme: "light",
        color: "white"
    }
};
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top