擷取並設定HTML5 Video的當前進度,html5video

來源:互聯網
上載者:User

擷取並設定HTML5 Video的當前進度,html5video

上周翻譯了一篇文章: 如何擷取HTML5視頻的期間。很顯然這是一門簡單卻很實用的技術, 但我認為還有一個更重要的知識點是控制視頻的時間設定。在用HTML5技術處理視頻時,設定(setting)和擷取(getting)時間都是很有用的,那就讓我們一起來看看如何達成這個 目標吧!

在管理視頻狀態時,最重要的是要瞭解 currentTime 是個什麼鬼。你可以通過這個屬性擷取當前播放至了哪個時間點:

// https://www.youtube.com/watch?v=Cwkej79U3ekconsole.log(video.currentTime);  // 25.431747

currentTime 既是 getter 又是 setter 屬性, 所以可以直接設定 currentTime 值來控制播放進度:

video.currentTime = 0; // Restart

API 介面很容易理解,而且是自解釋的(self-explanatory)。你仍然需要處理“second”來指定時間,包括內在實際的和外在顯示的(both inward and outward),但是秒(second)這個單位和你預期的一樣公平,所以說這個API設計是非常巧妙的。

樣本可以參考 小米空氣淨化器的示範頁面: http://www.mi.com/air/

<video id="videoIntro" class="video"     data-video-name="intro"     poster="http://c1.mifile.cn/f/i/2014/cn/goods/air/overall/video-main-poster.jpg"    >        <source type="video/mp4"     src="http://c1.mifile.cn/f/i/2014/cn/goods/air/overall/video-intro.mp4?2014120901">        <source type="video/webm"    src="http://c1.mifile.cn/f/i/2014/cn/goods/air/overall/video-intro.webm?2014120901"></video>

此外,蘋果官網的示範也採用這樣的控制模式。

原文連結: http://davidwalsh.name/html5-video-current-time

原文日期: 2015年03月16日

翻譯日期: 2015年03月21日

翻譯人員: 鐵錨 http://blog.csdn.net/renfufei

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.