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

Bug: Video autoplay broken on Chrome #106

Open
montyz opened this issue Nov 30, 2022 · 1 comment
Open

Bug: Video autoplay broken on Chrome #106

montyz opened this issue Nov 30, 2022 · 1 comment

Comments

@montyz
Copy link

montyz commented Nov 30, 2022

See https://liascript.github.io/course/?https://raw.githubusercontent.com/montyz/landstewards/main/slides.md#7 for an example of trying to autoplay mp4 files. On my chrome or brave browser on OS X it won't autoplay. It does work in Safari and Firefox.

@andre-dietrich
Copy link
Member

Hi @montyz ... this seems to be a browser problem, depending also on the time, when the slide with the video gets loaded, if it is the first, then the browser might prevent the loading. I got the following result

image

And setting muted as a parameter in the tag does not seem to fix this either.

https://stackoverflow.com/questions/14111917/html5-video-muted-but-still-playing

However, there is a way, how you can implement the desired behavior. LiaScript can execute scripts as well. You can either add this script to every slide, where you want to autoplay videos.

<script>
// select all tags of type video, where the property autoplay is set
const videos = document.querySelectorAll('video[autoplay]');

for(let video of videos) {
    // set mute manually to true, otherwise autoplay will be forbidden
    video.muted = true
    video.play()
}

// by returning undefined, this script will be invisible to the user
// it means, no body ...
undefined
</script>

or you can create a custom macro, which has to be defined in the main-comment of your document:

<!--
author: ...

@autoplay
<script>
// select all tags of type video, where the property autoplay is set
const videos = document.querySelectorAll('video[autoplay]');

for(let video of videos) {
    // set mute manually to true, otherwise autoplay will be forbidden
    video.muted = true
    video.play()
}

// by returning undefined, this script will be invisible to the user
// it means, no body ...
undefined
</script>
@end
-->

# Title 

...

## Wildlife

!?[Deer](pics/Deer.mp4)<!-- muted="true" -->
!?[Bears](pics/107.mp4)<!-- autoplay muted="muted" -->
!?[Doves](pics/Doves.mp4)<!-- autoplay muted="muted" -->
![wildflowers](pics/IMG_2190.jpeg)

@autoplay

The script will only autoplay vidoes, where the specific attribute has been added, all others will be ignored ...

...

Great course by the way ... I hope this helps ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants