Skip to content

Instantly share code, notes, and snippets.

@blairanderson
Last active February 4, 2022 21:10
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save blairanderson/bd9b8f25b3964aa4c071670e9bbaf2fe to your computer and use it in GitHub Desktop.
Save blairanderson/bd9b8f25b3964aa4c071670e9bbaf2fe to your computer and use it in GitHub Desktop.
Fullscreen Background Video Slideshow on iOS devices - note currently uses jquery :)
{% for video in site.static_files %}
{% if video.path contains 'img/videos' %}
<video muted playsinline>
<source src="{{ site.baseurl }}{{ video.path }}" type="video/mp4">
</video>
{% endif %}
{% endfor %}
window.__next_video = 0;
function playNextVideo() {
if (window.__next_video === $('video').length) {
window.__next_video = 0;
}
playVideoAtIndex(window.__next_video);
window.__next_video++;
}
function playVideoAtIndex(index) {
$('video').each(function(i, video) {
var $vid = $(video);
var vid = $vid[0];
$vid.off('ended');
$vid.fadeOut('fast');
if (index === i) {
vid.load();
vid.play();
$vid.fadeIn('fast');
$vid.on('ended', playNextVideo);
}
});
}
playNextVideo();
@blairanderson
Copy link
Author

@KevinFremon i also hope you see this. You should post some code here otherwise I cannot tell what you have added/changed.

@KevinFremon
Copy link

KevinFremon commented Sep 27, 2019

@blairanderson - That would be helpful, wouldn't it. :)

Here is my very minimal re-write:

(function(){
    window.__next_video = 0;

      function playNextVideo() {
          if (window.__next_video === $('#hs_cos_wrapper_{{ name }} video').length) {
            window.__next_video = 0;
          }
          playVideoAtIndex(window.__next_video);
          window.__next_video++;
        }

        function playVideoAtIndex(index) {
          $('#hs_cos_wrapper_{{ name }} video').each(function(i, video) {
            var $vid = $(video);
            var vid = $vid[0];
            $vid.off('ended');
            $vid.fadeOut('0');
            if (index === i) {
              vid.load();
              vid.play();
              $vid.fadeIn('0');
              $vid.on('ended', playNextVideo);
            }
          });
        }

    playNextVideo();  
}())

The only main difference is the #hs_cos_wrapper_{{ name }} proceeding VIDEO. This is basically generates a unique ID and helped me at least get as far as to have the videos play on multiple rows.

Thanks man! You're a lifesaver.

@blairanderson
Copy link
Author

blairanderson commented Sep 27, 2019 via email

@KevinFremon
Copy link

@blairanderson Thank you so much for pointing that out! I'll adjust that and give it a try.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment