You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
At the moment, one has to call play() and check for errors in various places to know if the request failed. Also, when a play() call is blocked because the UA doesn't allow it for some reasons (no user gesture, page not visible, etc.), it is very hard for the page to know about it because it is not a MediaError. The common way for a page to find out the UA blocked a play() request is the absence of playback. It is not an ideal developer experience.
I would like to have play() return a Promise<> so one can do:
media.play().then(function(){// playback started},function(e){// playback failed, use 'e' to check why});
(Note that when we resolve the promise might have issues similar to #309.)
After talking with @foolip about this, we think it would be great to use DOMException instead of MediaError when rejecting the play promise. It would be a first step in order to deprecate MediaError in order to use DOMException.
I suggest that we have this correspondence table:
MediaError
DOMException
MEDIA_ERR_ABORTED
"AbortError"
MEDIA_ERR_NETWORK
"NetworkError"
MEDIA_ERR_DECODE
"EncodingError"
MEDIA_ERR_SRC_NOT_SUPPORTED
"NotSupportedError"
Then, we can add "NotAllowedError" to be used if the play() request is rejected by the UA because it is not currently allowed by the UA or the system. We didn't find a matching error in the current list of DOMException. However, it's fine to create new names so unless someone has a better idea, I think it should be fine to use this one.