question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Media playback is not always tied to user gesture

See original GitHub issue

When 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()?

/cc @aghassemi @choumx @prateekbh @alanorozco

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:10 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
newmuiscommented, Nov 15, 2017

Okay, as a quick update: The autoplay attribute helps because amp-video will use that to mute the underlying video 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 subsequently pause() 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.

0reactions
newmuiscommented, Nov 16, 2017

Put together this JsFiddle to test out the maximum video limitation on iOS Safari.

Looks like the .error property gets set to MEDIA_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).

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found