Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HLS.js playlist could not be loaded and the video doesn't work on my web site #6363

Open
apoklyak opened this issue Apr 18, 2024 · 1 comment

Comments

@apoklyak
Copy link

What do you want to do with Hls.js?

I faced an issue with autoplaying videos on my website, particularly on mobile devices. I've successfully implemented video autoplay for desktop screens. But mobile screens are displaying an error message in Chrome:

image

I'm working with HTML/CSS/JavaScript and using HLS.js to play videos in chunks. All video content, including chunks and playlists, is hosted on AWS storage.

Here's the HTML code snippet for embedding the video:

<div class="background-video w-background-video w-background-video-atom">
    <video id="video" autoplay loop muted playsinline data-object-fit="cover"
           data-wf-ignore="true">
    </video>
</div>

And below is the JavaScript code I'm using to switch playlists based on screen resolution:

   document.addEventListener('DOMContentLoaded', function () {
        var video = document.getElementById('video');
        var videoSrc = window.innerWidth <= 1024 ?
            'https://d2vsrh5hfn32bm.cloudfront.net/output_mobile_playlist.m3u8' : // Mobile URL
            'https://d2vsrh5hfn32bm.cloudfront.net/output_playlist.m3u8'; // Desktop URL

        if (Hls.isSupported()) {
            var hls = new Hls();
            hls.loadSource(videoSrc);
            hls.attachMedia(video);
            hls.on(Hls.Events.MANIFEST_PARSED, function () {
                video.play();
            });
        } else if (video.canPlayType('application/vnd.apple.mpegurl')) {
            video.src = videoSrc;
            video.addEventListener('loadedmetadata', function () {
                video.play();
            });
        }
    });

Also I noticed the strange behavior. I am located in Poland. But if I change my IP address to US via VPN, the video will be work well.

It will be great to read some advices.

Link for the web site here https://aig.gvodex.work/index

What have you tried so far?

No response

@apoklyak apoklyak added Needs Triage If there is a suspected stream issue, apply this label to triage if it is something we should fix. Question labels Apr 18, 2024
@robwalch robwalch added the CORS label Apr 18, 2024
@robwalch
Copy link
Collaborator

mobile screens are displaying an error message in Chrome:

These errors do not originate from HLS.js. HLS content should be served with "Access-Control-Allow-Origin" headers to prevent CORS errors in Web-based players. HLS.js cannot proceed to parse and play content when the first request is blocked by CORS.

Search "AWS storage CORS policy" -> https://docs.aws.amazon.com/AmazonS3/latest/userguide/cors.html

Here's the HTML code snippet for embedding the video:
And below is the JavaScript code I'm using to switch playlists based on screen resolution:

Since you have "autoplay" on the video element, you do not need to call video.play() in either case. Let the browser handle autoplay (or reject it based on user preference and browser policy).

@robwalch robwalch added answered and removed Needs Triage If there is a suspected stream issue, apply this label to triage if it is something we should fix. labels Apr 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants