Skip to content

Autoplay videos do not autoplay when inside a content tab #8396

@Aikohh

Description

@Aikohh

Context

I'm trying to use auto-play videos as a replacement for animated GIFs/webp/APNGs for the better compression.
I am making pages that will contain multiple videos / animations, so having a user manually click on each video to start them is not a good experience.
However, it is currently impossible to auto-play videos in content tabs without additional JavaScript, when I thought it would just be a simple addition of the autoplay attribute to videos in HTML.

Bug description

When embedding a video with the autoplay attribute into a content tab, the video will not autoplay.
However, an autoplay video placed outside of a content tab will autoplay.

# Welcome to MkDocs

<video autoplay loop muted playsinline>
<source src="../ThisIsFine.mp4" type="video/mp4">
</video>

=== "This is a tab"

    <video autoplay loop muted playsinline>
    <source src="../ThisIsFine.mp4" type="video/mp4">
    </video>

Original video from: [https://www.youtube.com/watch?v=0oBx7Jg4m-o](https://www.youtube.com/watch?v=0oBx7Jg4m-o)
Image

I believe the cause of the issue is this commit that tries to pause videos in content tabs when content tabs are hidden. However, in this case there is only one content tab and it is never hidden, so the video is not supposed be paused.

The only workarounds I know of are:

  1. go back to using GIFs/webp/APNGs at the cost of much larger file sizes but will auto-play as intended, or
  2. add the controls attribute get the user to click on each video to start each one (which is annoying if there are many videos), or
  3. undo the change of the faulting commit using one of the methods suggested in Disabling media pause when switching content tabs. #6844

Related links

Docs:

Related issues and discussions

Reproduction

9.6.16-autoplay-video-does-not-autoplay-in-a-content-tab.zip

Steps to reproduce

  1. Extract the reproduction project (autoplay-video.zip)
  2. Run mkdocs serve in the root of the project
  3. Open a web browser to the served mkdocs website
  4. Observe that the autoplay video outside of a content tab is autoplaying, but the autoplay video inside a content tab is not autoplaying

Browser

Firefox, Chrome, Edge

Before submitting

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIssue reports a bugresolvedIssue is resolved, yet unreleased if open

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions