首页 > 代码库 > Video.js事件
Video.js事件
Home
膘叔 » Archives文章: 备份一个video的JS [打印]
分类: Javascript
作者: gouki
2012-02-16 17:58
备份一个JS,不是为了代码很优秀,而是。。。想直接用里面的事件,就当成参考了:
JavaScript代码
- var media_events=new Array();
- // was extracted from the spec in November 2011
- media_events["loadstart"]=0;
- media_events["progress"]=0;
- media_events["suspend"]=0;
- media_events["abort"]=0;
- media_events["error"]=0;
- media_events["emptied"]=0;
- media_events["stalled"]=0;
- media_events["loadedmetadata"]=0;
- media_events["loadeddata"]=0;
- media_events["canplay"]=0;
- media_events["canplaythrough"]=0;
- media_events["playing"]=0;
- media_events["waiting"]=0;
- media_events["seeking"]=0;
- media_events["seeked"]=0;
- media_events["ended"]=0;
- media_events["durationchange"]=0;
- media_events["timeupdate"]=0;
- media_events["play"]=0;
- media_events["pause"]=0;
- media_events["ratechange"]=0;
- media_events["volumechange"]=0;
- var media_controller_events=new Array();
- // was extracted from the spec in November 2011
- media_controller_events["emptied"]=0;
- media_controller_events["loadedmetadata"]=0;
- media_controller_events["loadeddata"]=0;
- media_controller_events["canplay"]=0;
- media_controller_events["canplaythrough"]=0;
- media_controller_events["playing"]=0;
- media_controller_events["ended"]=0;
- media_controller_events["waiting"]=0;
- media_controller_events["durationchange"]=0;
- media_controller_events["timeupdate"]=0;
- media_controller_events["play"]=0;
- media_controller_events["pause"]=0;
- media_controller_events["ratechange"]=0;
- media_controller_events["volumechange"]=0;
- // was extracted from the spec in November 2011
- var media_properties=[ "error","src","currentSrc","crossOrigin","networkState","preload","buffered","readyState","seeking","currentTime","initialTime","duration","startOffsetTime","paused","defaultPlaybackRate","playbackRate","played","seekable","ended","autoplay","loop","mediaGroup","controller","controls","volume","muted","defaultMuted","audioTracks","videoTracks","textTracks","width","height","videoWidth","videoHeight","poster" ];
- var media_properties_elts=null;
- var webm=null;
- function init(){
- document._video=document.getElementById("video");
- webm=document.getElementById("webm");
- init_events();
- init_properties();
- init_mediatypes();
- // properties are updated even if no event was triggered
- setInterval(update_properties,500);
- }
- document.addEventListener("DOMContentLoaded",init,false);
- function init_events(){
- for(key in media_events){
- document._video.addEventListener(key,capture,false);
- }
- var tbody=document.getElementById("events");
- var i=1;
- var tr=null;
- for(key in media_events){
- if(tr==null) tr=document.createElement("tr");
- var th=document.createElement("th");
- th.textContent=key;
- var td=document.createElement("td");
- td.setAttribute("id","e_"+key);
- td.innerHTML="0";
- td.className="false";
- tr.appendChild(th);
- tr.appendChild(td);
- if((i++%5)==0){
- tbody.appendChild(tr);
- tr=null;
- }
- }
- if(tr!=null) tbody.appendChild(tr);
- }
- function init_properties(){
- var tbody=document.getElementById("properties");
- var i=0;
- var tr=null;
- media_properties_elts=new Array(media_properties.length);
- do{
- if(tr==null) tr=document.createElement("tr");
- var th=document.createElement("th");
- th.textContent=media_properties[i];
- var td=document.createElement("td");
- td.setAttribute("id","p_"+media_properties[i]);
- var r=eval("document._video."+media_properties[i]);
- td.innerHTML=r;
- if(typeof(r)!="undefined"){
- td.className="true";
- }else{
- td.className="false";
- }
- tr.appendChild(th);
- tr.appendChild(td);
- media_properties_elts[i]=td;
- if((++i%3)==0){
- tbody.appendChild(tr);
- tr=null;
- }
- }while(i<media_properties.length);
- if(tr!=null) tbody.appendChild(tr);
- }
- function init_mediatypes(){
- var tbody=document.getElementById("m_video");
- var i=0;
- var tr=document.createElement("tr");
- var videoTypes=[ "video/ogg","video/mp4","video/webm" ];
- i=0;
- tr=document.createElement("tr");
- do{
- var td=document.createElement("th");
- td.innerHTML=videoTypes[i];
- tr.appendChild(td);
- }while(++i<videoTypes.length);
- tbody.appendChild(tr);
- i=0;
- tr=document.createElement("tr");
- if(!!document._video.canPlayType){
- do{
- var td=document.createElement("td");
- var support=document._video.canPlayType(videoTypes[i]);
- td.innerHTML=‘"‘+support+‘"‘;
- if(support==="maybe"){
- td.className="true";
- }else if(support===""){
- td.className="false";
- }
- tr.appendChild(td);
- }while(++i<videoTypes.length);
- tbody.appendChild(tr);
- }
- }
- function capture(event){
- media_events[event.type]=media_events[event.type]+1;
- for(key in media_events){
- var e=document.getElementById("e_"+key);
- if(e){
- e.innerHTML=media_events[key];
- if(media_events[key]>0) e.className="true";
- }
- }
- update_properties();
- }
- function update_properties(){
- var i=0;
- for(key in media_properties){
- var val=eval("document._video."+media_properties[key]);
- /*
- if (typeof val === "TimesRanges") {
- val = val.length + " TimeRanges";
- }
- */
- media_properties_elts[i++].innerHTML=val;
- }
- if(!!document._video.audioTracks){
- var td=document.getElementById("m_audiotracks");
- td.innerHTML=document._video.audioTracks.length;
- td.className="true";
- }
- if(!!document._video.videoTracks){
- var td=document.getElementById("m_videotracks");
- td.innerHTML=document._video.videoTracks.length;
- td.className="true";
- }
- if(!!document._video.textTracks){
- var td=document.getElementById("m_texttracks");
- td.innerHTML=document._video.textTracks.length;
- td.className="true";
- }
- }
- var videos=new Array();
- videos[0]=[
- "http://media.w3.org/2010/05/sintel/poster.png","http://media.w3.org/2010/05/sintel/trailer.mp4","http://media.w3.org/2010/05/sintel/trailer.ogv","http://media.w3.org/2010/05/sintel/trailer.webm"
- ];
- videos[1]=[
- "http://media.w3.org/2010/05/bunny/poster.png","http://media.w3.org/2010/05/bunny/trailer.mp4","http://media.w3.org/2010/05/bunny/trailer.ogv"
- ];
- videos[2]=[
- "http://media.w3.org/2010/05/bunny/poster.png","http://media.w3.org/2010/05/bunny/movie.mp4","http://media.w3.org/2010/05/bunny/movie.ogv"
- ];
- videos[3]=[
- "http://media.w3.org/2010/05/video/poster.png","http://media.w3.org/2010/05/video/movie_300.mp4","http://media.w3.org/2010/05/video/movie_300.ogv","http://media.w3.org/2010/05/video/movie_300.webm"
- ];
- function switchVideo(n){
- if(n>=videos.length) n=0;
- var mp4=document.getElementById("mp4");
- var ogv=document.getElementById("ogv");
- var parent=ogv.parentNode;
- document._video.setAttribute("poster",videos[n][0]);
- mp4.setAttribute("src",videos[n][1]);
- ogv.setAttribute("src",videos[n][2]);
- if(videos[n][3]){
- if(webm.parentNode==null){
- parent.insertBefore(webm,ogv);
- }
- webm.setAttribute("src",videos[n][3]);
- }else{
- if(webm.parentNode!=null){
- parent.removeChild(webm);
- }
- }
- document._video.load();
- }
这一段JS是从http://www.w3.org/2010/05/video/mediaevents.html拷贝而来,具体的演示就在这个页面了。我是想知道video标签中的一些事件。controller_event几乎用不到。 中文说明这里有:http://directguo.com/blog/index.php/2010/07/html5-audio-video-tag/
XML/HTML代码
- //错误状态
- Media.error; //null:正常
- Media.error.code; //1.用户终止 2.网络错误 3.解码错误 4.URL无效
- //网络状态
- Media.currentSrc; //返回当前资源的URL
- Media.src = value; //返回或设置当前资源的URL
- Media.canPlayType(type); //是否能播放某种格式的资源
- Media.networkState; //0.此元素未初始化 1.正常但没有使用网络 2.正在下载数据 3.没有找到资源
- Media.load(); //重新加载src指定的资源
- Media.buffered; //返回已缓冲区域,TimeRanges
- Media.preload; //none:不预载 metadata:预载资源信息 auto:
- //准备状态
- Media.readyState; //1:HAVE_NOTHING 2:HAVE_METADATA 3.HAVE_CURRENT_DATA 4.HAVE_FUTURE_DATA 5.HAVE_ENOUGH_DATA
- Media.seeking; //是否正在seeking
- //回放状态
- Media.currentTime = value; //当前播放的位置,赋值可改变位置
- Media.startTime; //一般为0,如果为流媒体或者不从0开始的资源,则不为0
- Media.duration; //当前资源长度 流返回无限
- Media.paused; //是否暂停
- Media.defaultPlaybackRate = value;//默认的回放速度,可以设置
- Media.playbackRate = value;//当前播放速度,设置后马上改变
- Media.played; //返回已经播放的区域,TimeRanges,关于此对象见下文
- Media.seekable; //返回可以seek的区域 TimeRanges
- Media.ended; //是否结束
- Media.autoPlay; //是否自动播放
- Media.loop; //是否循环播放
- Media.play(); //播放
- Media.pause(); //暂停
- //控制
- Media.controls;//是否有默认控制条
- Media.volume = value; //音量
- Media.muted = value; //静音
- //TimeRanges(区域)对象
- TimeRanges.length; //区域段数
- TimeRanges.start(index) //第index段区域的开始位置
- TimeRanges.end(index) //第index段区域的结束位置
借鉴一下。
标签: html5, video, audio
Powered by SaBlog-X (C) 2003-2005 Security Angel Team. XHTML 1.0
Video.js事件
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。