首頁  >  文章  >  web前端  >  詳解html5的video標籤測試應用

詳解html5的video標籤測試應用

零下一度
零下一度原創
2017-05-19 16:50:202706瀏覽

1、video標籤的使用

屬性:src(要播放的音訊檔案路徑)、autoplay(是否自動播放)、control(進度條)、loop(循環播放)、onended(是否播放完畢的是一個事件)

2、實作了一個簡單的播放器

介面如下:


##3、功能

主要透過onclick和onended事件來完成的,具體上面有的都實現了,不過音訊檔案的取名是有要求的,具體看代碼

4、代碼:

<!DOCTYPE HTML>
<html>
<head>
<title>播放视频</title>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
</head>
<body>
<p style="cursor:pointer;" onclick="javascript:playvideo(1);">播放视频</p>
<p style="cursor:pointer;" onclick="javascript:playvideo(2);">关闭视频</p>
<video id="video" style="width:1024px; height:600px; margin:0 auto; display:none;" src="./mybroadcast2.mkv" autoplay="autoplay" controls="controls" onended="javascript:videoover();" onclick="javascript:screen_stop();" ondblclick="javascript:double_click();">您的浏览器暂不支持播放该视频,请升级至最新版浏览器。</video>
<button id="hary_run" style="width:100px; height:35px; cursor:pointer;" onclick="javascript:controlTV(&#39;hary_run&#39;);">快进</button>
<button id="stop_run" style="width:100px; height:35px; cursor:pointer;" onclick="javascript:controlTV(&#39;stop_run&#39;);">暂停</button>
<button id="current_run" style="width:100px; height:35px; cursor:pointer;" disabled=true onclick="javascript:controlTV(&#39;current_run&#39;);">播放</button>
<button id="open_voice" style="width:100px; height:35px; cursor:pointer;" onclick="javascript:controlTV(&#39;open_voice&#39;);">静音</button>
<button id="close_voice" style="width:100px; height:35px; cursor:pointer;" disabled=true onclick="javascript:controlTV(&#39;close_voice&#39;);">取消静音</button>
</body>
<script>
function playvideo(type){
var openvideo = document.getElementById("video");
if (type == 1){
openvideo.style.display = "block";
} else if (type == 2){
openvideo.style.display = "none";
}
}
// 让视频循环列表播放
function videoover(){
var videoId = document.getElementById("video");
var video_path = videoId.src;
var path_begin = video_path.substring(0, video_path.lastIndexOf(".")-1);
var path_end = video_path.substring(video_path.lastIndexOf("."));
var num = parseInt(video_path.charAt(video_path.lastIndexOf(".")-1));
if (num >= 3) {
num = 0;
} else {
num++;
}
videoId.src = path_begin + num.toString() + path_end;
}
// 控制视频
function controlTV(oprationId){
var runId = document.getElementById(oprationId);
var btn_value = runId.innerText;
// 获取媒体播放Id
var videoId = document.getElementById("video");
if ("快进" == btn_value){
// 获取当前播放进度
var current_pro = videoId.currentTime;
videoId.currentTime = current_pro + 10;
} else if ("暂停" == btn_value) {
videoId.pause();
runId.disabled = true;
var broad_btn = document.getElementById("current_run");
broad_btn.disabled = false;
} else if ("播放" == btn_value) {
videoId.play();
runId.disabled = true;
var stop_btn = document.getElementById("stop_run");
stop_btn.disabled = false;
} else if ("静音" == btn_value) {
videoId.muted = true;
runId.disabled = true;
btn_disabled = document.getElementById("close_voice");
btn_disabled.disabled = false;
} else if ("取消静音" == btn_value) {
videoId.muted = false;
runId.disabled = true;
var btn_disabled = document.getElementById("open_voice");
btn_disabled.disabled = false;
}
}
function screen_stop(){
// 获取媒体播放Id
var videoId = document.getElementById("video");
// 判断是否已暂停
if (videoId.paused) {
videoId.play();
} else {
videoId.pause();
}
}
/*----------------------------------兼容性解决方案---------------------------------------------*/
// 进入全屏
function requestFullScrren(){
var de = document.documentElement;
if (de.requestFullscreen) {
// W3C 提议
de.requestFullscreen();
} else if (de.mozRequestFullScreen) {
// Firefox 10+
de.moRequestFullScreen();
} else if (de.webkitRequestFullScreen) {
// Webkit (works in Safari5.1 and Chrome 15)
de.webkitRequestFullScreen();
}
}
// 退出全屏
function exitFullScreen(){
var de = document;
if (de.exitFullscreen) {
// W3C 提议
de.exitFullscreen();
} else if (de.mozCancelFullScreen) {
// Firefox 10+
de.mozCancelFullScreen();
} else if (de.webkitCancelFullScreen) {
// Webkit (works in Safari5.1 and Chrome 15)
de.webkitCancelFullScreen();
}
}
// 双击全屏
function double_click(){
if (requestFullScrren) {
requestFullScrren();
} else {
exitFullScreen();
}
}
// 自动加载默认配置(未完成)
/**function onload_property(){
// 获取媒体播放Id
var videoId = document.getElementById("video");
var file = new ActiveXObject("Scripting.FileSystemObject");
var inputStream = file.OpenTextFile("customvideo.properties");
var content = "";
while(!inputStream.atEndOfLine){
content + inputStream.readLine + "\n";
}
inputStream.close();
}
window.onload = onload_property;**/
</script>
</html>

【相關推薦】

#1.

 H5 video標籤只能放聲音不能放影片的解決方法

#2. 

IIS的MIME未註冊MP4類型,導致無法識別vidoe標籤的解決方案

3. 

分享HTML5製作Banner的實例

4. 

概述HTML5的強大與未來發展

5. 

最新的h5標籤datalis的使用方法介紹

以上是詳解html5的video標籤測試應用的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn