This is an experimental technology
Because this technology's specification has not stabilized, check the compatibility table for usage in various browsers. Also note that the syntax and behavior of an experimental technology is subject to change in future versions of browsers as the specification changes.
The HTMLMediaElement.play()
method attempts to begin playback of the media and returns a Promise
which is fulfilled when the playback has been successfully started, and which is rejected if playback fails to begin for any reason (such as permission issues or other problems).
HTMLMediaElement.play().then(function() { ... }
None.
A Promise
which is fulfilled when playback has been started, or is rejected if for any reason playback cannot be started.
The promise's rejection handler is called with an exception as its input value (as opposed to a traditional exception being thrown). Possible exceptions include:
NotAllowedError
NotSupportedError
MediaStream
, MediaSource
, Blob
, or File
, for example) doesn't represent a supported media format.Other exceptions may be reported, depending on browser implementation details, media player implementation, and so forth.
Specification | Status | Comment |
---|---|---|
WHATWG HTML Living Standard The definition of 'play()' in that specification. | Living Standard | Initial definition; living specification. |
HTML5 The definition of 'play()' in that specification. | Recommendation | Initial definition. |
Note that the WHATWG and W3C versions of the specification differ (as of April 20, 2016) as to whether or not this method returns a Promise
or nothing at all, respectively.
Feature | Chrome | Edge | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
---|---|---|---|---|---|---|
Basic support | 50.0 | (Yes) | 3.5 (1.9.1) | ? | ? | ? |
Promise return value | 50.0 | ? | No support | ? | ? | ? |
Feature | Android | Android Webview | Edge | Firefox Mobile (Gecko) | Firefox OS | IE Mobile | Opera Mobile | Safari Mobile | Chrome for Android |
---|---|---|---|---|---|---|---|---|---|
Basic support | No support | 50.0 | (Yes) | (Yes) | ? | ? | ? | ? | 50.0 |
© 2005–2017 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/play