Skip to content

Commit

Permalink
mobile autoplay fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Theodore Zhao committed May 22, 2024
1 parent 06f4cf1 commit 6524441
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -269,19 +269,16 @@ <h1 style="font-size: 2em;">Everything</h1>
</style>

<!-- JavaScript for ensuring autoplay on mobile devices after user interaction -->
<script>
function enableAutoplay() {
var videos = document.querySelectorAll('video[autoplay]');
videos.forEach(function(video) {
document.addEventListener('DOMContentLoaded', function() {
var videos = document.querySelectorAll('video[autoplay]');
videos.forEach(function(video) {
video.muted = true; // Ensure the video is muted
video.play().catch(function(error) {
console.log('Autoplay was prevented: ', error);
console.log('Autoplay was prevented: ', error);
});
});
}
});
});

document.body.addEventListener('touchstart', enableAutoplay, {once: true});
document.body.addEventListener('click', enableAutoplay, {once: true});
</script>



Expand Down

0 comments on commit 6524441

Please sign in to comment.