当前位置: 移动技术网 > IT编程>网页制作>Html5 > html5自动播放mov格式视频的实例代码

html5自动播放mov格式视频的实例代码

2020年03月29日  | 移动技术网IT编程  | 我要评论

这个不算啥新奇吧?但还是记录一下。

这个问题应该这么看。

1、首先网站要支持.mov格式文件

就是说,网站要能识别.mov格式文件。

<mimemap fileextension=".mov" mimetype="video/quicktime" />

如何识别?设置mime类型。以iis为例。除了可以在iis界面上直接设置,还可以在项目的web.config里设置。给个完整的例子

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.webserver>
        <directorybrowse enabled="true" />
        <defaultdocument>
            <files>
                <remove value="default.aspx" />
                <remove value="iisstart.htm" />
                <remove value="" />
                <remove value="index.htm" />
                <remove value="default.asp" />
                <remove value="default.htm" />
            </files>
        </defaultdocument>
        <staticcontent>
   <remove fileextension=".mp4" />
   <remove fileextension=".wasm" />
   <remove fileextension=".woff" />
   <remove fileextension=".woff2" />
   <remove fileextension=".mov" />
    
   <mimemap fileextension=".mp4" mimetype="video/mpeg" />
            <mimemap fileextension=".wasm" mimetype="application/wasm" />
            <mimemap fileextension=".woff" mimetype="application/font-woff" />
            <mimemap fileextension=".woff2" mimetype="application/font-woff2" />
   <mimemap fileextension=".mov" mimetype="video/quicktime" />
        </staticcontent>
        <httpprotocol>
            <customheaders>
                <add name="access-control-allow-origin" value="*" />
            </customheaders>
        </httpprotocol>
        <caching>
            <profiles>
                <add extension=".png" policy="cacheuntilchange" kernelcachepolicy="cacheuntilchange" />
                <add extension=".jpg" policy="cacheuntilchange" kernelcachepolicy="cacheuntilchange" />
                <add extension=".css" policy="cacheuntilchange" kernelcachepolicy="cacheuntilchange" />
                <add extension=".js" policy="cacheuntilchange" kernelcachepolicy="cacheuntilchange" />
            </profiles>
        </caching>
    </system.webserver>
</configuration>

2、html

<!doctype html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<style>
body,center{
padding:0;
margin:0;
}
</style>
</head>
<body>
  <center>
  <video id="video"  width="640" height="480" muted controls autoplay="autoplay" preload="auto" >
    <source src="月半湾.mov" />
    您的浏览器不支持 html5 video 标签。
  </video>
  </center>
</body>
</html>

本例会自动播放。自动播放的关键是“muted”属性(静音),否则无论是声明autoplay=“autoplay”,还是用脚本video.play()都不起作用。这个应该是故意设计成这样的。否则,打开就自动播放,万一是爱情动作片怎么办?如果静音就少了许多顾虑。

总结

以上所述是小编给大家介绍的html5自动播放mov格式视频的实例代码,希望对大家有所帮助

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网