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

Autoplay doesn't work in Firefox and Safari Mobile Browsers #1316

Open
shmaltz opened this issue Jun 18, 2024 · 2 comments
Open

Autoplay doesn't work in Firefox and Safari Mobile Browsers #1316

shmaltz opened this issue Jun 18, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@shmaltz
Copy link

shmaltz commented Jun 18, 2024

Current Behavior:

I added a media player to my site with autoplay and on desktop it works properly, however on mobile Firefox browser the player loads ads stays loading (with the loading icon) but I cannot play the video even manually. (On iOS Safari mobile the player doesn't load at all, and chrome on Android works properly). I tried tapping into the auto-play and auto-play-fail event listeners, and even though the video fails to play, it still says it succeeded. I understand that some browsers block autoplay with sound, and I was intending to display a "Play" button if auto-play-fail fails, in order to manually start the video.

Expected Behavior:

I expect the video to autoplay properly (or at least auto-play-fail should work).

Steps To Reproduce:

<div class="video-player-outer">
<media-player autoplay load="eager" title="<?php echo $title; ?>" src="youtube/<?php echo $youtube_id; ?>">
  <media-provider>
    <media-poster
      class="vds-poster"
      src="<?php echo $thumbnail; ?>"
    ></media-poster>
  </media-provider>
  <media-video-layout thumbnails="<?php echo $thumbnail; ?>"></media-video-layout>
</media-player>
<button id="fallback-play-button" style="display: none;">Play</button>
</div>
document.addEventListener('DOMContentLoaded', function () {
    const player = document.querySelector('media-player');
    const playButton = document.getElementById('fallback-play-button');

 if (player) {
        player.addEventListener('auto-play', function () {
            playButton.style.display = 'none';
            console.log('autoplay succeeded!');
        });

        player.addEventListener('auto-play-fail', function () {
            playButton.style.display = 'block';
            console.log('autoplay failed!');
        });
    }

    playButton.addEventListener('click', function () {
        player.play();
    });
 }
});

Environment:

  • Version: 1.11.22-next
  • Framework: Web Components
  • PHP/JS
  • Device: OnePlus 9
  • OS: Android 14
  • Browser: Firefox@116
@shmaltz shmaltz added the bug Something isn't working label Jun 18, 2024
@wplit
Copy link

wplit commented Jun 19, 2024

Make sure the player is muted, many browsers won't autoplay unless the video is muted.

Works fine on my end with Safari on iOS, but only if muted.

@shmaltz
Copy link
Author

shmaltz commented Jun 19, 2024

Make sure the player is muted, many browsers won't autoplay unless the video is muted.

Works fine on my end with Safari on iOS, but only if muted.

Thanks @wplit . That did the trick for Firefox on Android, but on Safari iOS the player still doesn't load at all. Too bad I can't see the console for errors because it doesn't seem like I can on iOS.

Also, will the user have to manually unmute every single video now, or does the browser somehow remember that setting? If not, are there any hacks to auto unmute the video once it's playing?

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants