Home Web Front-end H5 Tutorial In html5, set or return the attribute autoplay of whether the audio and video will start playing after loading.

In html5, set or return the attribute autoplay of whether the audio and video will start playing after loading.

Nov 08, 2017 am 09:35 AM
h5 html5 Audio and video

Example

Enable autoplay and reload Video:

myVid=document.getElementById("video1");
myVid.autoplay=true;
myVid.load();
Copy after login

Definition and usage

autoplay PropertiesSettings Or returns whether the audio and video starts playing after loading.

Browser support

All major browsers support the autoplay attribute.

Note: Internet Explorer 8 or earlier browsers do not support this attribute.

Syntax

Set the autoplay attribute:

audio|video.autoplay=true|false
Copy after login

Return the autoplay attribute:

audio|video.autoplay
Copy after login

Attribute value

ValueDescription
trueIndicates that the audio and video will be played immediately after loading.
falseDefault. Indicates that the audio and video should not play immediately after loading.

Technical Details

Return ValueBoolean value. true|false
Default value:false

html5 video uses the autoplay attribute, the sound is confusing

Page code

Index.html

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>test</title> 
<meta charset=&#39;utf-8&#39;/>
<script src="js/jquery-1.4.4.min.js" type="text/javascript"></script>
<script src="js/thml5.js" type="text/javascript"></script>
<script type="text/javascript">

window.onload=function(){
$(&#39;#channel1&#39;).click(function(){
setConfig("test1.mp4");
});

$(&#39;#channel2&#39;).click(function(){
setConfig("test2.mp4");
});

$(&#39;#channel3&#39;).click(function(){
setConfig("test3.mp4");
});
}


function setConfig(url){
var jo=$(&#39;#test1&#39;);
var cfg=HTML5MediaService.getDefaultConfig();
 cfg=$.extend(cfg, {url: url});
HTML5MediaService.create(jo,cfg);
}

</script>
</head>
<body>
<div id=&#39;test1&#39; style="height:300px;width:500px;">

</div>
</br>
</br>
</br>
<div>
<span id=&#39;channel1&#39;>频道1</span>
<span id=&#39;channel2&#39;>频道2</span>
<span id=&#39;channel3&#39;>频道3</span>
</div>
</body>
</html>
Copy after login

js code
html5.js

var HTML5MediaService= {
    getDefaultConfig: function () {
        return $.extend({}, {width: "100%", height: "100%", controls: "controls", autoplay: "autoplay"});
    },
    create:function(jo,cfg){
         this.videoId = "videojs_" + new Date().getTime().toString();
        var videoJo = $(&#39;<video&#39; +
            &#39; id="&#39; + this.videoId + &#39;"&#39; +
            &#39; src=&#39; + cfg.url +
            &#39; controls=&#39; + cfg.controls +
            &#39; autoplay=&#39; + cfg.autoplay +
            &#39; width=&#39; + cfg.width +
            &#39; height=&#39; + cfg.height +
            &#39; preload=none&#39; +
            &#39;></video>&#39;);
        videoJo.appendTo(jo.empty());
    }  
   }
Copy after login

My solution:

Take To disable autoplay, you can use the play() function to achieve the automatic playback function;

The above is the detailed content of In html5, set or return the attribute autoplay of whether the audio and video will start playing after loading.. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Table Border in HTML Table Border in HTML Sep 04, 2024 pm 04:49 PM

Guide to Table Border in HTML. Here we discuss multiple ways for defining table-border with examples of the Table Border in HTML.

Nested Table in HTML Nested Table in HTML Sep 04, 2024 pm 04:49 PM

This is a guide to Nested Table in HTML. Here we discuss how to create a table within the table along with the respective examples.

HTML margin-left HTML margin-left Sep 04, 2024 pm 04:48 PM

Guide to HTML margin-left. Here we discuss a brief overview on HTML margin-left and its Examples along with its Code Implementation.

HTML Table Layout HTML Table Layout Sep 04, 2024 pm 04:54 PM

Guide to HTML Table Layout. Here we discuss the Values of HTML Table Layout along with the examples and outputs n detail.

HTML Input Placeholder HTML Input Placeholder Sep 04, 2024 pm 04:54 PM

Guide to HTML Input Placeholder. Here we discuss the Examples of HTML Input Placeholder along with the codes and outputs.

HTML Ordered List HTML Ordered List Sep 04, 2024 pm 04:43 PM

Guide to the HTML Ordered List. Here we also discuss introduction of HTML Ordered list and types along with their example respectively

Moving Text in HTML Moving Text in HTML Sep 04, 2024 pm 04:45 PM

Guide to Moving Text in HTML. Here we discuss an introduction, how marquee tag work with syntax and examples to implement.

HTML onclick Button HTML onclick Button Sep 04, 2024 pm 04:49 PM

Guide to HTML onclick Button. Here we discuss their introduction, working, examples and onclick Event in various events respectively.

See all articles