App下載

前端中怎么自動播放mov格式視頻?實例代碼分享!

我的夏天來了 2021-08-10 16:04:13 瀏覽數(shù) (5190)
反饋

對于視頻自動播放大家應(yīng)該都不陌生那么今天我們來說說:“前端中怎么自動播放mov格式視頻?”這個問題的方法和相關(guān)的解決內(nèi)容吧! 

這個問題應(yīng)該這么看。

1、首先網(wǎng)站要支持.MOV格式文件

就是說,網(wǎng)站要能識別.MOV格式文件。

<mimeMap fileExtension=".mov" mimeType="video/quicktime" />

如何識別?設(shè)置MIME類型。以IIS為例。除了可以在IIS界面上直接設(shè)置,還可以在項目的web.config里設(shè)置。給個完整的例子

<?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="index.html" />
                <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>

本例會自動播放。自動播放的關(guān)鍵是“muted”屬性(靜音),否則無論是聲明autoplay=“autoplay”,還是用腳本video.play()都不起作用。這個應(yīng)該是故意設(shè)計成這樣的。否則,打開就自動播放,萬一是愛情動作片怎么辦?如果靜音就少了許多顧慮。

總結(jié)

對于:“前端中怎么自動播放mov格式視頻? ”這個問題,我們的解決方法和相關(guān)內(nèi)容都在文章中可以了解到! 希望對大家有所幫助,更多的內(nèi)容我們可以在W3Cschool中進行學習和了解! 

0 人點贊