Skip to content

Cover Block: video doesn't start on iOS #17479

Closed

Description

@benoitchantre

Describe the bug
When you add a cover block containing a video, the video doesn't start on iOS.

Expected behavior
The video should start.

Smartphone (please complete the following information):

  • Device: iPhone XR
  • OS: iOS 12.4.1
  • Browser: Safari

Additional context

  • Gutenberg 6.5

Solution
Add the playsinline="" attribute to the video tag.

Activity

  1. added
    [Block] Cover
    Browser Issues
    on Sep 19, 2019
  2. zimjjan commented on Nov 10, 2019

    @zimjjan

    +1

  3. marcuswisecaesar commented on Nov 19, 2019

    @marcuswisecaesar

    +1

    2504115-zen

  4. separatelyunited commented on Jan 16, 2020

    @separatelyunited

    +1 to this.

    I found that the video didn't play on Google Chrome on iOs (using xs & 8+) on Safari or Google Chrome. On Android (using Samsung Note 9), the video started on Chrome and then froze; with Microsoft Edge the blurry video image didn't even load only a placeholder box.

    I expected that if the auto-play video isn't supported or doesn't start on mobile browsers that the video thumbnail would be what shows (similar to when autoplay is disabled on mobile for other video blocks). Or that a static image could be chosen as a fall back similar to how the Media header for Twentyseventeen is set up.

    Missing video on Edge:
    Screenshot_20200113-233337_Edge

    Video started then froze on Chrome using Android:
    Screenshot_20200113-233623_Chrome

    Not started at all on iOs:
    IMG_8374

  5. khristiansnyder commented on Feb 11, 2020

    @khristiansnyder

    +1
    Encountered this issue today as well.

  6. eamcgill90 commented on Mar 18, 2020

    @eamcgill90

    Reported here: 19496236-hc

  7. benchilcote commented on Mar 20, 2020

    @benchilcote

    I found this to be a suitable workaround:
    https://wordpress.org/plugins/advanced-backgrounds/

  8. pburke commented on Mar 25, 2020

    @pburke

    Workaround for anyone looking:

    /**
     * Filter Cover block output to add "playsinline" attribute on videos
     */
    add_filter('render_block', function ($block_content, $block) {
        if ('core/cover' !== $block['blockName']) {
            return $block_content;
        }
    
        return str_replace('autoplay muted loop', 'autoplay muted loop playsinline', $block_content);
    }, 10, 2);
  9. openfist commented on Mar 26, 2020

    @openfist

    reporting this issue as well
    #2819740-zen

  10. donalirl commented on Apr 23, 2020

    @donalirl

    I came across this too. Video backgrounds do not have full mobile browser support. It would be helpful to at least be able to set a fallback image for when the video doesn't play, as per #18962

  11. jasmussen commented on May 14, 2020

    @jasmussen
    Contributor

    Mobile Safari has a few heuristics built in for when it allows autoplay on mobile, for example it blocks playback if the device is in "low power mode".

    The heuristics for allowing mobile autoplay are also outlined there:

    • <video> elements will be allowed to autoplay without a user gesture if their source media contains no audio tracks.
    • <video muted> elements will also be allowed to autoplay without a user gesture.
    • <video autoplay> elements will only begin playing when visible on-screen such as when they are scrolled into the viewport, made visible through CSS, and inserted into the DOM.
    • <video autoplay> elements will pause if they become non-visible, such as by being scrolled out of the viewport.

    The document also notes the behavior of playsinline:

    On iPhone, <video playsinline> elements will now be allowed to play inline, and will not automatically enter fullscreen mode when playback begins.
    <video> elements without playsinline attributes will continue to require fullscreen mode for playback on iPhone.
    When exiting fullscreen with a pinch gesture, <video> elements without playsinline will continue to play inline.

    So it seems like playsinline is necessary because otherwise the video will require fullscreen to be played, and that happens only if you tap the video. We already add muted. So the following markup should work:

    <video autoplay muted playsinline>
      <source src="video.mp4" type="video/mp4" />
    </video>
    
  12. added
    [Status] In Progress
    on May 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Browser Issues[Block] Cover[Status] In Progress

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions