Video autoplay issue on some mobile devices—works on some but not others

I’ve recently asked about this issue, but I am still facing problems with video autoplay on mobile devices. While my code works on certain phones, on others, the video remains paused, and users have to tap the screen to start the video.

Here’s what I’ve tried so far:

- Muted the video to enable autoplay as per mobile browser requirements.
- Used "preload" and "autoplay" attributes in the video tag.
- Followed various recommendations from the community, but the issue persists.

I’ve also experimented with some JavaScript functions suggested by ChatGPT, but the problem still occurs inconsistently across different devices. Below is my current code:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Video Background</title>
    <style>
        html, body {
            margin: 0;
            padding: 0;
            height: 100%;
            width: 100%;
            overflow: hidden;
            position: relative;
        }

        video {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            object-fit: cover;
            z-index: -1;
        }
    </style>
</head>
<body>

    <video id="background-video" preload autoplay muted="muted" loop playsinline poster="">
        <source src="Background.mp4" type="video/mp4">
        Your browser does not support the video tag.
    </video>

</body>

</html>
        function playVideo() {
            var video = document.getElementById('background-video');
            video.play().then(function() {
                console.log('Video is playing');
            }).catch(function(error) {
                console.log('Video playback failed:', error);
            });
        }

        document.addEventListener('DOMContentLoaded', function() {
            var video = document.getElementById('background-video');

            
            document.body.addEventListener('click', playVideo);
            document.body.addEventListener('touchstart', playVideo);

           
            video.play().catch(function(error) {
                console.log('Auto-play failed:', error);
            });

           
            setTimeout(function() {
                window.location.href = 'menu.html';
            }, 3000);
        });


        document.addEventListener('visibilitychange', function() {
            var video = document.getElementById('background-video');
            if (document.hidden || video.muted === false) {
                video.pause();
            } else {
                video.play();
            }
        });
 html, body {
            margin: 0;
            padding: 0;
            height: 100%;
            width: 100%;
            overflow: hidden;
            position: relative;
        }

        video {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            object-fit: cover;
            z-index: -1;
        }

Despite implementing these solutions, the video still does not autoplay on all devices, and I’m unsure why. On some phones, the video is paused, and users have to tap the video to start playback.

Does anyone know why this might be happening or have any additional solutions? Your help would be greatly appreciated.

3

Many mobile browsers, including Chrome and Safari, restrict autoplay for videos, particularly those with sound. To provide a positive user experience and save data, these browsers typically block autoplay unless the video is muted. Additionally, some users may have settings enabled, either by default or by choice, to prevent autoplay due to data usage concerns or personal preferences. It is important to ensure that all devices are using the same browser, although be aware that device power modes may occasionally interfere with this. If one of these is the cause, there is virtually no solution.

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật