在 html 中播放視頻的方法有很多種<video width="320" height="240" controls> <source src="/static/i/html/html_video_1. mp4" type="video/mp4"> <source src="/static/i/html/html_video_1.ogg" type="video/ogg"> <source src="/static/i/html/html_video_1.webm" type="video/webm"> <object data="/static/i/html/html_video_1. mp4" width="320" height="240"> <embed src="/static/i/html/html_video_1.swf" width="320" height="240"> </object> </video> 問題以及解決方法在 HTML 中播放視頻并不容易 需要諳熟大量技巧,以確保視頻文件在所有瀏覽器中(Internet Explorer,Chrome,Firefox,Safari,Opera)和所有硬件上(PC,Mac,iPad,iPhone)都能夠播放 本節(jié),我們就來介紹在 HTML 中嵌入視頻碰到的問題和解決辦法。 使用 <embed> 標(biāo)簽<embed> 標(biāo)簽的作用是在 HTML 頁面中嵌入多媒體元素 下面的 HTML 代碼顯示嵌入網(wǎng)頁的 Flash 視頻 <embed src="intro.swf" height="200" width="200"> 問題
使用 <object> 標(biāo)簽<object> 標(biāo)簽的作用是在 HTML 頁面中嵌入多媒體元素 下面的 HTML 片段顯示嵌入網(wǎng)頁的一段 Flash 視頻 <object data="/static/i/html/intro.swf" height="200" width="200"></object> 問題
使用 HTML5 <video> 元素HTML5 <video> 標(biāo)簽定義了一個視頻或者影片 <video> 元素在所有現(xiàn)代瀏覽器中都支持 以下 HTML 片段會顯示一段嵌入網(wǎng)頁的 ogg、mp4 或 webm 格式的視頻 <video width="320" height="240" controls> <source src="/static/i/html/html_video_1. mp4" type="video/mp4"> <source src="/static/i/html/html_video_1.ogg" type="video/ogg"> <source src="/static/i/html/html_video_1.webm" type="video/webm"> </video> 問題
最好的 HTML 解決方法下面的范例中使用了 4 中不同的視頻格式 HTML 5 <video> 元素會嘗試播放以 mp4、ogg 或 webm 格式中的一種來播放視頻 如果均失敗,則回退到 <embed> 元素 <video width="320" height="240" controls> <source src="/static/i/html/html_video_1. mp4" type="video/mp4"> <source src="/static/i/html/html_video_1.ogg" type="video/ogg"> <source src="/static/i/html/html_video_1.webm" type="video/webm"> <object data="/static/i/html/html_video_1. mp4" width="320" height="240"> <embed src="/static/i/html/html_video_1.swf" width="320" height="240"> </object> </video> 問題
優(yōu)酷解決方案在 HTML 中顯示視頻的最簡單的方法是使用優(yōu)酷等視頻網(wǎng)站。 如果希望在網(wǎng)頁中播放視頻,那么可以把視頻上傳到優(yōu)酷等視頻網(wǎng)站,然后在您的網(wǎng)頁中插入 HTML 代碼即可播放視頻 <embed src="http://player.youku.com/player.PHP/sid/XMzI2NTc4NTMy/v.swf" width="480" height="400" type="application/x-shockwave-flash"> </embed> 使用超鏈接如果網(wǎng)頁包含指向媒體文件的超鏈接,大多數(shù)瀏覽器會使用"輔助應(yīng)用程序"來播放文件 以下代碼片段顯示指向 AVI 文件的鏈接 如果用戶點擊該鏈接,瀏覽器會啟動"輔助應(yīng)用程序",比如 Windows Media Player 來播放這個 AVI 文件 <a href="/static/i/html/intro.swf">Play a video file</a> 關(guān)于內(nèi)聯(lián)視頻的說明當(dāng)視頻被包含在網(wǎng)頁中時,它被稱為內(nèi)聯(lián)視頻 如果打算在 web 應(yīng)用程序中使用內(nèi)聯(lián)視頻,需要意識到很多人都覺得內(nèi)聯(lián)視頻令人惱火 同時請注意,用戶可能已經(jīng)關(guān)閉了瀏覽器中的內(nèi)聯(lián)視頻選項 所以我們建議只在用戶希望看到內(nèi)聯(lián)視頻的地方包含它們 一個正面的例子是,在用戶需要看到視頻并點擊某個鏈接時,會打開頁面然后播放視頻。 |