Media playback is not always tied to user gesture
See original GitHub issueWhen automatically advancing (e.g. after a fixed amount of time) between two amp-story-page
components that both contain media, the media does not always play on the second page, depending on the browser.
My guess is that this is because there is no gesture tied to the advancement, so the browser does not consider the media play()
invocation to have been caused by a user gesture. Perhaps there’s a way for us to hold onto the user’s previous gesture to tie that gesture to the call to play()
?
Issue Analytics
- State:
- Created 6 years ago
- Comments:10 (9 by maintainers)
Top Results From Across the Web
add method to discover whether playback is allowed ...
Safari macOS does not require a user gesture for each media element but activating one media element would activate them all. In other...
Read more >User gesture required to start playback in Android HTML5 ...
Normally video should only play following a user action. This is recommended behavior for both Android and iOS nowadays. You can, however, set ......
Read more >Autoplay policy in Chrome - Chrome Developers
When the permissions policy for autoplay is disabled, calls to play() without a user gesture will reject the promise with a NotAllowedError ...
Read more >178297 - Android Chrome does not allow applications to ...
The Android framework does not require a user gesture to begin media playback. The web shouldn't have that restriction either. The fix affects...
Read more >WKAudiovisualMediaTypes - Documentation
To indicate that no user gestures are required to play media, use an empty set of audio/visual media types, indicated by the empty...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Okay, as a quick update: The
autoplay
attribute helps becauseamp-video
will use that to mute the underlyingvideo
by default. This, however, does not help in the case of unmuted videos.Per @aghassemi’s suggestion, we can call
play()
on all videos when the user taps the unmute icon, and subsequentlypause()
any videos that shouldn’t be playing. This will bless them for future automatic playback.However, we don’t want to require that ALL media elements exist in memory all the time. We can instead keep a pool of these media elements and swap them in/out of the DOM. We can perhaps start off with a fixed-size pool; as an optimization we might be able to calculate the size of the pool at build time, based on how many media elements would be needed to load a page and preload subsequent pages.
Put together this JsFiddle to test out the maximum video limitation on iOS Safari.
Looks like the
.error
property gets set toMEDIA_ERR_DECODE
for videos that are created beyond the limit. It also looks like it is last-played first-evicted (i.e. on my device, where the limit is 16 videos, when the 17th video is added, it immediately fails, and so on, leaving the first 16 videos intact).