The HTMLMediaElement.autoplay
property reflects the autoplay
HTML attribute, indicating whether playback should automatically begin as soon as enough media is available to do so without interruption.
A media element whose source is a MediaStream
and whose autoplay
property is true
will begin playback when it becomes active (that is, when MediaStream.active
becomes true
).
Note: Sites which automatically play audio (or videos with an audio track) can be an unpleasant experience for users, so it should be avoided when possible. If you must offer autoplay functionality, you should make it opt-in (requiring a user to specifically enable it). However, autoplay can be useful when creating media elements whose source will be set at a later time, under user control.
For a much more in-depth look at autoplay, autoplay blocking, and how to respond when autoplay is blocked by the user's browser, see our article Autoplay guide for media and Web Audio APIs.