作为HTML5的一部分,<video> 可以通用CSS和JavaScript来定制和操作,使得我们能够用一种不错的方式对用户观看的视频加以处理。以此为题材,我们可以做出一个很实用的组件——live video ,以下为截图:
首先扩展Ext.Panel使其可以播放HTML5的视频:
Ext.ns('Ext.ux'); /* -NOTICE- * For HTML5 video to work, your server must * send the right content type, for more info see: * http://developer.mozilla.org/En/HTML/Element/Video */ Ext.ux.HTML5VideoPanel = Ext.extend(Ext.Panel, { constructor: function(config) { Ext.ux.HTML5VideoPanel.superclass.constructor.call(this, Ext.applyIf(config, { width : '100%', height : '100%', autoplay : false, controls : true, bodyStyle: 'background-color:#000;color:#fff', html : '', suggestChromeFrame: false })); this.on({ scope : this, render : this._render, beforedestroy: function() { this.video = null; }, bodyresize : function(panel, width, height) { if (this.video) this.video.setSize(width, height); } }); }, _render: function() { var fallback = ''; if (this.fallbackHTML) { fallback = this.fallbackHTML; } else { fallback = "Your browser doesn't support html5 video. "; if (Ext.isIE && this.suggestChromeFrame) { /* chromeframe requires that your site have a special tag in the header * see http://code.google.com/chrome/chromeframe/ for details */ fallback += '<a>Get Google Chrome Frame for IE</a>'; } else if (Ext.isChrome) { fallback += '<a>Upgrade Chrome</a>'; } else if (Ext.isGecko) { fallback += '<a>Upgrade to Firefox 3.5</a>'; } else { fallback += '<a>Get Firefox 3.5</a>'; } } /* match the video size to the panel dimensions */ var size = this.getSize(); var cfg = Ext.copyTo({ tag : 'video', width : size.width, height: size.height }, this, 'poster,start,loopstart,loopend,playcount,autobuffer,loop'); /* just having the params exist enables them */ if (this.autoplay) cfg.autoplay = 1; if (this.controls) cfg.controls = 1; /* handle multiple sources */ if (Ext.isArray(this.src)) { cfg.children = []; for (var i = 0, len = this.src.length; i < len; i++) { if (!Ext.isObject(this.src[i])) { throw "source list passed to html5video panel must be an array of objects"; } cfg.children.push( Ext.applyIf({tag: 'source'}, this.src[i]) ); } cfg.children.push({ html: fallback }); } else { cfg.src = this.src; cfg.html = fallback; } this.video = this.body.createChild(cfg); } }); Ext.reg('html5video', Ext.ux.HTML5VideoPanel);
将html5video panel添加到一个web desktop window,canvas preview 添加到taskbar按钮:
Desktop.VideoWindow = Ext.extend(Ext.app.Module, { id: 'video-win', init: function() { this.launcher = { text : 'Video Window', iconCls: 'icon-grid', handler: this.createWindow, scope : this }; }, createWindow: function() { var win, tipWidth = 160, tipHeight = 96; /* createWindow uses renderTo, so it is immediately rendered */ win = this.app.getDesktop().createWindow({ animCollapse : false, constrainHeader: true, title : 'Video Window', width : 740, height : 480, iconCls: 'icon-grid', shim : false, border : false, layout : 'fit', items: [{ xtype: 'html5video', src: [ // firefox (ogg theora) { src : 'http://xant.us/files/google_main.ogv', type: 'video/ogg' }, // chrome and webkit-nightly (h.264) { src : 'http://xant.us/files/google_main.mgv', type: 'video/mp4' } ], autobuffer: true, autoplay : true, controls : true, /* default */ listeners: { afterrender: function() { var win = this.ownerCt; win.videoEl = this.video.dom; win.tip = new Ext.ToolTip({ anchor : 'bottom', autoHide : true, hideDelay: 300, height : tipHeight, width : tipWidth, bodyCfg : { tag : 'canvas', width : tipWidth, height : tipHeight }, listeners: { afterrender: function() { /* get the canvas 2d context */ win.ctx = this.body.dom.getContext('2d'); } } }); } } }], listeners: { beforedestroy: function() { win.tip = win.ctx = win.videoEl = null; } } }); win.show(); win.tip.initTarget(win.taskButton.el); win.tip.on('show', this.renderPreview.createDelegate(this, [win])); }, renderPreview: function(win) { if ((win.tip && ! win.tip.isVisible()) || !win.videoEl) return; if (win.ctx) { win.ctx.drawImage(win.videoEl, 0, 0, win.tip.width, win.tip.height); } /* 20ms to keep the tooltip video smooth */ this.renderPreview.defer(20, this, [win]); } });
在靠近sample.js顶部的位置,为getModules添加app constructor:
getModules : function(){ return [ new MyDesktop.GridWindow(), new MyDesktop.TabWindow(), new MyDesktop.AccordionWindow(), new MyDesktop.BogusMenuModule(), new MyDesktop.BogusModule(), /* add the line below, and don't forget the comma above */ new MyDesktop.VideoWindow() ]; }
相关阅读 完美视频怎么使用说明 完美视频播放器怎么用看韩剧用什么播放器好 看韩剧用什么软件优酷怎么1元开通会员 优酷会员1元购买方法b站播放器绿屏卡顿花屏怎么办 bilibili播放器常见问题解决方法看视频用哪款软件好 全中国最好的几款视频app都在这里音乐达人必备 轻松玩转四款高人气音乐app免费看片播放器大全 免费看片播放器推荐 免费看片播放器排行榜春潮快潘播放器在哪下载 春潮快潘播放器最新下载地址
热门文章 JS文件中的中文在网页
最新文章
JS文件中的中文在网页关于一些Play 1.0.1资
JAVA中抽象类与接口的区别Java技巧:关于Cookie的操作JAVA AWT图形用户界面设计巧用Java将Word转换为Html网页文件
人气排行 JS文件中的中文在网页上显示为乱码解决方法怎么为Java程序添加漂亮背景图片代码JAVA AWT图形用户界面设计怎样获取java线程中信息JS简介及特点Java面向对象编程学习总结js鼠标滑过切换层效果代码下载教你java使用回调和线程处理响应全过程
查看所有0条评论>>