So far i have managed to make product videos on the product pages to autoplay but only on desktop. Is there any code or way of making it work for mobile devices?
I’d also like to have auto play videos on the product card which is on my home page so that people can see the product in action without having to click “play”
I’ve looked everywhere. There are similar solutions but nothing that has worked for me.
To enable autoplay videos on mobile devices, you might try a JavaScript-based approach. Some mobile browsers prevent autoplay with sound, so ensure that videos are muted. Here’s a code snippet to autoplay videos on both desktop and mobile devices:
Autoplay on Product Pages (Desktop and Mobile):
Add this JavaScript to ensure the video autoplays when muted:
For the product cards, add similar code, ensuring videos are muted and have the autoplay ,loop, and playsinline attributes. Add this to your theme’s JavaScript file or in-line Javascript:
document.addEventListener("DOMContentLoaded", function() {
const productCardVideos = document.querySelectorAll('.product-card-video');
productCardVideos.forEach(video => {
video.setAttribute("autoplay", "");
video.setAttribute("loop", "");
video.setAttribute("muted", "");
video.setAttribute("playsinline", ""); // Important for mobile
video.muted = true;
video.play().catch(error => {
console.error("Autoplay failed on product cards:", error);
});
});
});
Let me know if this approach works for you or if you need further customization!
If I was able to help you, please don’t forget to Like and mark it as the Solution!
If you’re looking for expert help with customization or coding, I’d be delighted to support you. Please don’t hesitate to reach out via the email in my signature below—I’m here to help bring your vision to life!