removed output-disable in dbms-output fetching procedure
[mediawiki.git] / js2 / mwEmbed / libEmbedVideo / javaEmbed.js
blobe696b8ea95819e9a1e405a9a3f8f9a0c0ba51f30
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'
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 & mw.parseUri( document.URL ).host !=  mw.parseUri( mediaSrc ).host ) {
36                         if ( window.cortadoDomainLocations[mw.parseUri( mediaSrc ).host] ) {
37                                 applet_loc =  window.cortadoDomainLocations[mw.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 + 'libEmbedVideo/binPlayers/cortado/cortado-ovt-stripped-0.5.0.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.isPlaying() ) {
89                         if ( this.jce && this.jce.getPlayPosition ) {
90                                 try {
91                                    // java reads ogg media time.. so no need to add the start or seek offset:
92                                    // js_log(' ct: ' + this.jce.getPlayPosition() + ' ' +  this.supportsURLTimeEncoding());                                                                                                
93                                    this.currentTime = this.jce.getPlayPosition();
94                                    if ( this.jce.getPlayPosition() < 0 ) {
95                                                 js_log( 'pp:' + this.jce.getPlayPosition() );
96                                                 // probably reached clip end                                    
97                                                 this.onClipDone();
98                                    }
99                                 } catch ( e ) {
100                                    js_log( 'could not get time from jPlayer: ' + e );
101                                 }
102                         }
103                 }
104                 // once currentTime is updated call parent_monitor 
105                 this.parent_monitor();
106         },
107         /* 
108          * (local cortado seek does not seem to work very well)  
109          */
110         doSeek:function( perc ) {
111                 js_log( 'java:seek:p: ' + perc + ' : '  + this.supportsURLTimeEncoding() + ' dur: ' + this.getDuration() + ' sts:' + this.seek_time_sec );
112                 this.getJCE();
113                 
114                 if ( this.supportsURLTimeEncoding() ) {
115                         this.parent_doSeek( perc );
116                         // this.seek_time_sec = npt2seconds( this.start_ntp ) + parseFloat( perc * this.getDuration() );                                                
117                    // this.jce.setParam('url', this.getURI( this.seek_time_sec ))
118                         // this.jce.restart();
119                 } else if ( this.jce ) {
120                    // do a (genneraly broken) local seek:   
121                    js_log( "cortado javascript seems to always fail ... but here we go... doSeek(" + ( perc * parseFloat( this.getDuration() ) ) );
122                    this.jce.doSeek( perc * parseFloat( this.getDuration() )  );
123                 } else {
124                         this.doPlayThenSeek( perc );
125                 }
126         },
127         doPlayThenSeek:function( perc ) {
128                 js_log( 'doPlayThenSeek Hack' );
129                 var _this = this;
130                 this.play();
131                 var rfsCount = 0;
132                 var readyForSeek = function() {
133                         _this.getJCE();
134                         // if we have .jre ~in theory~ we can seek (but probably not) 
135                         if ( _this.jce ) {
136                                 _this.doSeek( perc );
137                         } else {
138                                 // try to get player for 10 seconds: 
139                                 if ( rfsCount < 200 ) {
140                                         setTimeout( readyForSeek, 50 );
141                                         rfsCount++;
142                                 } else {
143                                         js_log( 'error:doPlayThenSeek failed' );
144                                 }
145                         }
146                 }
147                 readyForSeek();
148         },
149         // get java cortado embed object
150         getJCE:function() {
151                 if ( embedTypes.mozilla ) {
152                         this.jce = window.frames['cframe_' + this.id ].document.getElementById( this.pid );
153                 } else {
154                         this.jce = $j( '#' + this.pid ).get( 0 );
155                 }
156         },
157         doThumbnailHTML:function() {
158                 // empty out player html (jquery with java applets does mix) :                  
159                 var pelm = document.getElementById( 'dc_' + this.id );
160                 if ( pelm ) {
161                         pelm.innerHTML = '';
162                 }
163                 this.parent_doThumbnailHTML();
164         },
165         play:function() {
166                 this.getJCE();
167                 this.parent_play();
168                 if ( this.jce )
169                         this.jce.doPlay();
170         },
171         pause:function() {
172                 this.getJCE();
173                 this.parent_pause();
174                 if ( this.jce )
175                         this.jce.doPause();
176         }