This repository has been archived by the owner on Nov 25, 2020. It is now read-only.
/
class.VideoPreviewer.js
248 lines (225 loc) · 10.9 KB
/
class.VideoPreviewer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
/*
* Copyright 2007-2013 Charles du Jeu - Abstrium SAS <team (at) pyd.io>
* This file is part of Pydio.
*
* Pydio is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Pydio is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Pydio. If not, see <http://www.gnu.org/licenses/>.
*
* The latest code can be found at <http://pyd.io/>.
*/
Class.create("VideoPreviewer", AbstractEditor, {
fullscreenMode: false,
initialize: function($super, oFormObject, options){
this.editorOptions = options;
this.element = oFormObject;
},
open : function($super, ajxpNode){
this.currentRichPreview = this.getPreview(ajxpNode, true);
if(this.element.id == "videojs_previewer"){
fitHeightToBottom(this.element);
this.element.insert(this.currentRichPreview);
}else{
this.element.down("#videojs_previewer").setStyle({height:'297px'});
this.element.down("#videojs_previewer").insert(this.currentRichPreview);
this.currentRichPreview.resizePreviewElement({width:380, height:260, maxHeight:260}, true);
if(this.element.down('.vjs-flash-fallback')){
fitHeightToBottom(this.element.down('.vjs-flash-fallback'));
}
if(this.element.down('object')){
this.element.down('object').setAttribute('height', this.element.getHeight());
}
}
modal.setCloseValidation(function(){
this.currentRichPreview.destroyElement();
return true;
}.bind(this));
this.element.fire("editor:updateTitle", ajxpNode.getLabel());
},
resize: function($super, size){
$super(size);
fitHeightToBottom(this.element);
try{
this.currentRichPreview.resizePreviewElement({
width:this.element.getWidth(),
height:this.element.getHeight(),
maxHeight:this.element.getHeight()
}, true);
}catch(e){}
if(this.element.down('.vjs-flash-fallback')){
fitHeightToBottom(this.element.down('.vjs-flash-fallback'));
}
if(this.element.down('object')){
this.element.down('object').setAttribute('height', this.element.getHeight());
}
},
destroy: function(){
this.currentRichPreview.destroyElement();
},
getSharedPreviewTemplate : function(node){
var mime = getAjxpMimeType(node);
var cType;
if(mime == "mp4" || mime == "m4v") cType = "video/mp4";
else if(mime == "ogv") cType = "video/ogg";
else if(mime == "webm") cType = "video/webm";
return new Template('<link href="http://vjs.zencdn.net/c/video-js.css" rel="stylesheet">\n\
<script src="http://vjs.zencdn.net/c/video.js"></script>\n\
<video id="my_video_1" class="video-js vjs-default-skin" controls\n\
preload="auto" width="#{WIDTH}" height="#{HEIGHT}" data-setup="{}">\n\
<source src="#{DL_CT_LINK}" type="'+cType+'">\n\
</video>');
},
getRESTPreviewLinks:function(node){
return {"Video Stream": "&file=" + encodeURIComponent(node.getPath())};
},
getPreview : function(ajxpNode, rich){
if(rich){
var url = document.location.href.split('#').shift().split('?').shift();
if(url[(url.length-1)] == '/'){
url = url.substr(0, url.length-1);
}else if(url.lastIndexOf('/') > -1){
url = url.substr(0, url.lastIndexOf('/'));
}
if($$('base').length){
url = $$("base")[0].getAttribute("href");
if(!url.startsWith('http') && !url.startsWith('https')){
url = document.location.origin + url;
}
}
url = LangUtils.trimRight(url, "\/");
var html5proxies = $H({});
var mime = ajxpNode.getAjxpMime();
if(mime == "mp4" || mime == "m4v" || mime == "webm" || mime == "ogv"){
html5proxies.set(mime, ajxpNode.getPath());
}
var meta = ajxpNode.getMetadata();
if(meta.get("video_altversion_mp4")){
html5proxies.set('mp4', meta.get("video_altversion_mp4"));
}
if(meta.get("video_altversion_webm")){
html5proxies.set('webm', meta.get("video_altversion_webm"));
}
if(meta.get("video_altversion_ogv")){
html5proxies.set('ogv', meta.get("video_altversion_ogv"));
}
//if(mime == "mp4" || mime == "webm" || mime == "ogv"){
var div, content;
if(html5proxies.keys().length){
// Problem : some embedded HTML5 readers do not send the cookies!
if(!window.crtAjxpSessid){
var connexion = new Connexion();
connexion.addParameter("get_action", "get_sess_id");
connexion.onComplete = function(transport){
window.crtAjxpSessid = transport.responseText.trim();
window.setTimeout(function(){window.crtAjxpSessid = null}, 1000 * 60 * 5);
};
connexion.sendSync();
}
var sessidPart = '&ajxp_sessid='+window.crtAjxpSessid;
var types = {
mp4:'video/mp4; codecs="avc1.42E01E, mp4a.40.2"',
m4v:'video/mp4; codecs="avc1.42E01E, mp4a.40.2"',
webm:'video/webm; codecs="vp8, vorbis"',
ogv:'video/ogg; codecs="theora, vorbis"'
};
var poster = resolveImageSource(ajxpNode.getIcon(),'/images/mimes/ICON_SIZE',64);
div = new Element("div", {className:"video-js-box"});
content = '';
content +=' <video class="video-js" controls preload="auto" height="200">';
var flashName;
html5proxies.each(function(pair){
var fname = url+'/'+ajxpBootstrap.parameters.get('ajxpServerAccess')+'&action=read_video_data'+sessidPart+'&file='+encodeURIComponent(pair.value);
if(!flashName){
flashName = encodeURIComponent(url+'/'+ajxpBootstrap.parameters.get('ajxpServerAccess')+'&action=read_video_data'+sessidPart+'&file='+pair.value);
}
content +=' <source src="'+fname+'" type=\''+types[pair.key]+'\' />';
});
content += '<object type="application/x-shockwave-flash" class="vjs-flash-fallback" data="plugins/editor.video/player_flv_maxi.swf" width="100%" height="200">';
content += ' <param name="movie" value="plugins/editor.video/player_flv_maxi.swf" />';
content += ' <param name="quality" value="high">';
content += ' <param name="allowFullScreen" value="true" />';
content += ' <param name="FlashVars" value="flv='+flashName+'&showstop=1&showvolume=1&showtime=1&showfullscreen=1&playercolor=676965&bgcolor1=f1f1ef&bgcolor2=f1f1ef&buttonovercolor=000000&sliderovercolor=000000" />';
content += '</object>';
content +=' </video>';
content += '<p align="center"> <img src="'+poster+'" width="64" height="64"></p>';
div.update(content);
div.resizePreviewElement = function(dimensionObject, innerInstance){
var videoObject = div.down('.video-js');
if(!div.ajxpPlayer && div.parentNode && videoObject){
$(div.parentNode).setStyle({paddingLeft:10,paddingRight:10});
div.ajxpPlayer = VideoJS.setup(videoObject, {
preload:true,
controlsBelow: false, // Display control bar below video instead of in front of
controlsHiding: true, // Hide controls when mouse is not over the video
defaultVolume: 0.85, // Will be overridden by user's last volume if available
flashVersion: 9, // Required flash version for fallback
linksHiding: true, // Hide download links when video is supported,
playerFallbackOrder : (mime == "mp4" || mime=="m4v"?["html5", "flash", "links"]:["html5", "links"])
});
}
var height = Math.min(dimensionObject.height, dimensionObject.maxHeight);
var width = dimensionObject.width;
var styleObject = {height: height + 'px', width : width + 'px'};
div.setStyle(styleObject);
div.down('.vjs-flash-fallback').setAttribute('width', width);
if(innerInstance) div.down('.vjs-flash-fallback').setAttribute('height', height);
if(videoObject) {
videoObject.setAttribute('width', width);
if(innerInstance) videoObject.setAttribute('height', height);
videoObject.setStyle(styleObject);
}
if(div.ajxpPlayer) {
div.ajxpPlayer.height(height);
div.ajxpPlayer.width(width);
}
};
div.destroyElement = function(){
if(div.ajxpPlayer){
div.ajxpPlayer.pause();
try{
$A(div.children).invoke("remove");
div.down("video").destroy();
}catch(e){}
div.update('');
}
};
}else{
var f = encodeURIComponent(url+'/'+ajxpBootstrap.parameters.get('ajxpServerAccess')+'&action=read_video_data&file='+ajxpNode.getPath());
div = new Element('div', {id:"video_container", style:"text-align:center; margin-bottom: 5px;"});
content = '<object type="application/x-shockwave-flash" data="plugins/editor.video/player_flv_maxi.swf" width="100%" height="200">';
content += ' <param name="movie" value="plugins/editor.video/player_flv_maxi.swf" />';
content += ' <param name="quality" value="high">';
content += ' <param name="wmode" value="opaque" />';
content += ' <param name="allowFullScreen" value="true" />';
content += ' <param name="FlashVars" value="flv='+f+'&showstop=1&showvolume=1&showtime=1&showfullscreen=1&playercolor=676965&bgcolor1=f1f1ef&bgcolor2=f1f1ef&buttonovercolor=000000&sliderovercolor=000000" />';
content += '</object>';
div.update(content);
div.resizePreviewElement = function(dimensionObject){
// do nothing;
var h =dimensionObject.height;
if(h > 400) div.down('object').setAttribute('height', 400);
else if(h > 300) div.down('object').setAttribute('height', 300);
else if(h > 200) div.down('object').setAttribute('height', 200);
};
div.destroyElement = function(){
div.update('');
};
}
return div;
}else{
return AbstractEditor.prototype.getPreview(ajxpNode);
}
},
getThumbnailSource : function(ajxpNode){
return resolveImageSource(ajxpNode.getIcon(),'/images/mimes/ICON_SIZE',64);
}
});