]> git.proxmox.com Git - extjs.git/blame - extjs/modern/modern/src/Video.js
add extjs 6.0.1 sources
[extjs.git] / extjs / modern / modern / src / Video.js
CommitLineData
6527f429
DM
1/**\r
2 * Provides a simple Container for HTML5 Video.\r
3 *\r
4 * ## Notes\r
5 *\r
6 * - There are quite a few issues with the `<video>` tag on Android devices. On Android 2+, the video will\r
7 * appear and play on first attempt, but any attempt afterwards will not work.\r
8 *\r
9 * ## Useful Properties\r
10 *\r
11 * - {@link #url}\r
12 * - {@link #autoPause}\r
13 * - {@link #autoResume}\r
14 *\r
15 * ## Useful Methods\r
16 *\r
17 * - {@link #method-pause}\r
18 * - {@link #method-play}\r
19 * - {@link #toggle}\r
20 *\r
21 * ## Example\r
22 *\r
23 * var panel = Ext.create('Ext.Panel', {\r
24 * fullscreen: true,\r
25 * items: [\r
26 * {\r
27 * xtype : 'video',\r
28 * x : 600,\r
29 * y : 300,\r
30 * width : 175,\r
31 * height : 98,\r
32 * url : "porsche911.mov",\r
33 * posterUrl: 'porsche.png'\r
34 * }\r
35 * ]\r
36 * });\r
37 */\r
38Ext.define('Ext.Video', {\r
39 extend: 'Ext.Media',\r
40 xtype: 'video',\r
41\r
42 config: {\r
43 /**\r
44 * @cfg {String/Array} url\r
45 * Location of the video to play. This should be in H.264 format and in a .mov file format.\r
46 * @accessor\r
47 */\r
48\r
49 /**\r
50 * @cfg {String} posterUrl\r
51 * Location of a poster image to be shown before showing the video.\r
52 * @accessor\r
53 */\r
54 posterUrl: null,\r
55\r
56 /**\r
57 * @cfg\r
58 * @inheritdoc\r
59 */\r
60 baseCls: Ext.baseCSSPrefix + 'video',\r
61\r
62 /**\r
63 * @cfg {Boolean} controls\r
64 * Determines if native controls should be shown for this video player.\r
65 */\r
66 controls: true\r
67 },\r
68\r
69 template: [{\r
70 /**\r
71 * @property {Ext.dom.Element} ghost\r
72 * @private\r
73 */\r
74 reference: 'ghost',\r
75 classList: [Ext.baseCSSPrefix + 'video-ghost']\r
76 }, {\r
77 tag: 'video',\r
78 reference: 'media',\r
79 classList: [Ext.baseCSSPrefix + 'media']\r
80 }],\r
81\r
82 initialize: function() {\r
83 var me = this;\r
84\r
85 me.callParent();\r
86\r
87 me.media.hide();\r
88\r
89 me.ghost.on({\r
90 tap: 'onGhostTap',\r
91 scope: me\r
92 });\r
93\r
94 me.media.on({\r
95 pause: 'onPause',\r
96 scope: me\r
97 });\r
98\r
99 if (Ext.os.is.Android4 || Ext.os.is.iPad) {\r
100 this.isInlineVideo = true;\r
101 }\r
102 },\r
103\r
104 applyUrl: function(url) {\r
105 return [].concat(url);\r
106 },\r
107\r
108 updateUrl: function(newUrl) {\r
109 var me = this,\r
110 media = me.media,\r
111 newLn = newUrl.length,\r
112 existingSources = media.query('source'),\r
113 oldLn = existingSources.length,\r
114 i;\r
115\r
116\r
117 for (i = 0; i < oldLn; i++) {\r
118 Ext.fly(existingSources[i]).destroy();\r
119 }\r
120\r
121 for (i = 0; i < newLn; i++) {\r
122 media.appendChild(Ext.Element.create({\r
123 tag: 'source',\r
124 src: newUrl[i]\r
125 }));\r
126 }\r
127\r
128 if (me.isPlaying()) {\r
129 me.play();\r
130 }\r
131 },\r
132\r
133 updateControls: function(value) {\r
134 this.media.set({controls:value ? true : undefined});\r
135 },\r
136\r
137 onActivate: function() {\r
138 this.media.setTop(0);\r
139 },\r
140\r
141 onDeactivate: function() {\r
142 this.pause();\r
143 this.media.setTop(-2000);\r
144 this.ghost.show();\r
145 },\r
146\r
147 /**\r
148 * @private\r
149 * Called when the {@link #ghost} element is tapped.\r
150 */\r
151 onGhostTap: function() {\r
152 var me = this,\r
153 media = this.media,\r
154 ghost = this.ghost;\r
155\r
156 media.show();\r
157 // Browsers which support native video tag display only, move the media down so\r
158 // we can control the Viewport\r
159 ghost.hide();\r
160 me.play();\r
161 },\r
162\r
163 /**\r
164 * @private\r
165 * native video tag display only, move the media down so we can control the Viewport\r
166 */\r
167 onPause: function() {\r
168 this.callParent(arguments);\r
169 if (!this.isInlineVideo) {\r
170 this.media.setTop(-2000);\r
171 this.ghost.show();\r
172 }\r
173 },\r
174\r
175 /**\r
176 * @private\r
177 * native video tag display only, move the media down so we can control the Viewport\r
178 */\r
179 onPlay: function() {\r
180 this.callParent(arguments);\r
181 this.media.setTop(0);\r
182 },\r
183\r
184 /**\r
185 * Updates the URL to the poster, even if it is rendered.\r
186 * @param {Object} newUrl\r
187 */\r
188 updatePosterUrl: function(newUrl) {\r
189 var ghost = this.ghost;\r
190 if (ghost) {\r
191 ghost.setStyle('background-image', 'url(' + newUrl + ')');\r
192 }\r
193 }\r
194});\r