provide installation instructions
[extjs.git] / air / src / VideoPanel.js
1 /*\r
2  * Ext JS Library 0.30\r
3  * Copyright(c) 2006-2009, Ext JS, LLC.\r
4  * licensing@extjs.com\r
5  * \r
6  * http://extjs.com/license\r
7  */\r
8 \r
9 /**
10  * @class Ext.air.VideoPanel
11  * @extends Ext.Panel
12  */
13 Ext.air.VideoPanel = Ext.extend(Ext.Panel, {
14     // Properties
15     autoResize: true,
16
17     // Overriden methods
18     initComponent: function() {
19         var connection = new air.NetConnection();
20         connection.connect(null);
21
22         this.stream = new runtime.flash.net.NetStream(connection);
23         this.stream.client = {
24             onMetaData: Ext.emptyFn
25         };
26         
27         Ext.air.VideoPanel.superclass.initComponent.call(this);
28         this.on('bodyresize', this.onVideoResize, this);
29     },
30     
31     afterRender: function() {
32         Ext.air.VideoPanel.superclass.afterRender.call(this);
33         (function() {
34             var box = this.body.getBox();
35             this.video = new air.Video(this.getInnerWidth(), this.getInnerHeight());
36             if (this.url) {
37                 this.video.attachNetStream(this.stream);
38                 this.stream.play(this.url);
39             }
40             nativeWindow.stage.addChild(this.video);
41             this.video.x = box.x;
42             this.video.y = box.y;
43         }).defer(500, this);
44     },
45     
46     // Custom Methods
47     onVideoResize: function(pnl, w, h) {
48         if (this.video && this.autoResize) {
49             var iw = this.getInnerWidth();
50             var ih = this.getInnerHeight();
51             this.video.width = iw
52             this.video.height = ih;
53             var xy = this.body.getXY();
54             if (xy[0] !== this.video.x) {
55                     this.video.x = xy[0];
56             }
57             if (xy[1] !== this.video.y) {
58                     this.video.y = xy[1];
59             }
60         }
61     },
62     
63     loadVideo: function(url) {
64         this.stream.close();
65         this.video.attachNetStream(this.stream);
66         this.stream.play(url);          
67     }
68     
69 });
70 Ext.reg('videopanel', Ext.air.VideoPanel);
71