Bug 175748

Summary: Autoplay Muted Videos Don't Play When Outside Viewport
Product: WebKit Reporter: Neil Daniels <neil.here>
Component: MediaAssignee: Jer Noble <jer.noble>
Status: RESOLVED FIXED    
Severity: Normal CC: buildbot, commit-queue, eric.carlson, jer.noble, rniwa, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: Other   
Hardware: iPhone / iPad   
OS: iOS 11   
Attachments:
Description Flags
Webarchive of mentioned test case.
none
Patch
none
Archive of layout-test-results from ews100 for mac-elcapitan
none
Archive of layout-test-results from ews106 for mac-elcapitan-wk2
none
Archive of layout-test-results from ews113 for mac-elcapitan
none
Archive of layout-test-results from ews125 for ios-simulator-wk2
none
Patch none

Description Neil Daniels 2017-08-18 17:45:38 PDT
Created attachment 318565 [details]
Webarchive of mentioned test case.

I have various <video autoplay loop muted playsinline> on a single page, on iOS 11 (15A5354b, iPhone and iPad) only the videos that are within the viewport automatically play.

A test case exists at this page: https://www.fomopop.com/html5-video-test/ (a webarchive is attached as well, for posterity). If you view on an iPhone running iOS 10.x, all 5 of the videos will play. On an iPhone running iOS 11 (15A5354b), only the first 2 videos will play.

This might be related to https://bugs.webkit.org/show_bug.cgi?id=170610 , but I'm not sure if that's in a public iOS build yet.
Comment 1 Jer Noble 2017-08-18 17:49:25 PDT
It's actually more likely related to <https://bugs.webkit.org/show_bug.cgi?id=168268>, as it seems to only happen with <video><source /></video> elements, and not <video src=""></video> elements.
Comment 2 Jer Noble 2017-08-18 17:50:35 PDT
It looks like we're not calling prepareForLoad() in the <source /> selection case; prepareForLoad() is what sets the state PlatformSessionManager state to Autoplaying, thus breaking restoring that state to Autoplaying when becoming visible again.
Comment 3 Jer Noble 2017-08-18 18:02:29 PDT
Aha, we set the PlatformMediaSession's state to Autoplaying inside prepareForLoad(), which also sets the m_autoplaying flag to true (as specified in the "media element load algorithm" section of the HTML spec.  But the autoplaying flag is initially true (as specified in just before same), so we should probably notify the client that we're autoplaying on HTMLMediaElement creation.
Comment 4 Radar WebKit Bug Importer 2017-08-18 18:16:41 PDT
<rdar://problem/33974383>
Comment 5 Jer Noble 2017-08-21 12:09:03 PDT
Created attachment 318657 [details]
Patch
Comment 6 Build Bot 2017-08-21 13:05:00 PDT Comment hidden (obsolete)
Comment 7 Build Bot 2017-08-21 13:05:01 PDT Comment hidden (obsolete)
Comment 8 Build Bot 2017-08-21 13:33:31 PDT Comment hidden (obsolete)
Comment 9 Build Bot 2017-08-21 13:33:32 PDT Comment hidden (obsolete)
Comment 10 Build Bot 2017-08-21 13:40:43 PDT Comment hidden (obsolete)
Comment 11 Build Bot 2017-08-21 13:40:44 PDT Comment hidden (obsolete)
Comment 12 Build Bot 2017-08-21 13:56:30 PDT Comment hidden (obsolete)
Comment 13 Build Bot 2017-08-21 13:56:33 PDT Comment hidden (obsolete)
Comment 14 Jer Noble 2017-08-21 16:57:51 PDT
Created attachment 318699 [details]
Patch
Comment 15 WebKit Commit Bot 2017-08-22 09:13:26 PDT
Comment on attachment 318699 [details]
Patch

Clearing flags on attachment: 318699

Committed r221016: <http://trac.webkit.org/changeset/221016>
Comment 16 WebKit Commit Bot 2017-08-22 09:13:27 PDT
All reviewed patches have been landed.  Closing bug.