Audio autoplayProperty

Audio 对象参考手册Audio Object

Examples

Check whether the audio is set to play immediately after loading:

var x = document.getElementById("myAudio").autoplay;
xThe output result is:
true

Try it Yourself »

Definition and Usage

The autoplay property sets or returns whether the audio/video starts playing immediately after loading.

This property reflects the <audio> autoplay attribute.

If the autoplay attribute is set, it specifies that the audio will start playing immediately after loading.

Note:The <audio> element is a new element in HTML5.


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

The autoplay property is supported by all mainstream browsers.

Note:Internet Explorer 8 and earlier IE versions do not support the <video> element.


Syntax

Return the autoplay property:

audioObject.autoplay

Set the autoplay property:

audioObject.autoplay=true|false

Property Values

Value Description
true|false Sets whether the audio/video starts playing immediately after loading.
  • true - Automatically starts playing after the audio has finished loading.
  • false - Default. Does not automatically play after the audio has finished loading.

Technical Details

Return Value: A Boolean value. Returns true if the audio autoplay is set, otherwise returns false.
Default Value: false 


More Examples

Examples

Enable autoplay, and reload the video:

var x = document.getElementById("myAudio");
x.autoplay = true;
x.load();

Try it Yourself »

Examples

The following example demonstrates how to create a <video> element and set the autoplay attribute:

var x = document.createElement("AUDIO");

Try it Yourself »


Related Pages

HTML Reference Manual:HTML <audio> autoplay attribute


Audio 对象参考手册Audio Object

Other Extensions