Bug 20489 Configure illegal file characters https://bugzilla.wikimedia.org/show_bug...
[mediawiki.git] / js2 / mwEmbed / libEmbedVideo / javaEmbed.js
blob114577f73940094f9c2df2774ce53ebd1ac0e0db
1 window.cortadoDomainLocations = {
2         'upload.wikimedia.org'  : 'http://upload.wikimedia.org/jars/cortado.jar',
3         'tinyvid.tv'                    : 'http://tinyvid.tv/static/cortado.jar',
4         'media.tinyvid.tv'              : 'http://media.tinyvid.tv/cortado.jar'
5
7 var javaEmbed = {
8         instanceOf:'javaEmbed',
9         iframe_src:'',
10         logged_domain_error:false,
11         supports: {
12                 'play_head':true, 
13                 'pause':true, 
14                 'stop':true, 
15                 'fullscreen':false, 
16                 'time_display':true, 
17                 'volume_control':false
18         },
19         getEmbedHTML : function (){
20                 //big delay on embed html cuz its just for status updates and ie6 is crazy. 
21                 if(this.controls)
22                         setTimeout('document.getElementById(\''+this.id+'\').postEmbedJS()', 500);
23                 //set a default duration of 30 seconds: cortao should detect duration.
24                 return this.wrapEmebedContainer( this.getEmbedObj() );
25         },
26         getEmbedObj:function(){ 
27                 js_log("java play url:" + this.getURI( this.seek_time_sec ));
28                 //get the duration
29                 this.getDuration();
30                 //if still unset set to an arbitrary time 60 seconds: 
31                 if(!this.duration)this.duration=60;
32                 //@@todo we should have src property in our base embed object
33                 var mediaSrc = this.getSrc();
34                 
35                 if(mediaSrc.indexOf('://')!=-1 & parseUri(document.URL).host !=  parseUri(mediaSrc).host){
36                         if(window.cortadoDomainLocations[parseUri(mediaSrc).host]){
37                                 applet_loc =  window.cortadoDomainLocations[parseUri(mediaSrc).host];
38                         }else{
39                                 applet_loc  = 'http://theora.org/cortado.jar';
40                         }
41                 }else{
42                         //should be identical to cortado.jar
43                         applet_loc = mv_embed_path+'binPlayers/cortado/cortado.jar';
44                 }
45                         //load directly in the page..
46                         // (media must be on the same server or applet must be signed)
47                         var appplet_code = ''+
48                         '<applet id="' + this.pid + '" code="com.fluendo.player.Cortado.class" archive="' + applet_loc + '" width="' + this.width + '" height="' + this.height + '">    '+ "\n"+
49                                 '<param name="url" value="' + mediaSrc + '" /> ' + "\n"+
50                                 '<param name="local" value="false"/>'+ "\n"+
51                                 '<param name="keepaspect" value="true" />'+ "\n"+
52                                 '<param name="video" value="true" />'+"\n"+
53                                 '<param name="showStatus" value="hide" />' + "\n"+
54                                 '<param name="audio" value="true" />'+"\n"+
55                                 '<param name="seekable" value="true" />'+"\n"+
56                                 '<param name="duration" value="' + this.duration + '" />'+"\n"+
57                                 '<param name="bufferSize" value="4096" />'+"\n"+
58                         '</applet>';                                                            
59                                                                         
60                         // Wrap it in an iframe to avoid hanging the event thread in FF 2/3 and similar
61                         // Doesn't work in MSIE or Safari/Mac or Opera 9.5
62                         if ( embedTypes.mozilla ) {
63                                 var iframe = document.createElement( 'iframe' );
64                                 iframe.setAttribute( 'width', params.width );
65                                 iframe.setAttribute( 'height', playerHeight );
66                                 iframe.setAttribute( 'scrolling', 'no' );
67                                 iframe.setAttribute( 'frameborder', 0 );
68                                 iframe.setAttribute( 'marginWidth', 0 );
69                                 iframe.setAttribute( 'marginHeight', 0 );
70                                 iframe.setAttribute( 'id', 'cframe_' + this.id)
71                                 elt.appendChild( iframe );
72                                 var newDoc = iframe.contentDocument;
73                                 newDoc.open();
74                                 newDoc.write( '<html><body>' + appplet_code + '</body></html>' );
75                                 newDoc.close(); // spurious error in some versions of FF, no workaround known
76                         } else {
77                                 return appplet_code;
78                         }
79         }, 
80         postEmbedJS:function(){
81                 //reset logged domain error flag:
82                 this.logged_domain_error = false;
83                 //start monitor: 
84                 this.monitor();
85         },
86         monitor:function(){
87                 this.getJCE()   
88                 if(this.jce && this.jce.getPlayPosition){                 
89                         try{                                     
90                            //java reads ogg media time.. so no need to add the start or seek offset:
91                            //js_log(' ct: ' + this.jce.getPlayPosition() + ' ' +  this.supportsURLTimeEncoding());                                                                                                 
92                            this.currentTime = this.jce.getPlayPosition();       
93                            if( this.jce.getPlayPosition() < 0){
94                                         js_log('pp:'+this.jce.getPlayPosition());                                
95                                         //probably reached clip end 
96                                         this.onClipDone();
97                            }                                              
98                         }catch (e){
99                            js_log('could not get time from jPlayer: ' + e);
100                         }                                                       
101                 }  
102                 //once currentTime is updated call parent_monitor 
103                 this.parent_monitor();
104         },   
105    /* 
106         * (local cortado seek does not seem to work very well)  
107         */
108         doSeek:function(perc){           
109                 js_log('java:seek:p: ' + perc+ ' : '  + this.supportsURLTimeEncoding() + ' dur: ' + this.getDuration() + ' sts:' + this.seek_time_sec );                
110                 this.getJCE();
111                 
112                 if( this.supportsURLTimeEncoding() ){            
113                         this.parent_doSeek(perc);   
114                         //this.seek_time_sec = npt2seconds( this.start_ntp ) + parseFloat( perc * this.getDuration() );                                         
115                    // this.jce.setParam('url', this.getURI( this.seek_time_sec ))
116                         //this.jce.restart();
117                 }else if(this.jce){                                      
118                    //do a (genneraly broken) local seek:   
119                    js_log("cortado javascript seems to always fail ... but here we go... doSeek(" + (perc * parseFloat(this.getDuration()) ) );  
120                    this.jce.doSeek( perc * parseFloat(this.getDuration())  );                           
121                 }else{
122                         this.doPlayThenSeek(perc);
123                 }               
124         },
125         doPlayThenSeek:function(perc){
126                 js_log('doPlayThenSeek Hack');
127                 var _this = this;
128                 this.play();
129                 var rfsCount = 0;
130                 var readyForSeek = function(){
131                         _this.getJCE(); 
132                         //if we have .jre ~in theory~ we can seek (but probably not) 
133                         if(_this.jce){
134                                 _this.doSeek(perc);
135                         }else{                  
136                                 //try to get player for 10 seconds: 
137                                 if( rfsCount < 200 ){
138                                         setTimeout(readyForSeek, 50);
139                                         rfsCount++;
140                                 }else{
141                                         js_log('error:doPlayThenSeek failed');
142                                 }
143                         }
144                 }
145                 readyForSeek();
146         },
147         //get java cortado embed object
148         getJCE:function(){              
149                 if ( embedTypes.mozilla ) {
150                         this.jce = window.frames['cframe_' + this.id ].document.getElementById( this.pid );
151                 }else{
152                         this.jce = $j('#'+this.pid).get( 0 );
153                 }
154                 /*if( ! mv_java_iframe ){
155                         
156                 }else{
157                         if( $j('#iframe_' + this.pid ).length > 0 )
158                                 try{
159                                         this.jce = $j('#iframe_' + this.pid ).get(0).contentWindow.jPlayer;
160                                 }catch (e){
161                                         if(!this.logged_domain_error)
162                                                 js_log("failed to grab jce we wont have time updates for java");
163                                         this.logged_domain_error = true;
164                                 }
165                         else
166                                 return false;
167                 }   */           
168         },
169         doThumbnailHTML:function(){             
170                 //empty out player html (jquery with java applets does mix) :                   
171                 var pelm = document.getElementById('dc_' + this.id );
172                 pelm.innerHTML = '';            
173                 this.parent_doThumbnailHTML();
174         },
175         play:function(){
176                 this.getJCE();
177                 this.parent_play();
178                 if( this.jce )
179                         this.jce.doPlay();
180         },
181         pause:function(){
182                 this.getJCE();
183                 this.parent_pause();
184                 if( this.jce )
185                         this.jce.doPause();              
186         }