S
S
stichii2016-05-25 17:24:01
YouTube
stichii, 2016-05-25 17:24:01

How to change the preview in the video?

Good afternoon! According to this article, I am optimizing the loading of a website page from a YouTube video.
Here is the jQuery code

$(function() {
    $(".youtube").each(function() {
        // Based on the YouTube ID, we can easily find the thumbnail image
        $(this).css('background-image', 'url(http://i.ytimg.com/vi/' + this.id + '/sddefault.jpg)');

        // Overlay the Play icon to make it look like a video player
        $(this).append($('<div/>', {'class': 'play'}));

        $(document).delegate('#'+this.id, 'click', function() {
            // Create an iFrame with autoplay set to true
            var iframe_url = "https://www.youtube.com/embed/" + this.id + "?autoplay=1&autohide=1";
            if ($(this).data('params')) iframe_url+='&'+$(this).data('params');

            // The height and width of the iFrame should be the same as parent
            var iframe = $('<iframe/>', {'frameborder': '0', 'src': iframe_url, 'width': $(this).width(), 'height': $(this).height() })

            // Replace the YouTube thumbnail with YouTube HTML5 Player
            $(this).replaceWith(iframe);
        });
    });
});

That is, this code loads the preview first, and when you click on the picture, it already loads the video.
The problem is that not all videos have a picture, some have it instead of a picture. 087dee798417471e8af299c301501dde.jpg
Can you please tell me if it is possible for such videos to set up their own picture?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question