video事件
/*
* video播放器
*/
* @ src: 指定所要嵌入视频、文档的URL。
* @ poster: 视频预览图像
* @ autoplay: 视频自动播放
* @ loop: 循环播放
* @ muted: 是否静音
* @ controls: 视频控件
* @ preload: 用于指定是否提前下载,怎样提前下载视频数据,给用户代理相应的提示。autoplay:preload属性将无效
* @ 1. auto:尽可能提前下载视频
* @ 2.metadata:只下载视频的meta信息部分。Meta信息中收集了关于视频的长度、视频的起始祯的图像、视频的长度等信息
/*
* video事件
*/
* @ canPlayType: 检查是否支持HTML5 video元素并且执行所有其他代码, 如果不支持视频, 返回false并显示一条消息
* @ canplay: 通知何时视频加载内容已足够用于开始播放
* @ loadedmetadata: 获取视频的长度, 才有duration属性
* @ timeupdate: 获取视频中的当前位置, 当currentTime属性发生更改时, 引发ontimeupdate事件,在事件处理程序中,从视频对象中检索 currentTime的值并进行显示。currentTime 属性是浮点型变量,该变量可以从 12 位中获取小数位置。但是,出于性能方面的考虑,在 Windows Internet Explorer中一秒内仅引发该事件四次。若要在示例中显示,则需要使用 "toFixed()" 方法将 currentTime 取舍为一位。运行视频时,会更新和显示当前时间。
* @ playing: 点击视频播放
* @ pause: 点击视频暂停
* @ volumechange: 视频静音设置
/*
* video属性
*/
* @ play: 视频的播放
* @ pause: 视频的暂停
* @ paused: 检查video是否在暂停
* @ volume: 获取或设置音量
* @ duration: 获取视频总时间
* @ currentTime: 获取当前播放时间
* @ playbackRate属性: 视频播放速度
HTMl <embed>
<embed src="http://gz.chimelong.com/happy/images/banner/happy08.mp4" autostart="false" type="application/x-shockwave-flash" allowfullscreen="false" allowscriptaccess="always" width="300" height="200"/>
hidden设置播放面板的显示和隐藏,hidden有两个值:true(隐藏)和no(显示); autostart设置多媒体内容的播放方式, autostart 有两个值:true(自动播放)和no(不自动播放); loop设定是否循环播放, loop有两个值:true(无限次循环播放)no(仅播放一次)。 starttime开始时间,值为"mm:ss" ,表示多久后开始播放。 volume调节音量:, 属性规定音频或视频文件的音量大小。值在0~100之间的整数。
HTML5: video事件
<video id="thevideo" autoplay width="300" height="200" poster="/images/video.png">
<source src="http://gz.chimelong.com/happy/images/banner/happy08.mp4" type="video/mp4" >
<!-- IE低版本 -->
<object>
<embed src="http://gz.chimelong.com/happy/images/banner/happy08.mp4" type= "application/x-shockwave-flash" allowfullscreen="false" allowscriptaccess="always" width="300" height="200"/>
</object>
</video>
<div id="wrap">
<button id="play" title="play">播放</button>
<button id="restart" title="restart">重播一次</button>
<button id="rew" title="rew">快退</button>
<button id="forward" title="forward">前进</button>
<button id="slower" title="slower">慢速</button>
<button id="mormal" title="mormal">常速</button>
<button id="faster" title="faster">快速</button>
<button id="volumeUp" title="volumeUp">音量+</button>
<button id="volumeDown" title="volumeDown">音量-</button>
<button id="mute" title="mute">静音</button>
<div id="vLength"></div>
<div id="curTime"></div>
<div id="vRemaining"></div>
<div id="mutetext"></div>
<div id="errorMsg"></div>
<!-- <img src="/images/3.png" id="rotateVideo" alt=""> -->
</div>
<div title="Event status area" >
<label>oncanplaythrough: </label><span class="stats" id="cpt"></span><br />
<label>onloadstart: </label><span class="stats" id="ls"></span><br />
<label>onprogress: </label><span class="stats" id="pg"></span><br />
<label>onloadeddata: </label><span class="stats" id="ld"></span><br />
<label>onended: </label><span class="stats" id="ndd"></span><br />
<label>onemptied: </label><span class="stats" id="mt"></span><br />
<label>onstalled: </label><span class="stats" id="stall"></span><br />
<label>onwaiting: </label><span class="stats" id="waiting"></span><br />
<label>ondurationchange: </label><span class="stats" id="dc"></span><br />
</div>
(function(){
var video = document.getElementById("thevideo");
var vLength;
var pgFlag = ""; //used for progress tracking
if(video.canPlayType){ //tests that we have HTML5 video support
//video button helper functions;
//play video
function vidplay(evt){
if(video.paused){
video.play();
document.getElementById("play").innerHTML = "暂停";
}else{
video.pause();
document.getElementById("play").innerHTML = "播放"
}
}
video.addEventListener("canplay",function(){
document.getElementById("wrap").style.display = "block";
video.controls = true;
},false)
//button helper functions
//skip,forward,backwrap,or restart
function setTime(tValue){
//if no video is loaded,this throws an exception
try{
if(tValue == 0){
video.currentTime = tValue;
video.play(); //如果是暂停后再按重放键会重置到开始是暂停状态,所以要开启
}else{
video.currentTime += tValue;
}
}catch(err){
errMessage("Video content might not be loaded");
}
}
//change volume based on incoming value
function setVol(value){
var vol = video.volume;
vol = (vol + value).toFixed(1);
//test for range 0 - 1 to avoid exceptions
if(vol >= 0 && vol <= 1){
video.volume = vol;
}else{
video.volume = (vol < 0) ? 0 : 1;
}
}
//点击视频内容播放暂停
var borwser = (function(){
var s = navigator.userAgent.toLowerCase();
var match = /(webkit)[ \/]([\w.]+)/.exec(s)||/(opera)(?:.*version)?[ \/]([\w.]+)/.exec(s)||(!!window.ActiveXObject || "ActiveXObject" in window) && /(msie\s|rv:)([\w.]+)/.exec(s)||!/compatible/.test(s) && /(mozilla)(?:.*? rv:([\w.]+))?/.exec(s) ||[];
return {name : match[1] || "",version : match[2] || "0"};
})();
if(borwser.name !== "mozilla"){
video.addEventListener("click",vidplay,false);
console.log("非火狐浏览器")
}else{
console.log("火狐浏览器")
}
//chrome和opera双击全屏
if(borwser.name === "webkit"){
//chrome的双击视频画面全屏
var count = 0;
video.addEventListener("dblclick",function(){
if(count % 2 == 0){
video.webkitRequestFullScreen();
}else{
// video.exitFullscreen();
document.webkitCancelFullScreen();
console.log("退出全屏")
}
count++;
},false);
}
//play
document.getElementById("play").addEventListener("click",vidplay,false);
//restart
document.getElementById("restart").addEventListener("click",function(){
setTime(0);
},false);
//Skip backwrad 10 seconds
document.getElementById("rew").addEventListener("click",function(){
setTime(-10);
},false);
//Skip forward 10 seconds
document.getElementById("forward").addEventListener("click",function(){
setTime(10);
},false);
//volume buttons
document.getElementById("volumeDown").addEventListener("click",function(){
setVol(-.1); //down by 10%;
},false);
document.getElementById("volumeUp").addEventListener("click",function(){
setVol(.1); //up by 10%;
},false);
//playback speed buttons
document.getElementById("slower").addEventListener("click",function(){
video.playbackRate -= .25;
},false);
document.getElementById("faster").addEventListener("click",function(){
video.playbackRate += .25;
},false);
document.getElementById("mormal").addEventListener("click",function(){
video.playbackRate = 1;
},false);
//mute
document.getElementById("mute").addEventListener("click",function(){
if(video.muted){
video.muted = false;
}else{
video.muted = true;
}
},false);
//paused and playing events to control buttons
video.addEventListener("pause",function(){
document.getElementById("play").innerHTML = "播放";
},false);
video.addEventListener("playing",function(){
document.getElementById("play").innerHTML = "暂停";
},false);
//display video duration when availbale
video.addEventListener("loadedmetadata",function(){
vLength = video.duration.toFixed(1);
document.getElementById("vLength").innerHTML = "视频时间长度:" + vLength + "秒";
},false)
//display the current and remaining times
video.addEventListener("timeupdate",function(){
var vTime = video.currentTime;
document.getElementById("curTime").innerHTML = "当前播放时间:" + vTime.toFixed(1) + "秒";
document.getElementById("vRemaining").innerHTML = "当前播放时间:" + (vLength - vTime).toFixed(1) + "秒";
},false);
//onvolumechange controls mute
video.addEventListener("volumechange",function(){
if(video.muted){
document.getElementById("mutetext").innerHTML = "声音:静音";
}else{
document.getElementById("mutetext").innerHTML = "音量:" + video.volume;
}
},false);
//any video error will fail with message
video.addEventListener("error",function(err){
errMessage(err);
},false);
//Download and playback status events
//页面加载时出现
video.addEventListener("loadstart",function(){
document.getElementById("ls").innerHTML = "Stared";
},false);
//视频加载完后才出现
video.addEventListener("loadeddata",function(){
document.getElementById("ld").innerHTML = "Data was loaded";
},false);
//视频播放结束后触发
video.addEventListener("ended",function(){
document.getElementById("ndd").innerHTML = "Playback ended;";
},false);
//重置为初始状态下触发
video.addEventListener("emptied",function(){
document.getElementById("mt").innerHTML = "Video reset";
},false);
//在下载被中断三秒以上时引发.网络差时触发
video.addEventListener("stalled",function(){
document.getElementById("stall").innerHTML = "Download was stalled";
},false);
//播放下一帧不可用时触发(断网或者缓冲情况下)
video.addEventListener("waiting",function(){
document.getElementById("waiting").innerHTML = "Player waited for content";
},false);
//指示正在下载媒体内容,下载完后停止
video.addEventListener("progress",function(){
pgFlag += ".";
if(pgFlag.length > 10){
pgFlag = ".";
}
document.getElementById("pg").innerHTML = pgFlag;
},false);
//在onloadstart之后和onloadedmetadata(确定时间)之前主立即引发
video.addEventListener("durationchange", function () {
document.getElementById("dc").textContent = "Duration has changed";
}, false);
//在不需要进一步缓冲就可以播放直至文件结束时引发
video.addEventListener("canplaythrough", function () {
document.getElementById("cpt").textContent = "Ready to play whole video";
}, false);
function errMessage(msg){
//display an error message for 5 seconds then clears it;
document.getElementById("errorMsg").innerHTML = msg;
setTimeout(function(){
document.getElementById("errorMsg").innerHTML = "";
},5000);
}
}else{
errMessage("HTML5 Video is required for this example");
}
}())
video事件的更多相关文章
- Video事件、方法-- DOM
<video> 元素同样拥有方法.属性和事件.其中的方法用于播放.暂停以及加载等.其中的属性(比如时长.音量等)可以被读取或设置.其中的 DOM 事件能够通知您,比方说,<video ...
- HTML5 video 事件
1.获取视频时间长度 当视频载入video后,使用 onloadedmetadata 事件获取视频的时间长度. video.onloadedmetadata = function () { var v ...
- H5的Video事件,控制方法,及监听
1.标签基本属性 src :视频的属性 poster:视频封面,没有播放时显示的图片preload:预加载autoplay:自动播放loop:循环播放controls:浏览器自带的控制条width:视 ...
- video 属性和事件用法大全
1.video 属性 <!-- video 不支持 IE8及以下版本浏览器,支持三种视频格式:MP4,WebM 和 Ogg --> <video src="test.mp4 ...
- video.js--很赞的H5视频播放库
video.js是一款很流行的html5视频播放插件.很适合在移动端播放视频(比如微信网页),功能强大,且支持降级到flash,兼容ie8.官网:http://videojs.com/ git& ...
- video.js-H5视频播放库
video.js是一款很流行的html5视频播放插件.很适合在移动端播放视频(比如微信网页),功能强大,且支持降级到flash,兼容ie8.官网:http://videojs.com/ git& ...
- 移动端HTML5<video>视频播放优化实践
遇到的挑战 移动端HTML5使用原生<video>标签播放视频,要做到两个基本原则,速度快和体验佳,先来分析一下这两个问题. 下载速度 以一个8s短视频为例,wifi环境下提供的高清视频达 ...
- 移动端HTML5<video>视频播放优化实践[转]
http://blog.csdn.net/u010918416/article/details/52705732 http://www.xuanfengge.com/html5-video-play. ...
- ActionScript 3.0 API 中的 Video 类
注:这个类在Flash流媒体开发中使用的很频繁,在此记录一下它的使用方法. 包 flash.media 类 public class Video 继承 Video DisplayObject Ev ...
随机推荐
- hibernate不调用save也保存上了
List<Instrument> insts = instService.search(search); if (insts.size() == 1) { Instrument inst ...
- 如何修复U盘提示被写保护的问题
最近一客户来店里说新买的U盘没用多久,在复制文件时提示:该磁盘已被写保护! 打不开U盘,并且也不能格式化,在DOS下重新给U盘分区也没用. 今天鼎盛电脑科技服务部的工程师就帮大家解决这个问题. 首先客 ...
- 【转】MFC WM_USER和WM_APP
WM_USER常量是Windows帮助应用程序定义私有窗口类里的私有消息,通常使用WM_USER+一个整数值,但总值不能超过0x7FFF. #define WM_USER 0x0400 W ...
- am335x phy led problem
问题描述 连接网线的情况下,每次进行软件"reboot",网口的LINK LED能够正常的熄灭,而ACTIVE LED却是亮的. reboot重启之后,LINK的灯正常变亮,而AC ...
- Checked Exception & Unchecked Exception
查Spring事务管理时看到一句话: Spring使用声明式事务处理,默认情况下,如果被注解的数据库操作方法中发生了unchecked异常,所有的数据库操作将rollback:如果发生的异常是chec ...
- wampserver下配置虚拟主机 实现多站点支持
wampserver下配置虚拟主机 实现多站点支持 wampserver是由德国人开发,在windows环境下实现apache+php+mysql的一款集成环境软件,wampserver自带SQLit ...
- MVC演化 (转至http://www.cnblogs.com/wubaiqing/archive/2011/10/26/2225438.html)
MVC已经成为我们最常误用的模式,人们之所以常常误用MVC,很大程度上是因为混淆了不同的MVC变体. Classic MVC Classic MVC 大概上世纪七十年代,Xerox PARC的Tryg ...
- Python的可变对象与不可变对象。
参考:http://thomaschen2011.iteye.com/blog/1441254 Python基础:Python可变对象和不可变对象 http://blog.jobbo ...
- HGNC 数据库-人类基因组数据库
HGNC 全称为HUGO Gene Nomenclature Committee, 叫做 HUGO基因命名委员会,负责对人类基因组上包括蛋白编码基因, ncRNA基因,甲基因和其他基因在内的所有基因提 ...
- perl 面向对象编程
今天看到一个perl面向对象编程的例子,充分体现了如何对数据进行封装: 自己模仿写一个读取配置文件的例子, 配置文件的内容如下 samtools_binary = /usr/bin/samtools ...