Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes togglePlay() unhandled exception in promise #31

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

zackees
Copy link

@zackees zackees commented Jun 25, 2022

Brief

Fixes the new autoplay restrictions where Play() can fail due to Chrome/Safari not registering a user interaction before the video plays (with sound).

Summary

Suppose a video is in an html, which will call video.play to auto-start the video. This video.html is embedded as a same-host iframe. If the user has been using the app then no problem the video autoplays fine.

HOWEVER

If this user takes this link and sends it to one of their friends the video autoplay will fail. In this scenario, chrome/firefox/safaria etc will actually block the video play because the user hasn't click anything yet. The clue that this has happened is that the browser invoke an exception to the promise of video.play(). However, moovie doesn't handle this because the promise is not returned to the caller.

The solution is to change togglePlay() such that the promise is returned to the caller, where the error condition can be gracefully handled.

This enables an attempt at autoplay, with a fallback behavior such as displaying the play.svg button to cue the user to play click the play button. Infact this is exactly the solution I'm using.

Fixes the new autoplay restrictions where Play() can fail due to Chrome/Safari not registering a user interaction before the video plays (with sound). In this case, when a same-host iframe loads a call to video.play() is invoked to auto-start the video. If the user has been using the app then no problem the video autoplays fine. But if this user takes a link and sends it to one of their friends, who autoplays it when they load the link. In this scenario, chrome will actually block the video play and invoke an exception in a promise from video.play(). This promise is not correctly referenced and therefore the orphaned promise errors to the console instead of being handled.

The solution is to change togglePlay() such that the promise is returned to the caller, where the error condition can be gracefully handled.

This enables an attempt at autoplay, with a fallback behavior such as displaying a play.svg button.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant