So I'm currently building a website that has a carousel containing four videos, each video is triggered to play by hooking in to the Bootstrap 3 carousel's slide.bs.carousel
event.
Each of the videos are embedded in the page like so:
<video id="somevideo" class="video-js vjs-default-skin m-hide" controls preload="auto" data-setup='{ "controls": false, "autoplay": false, "preload": "auto" }'>
<source src="somevideo.mp4">
<source src="somevideo.webmhd.webm">
</video>
Now, given the restrictions imposed particularly by Apple on the autoplaying and preloading of HTML5 videos (both are disabled and user interaction is required to trigger playback) I've decided to omit the videos for mobile & opt for static images instead. This is relatively simple, since all that's required to stop the video from overlaying the content is a media query that hides them.
That said, I'm finding it very difficult to prevent the videos from being downloaded and the overhead is massive.
For example, I have a script to check whether the user is currently visiting from a mobile device, as such, I've tried:
var check = false;
window.mobilecheck = function() {
// Check for mobile here
if (check === true) {
// Device is mobile
var videos = document.querySelectorAll('.video-js');
for (var i = 0; i < videos.length; i++) {
// videojs(videos[i]).destroy();
videos[i].parentNode.removeChild(videos[i]);
}
}
}
This successfully removes the elements, but this has to be called on DOMReady which also means the resources already begin download.
How do I stop the videos from loading on mobile? I'd like to find a solution that uses VideoJS inherently preferably.