首页 > 解决方案 > Inline-videos don't play when direct URLs are pasted into URL bar in Google Chrome

问题描述

If I link from another page in my site, they play. They look like this:

<video playsinline autoplay loop class="vf-video">
    <source src="/assets/video/the-video.mp4" type="video/mp4">
</video>

When I paste in the URL and hit enter, they do not play. I even added this jQuery in a DOMContentLoaded listener:

setTimeout(function () {
    $("video[autoplay]").each(function () {
        console.log(this);
        this.play();
    });
}, 3000);

Still will not play. They play fine in FireFox. Using latest Google Chrome on OS X.

标签: javascriptgoogle-chromevideohtml5-video

解决方案


For video elements without sound disabled, they wont play without a user interaction. A click from a previous page is apparently considered a user interaction that should allow video to play. For my example, I just had to add the 'muted' to meet this criteria so the video would autoplay.


推荐阅读