removed output-disable in dbms-output fetching procedure
[mediawiki.git] / js2 / mwEmbed / libEmbedVideo / vlcEmbed.js
blob6c1fd2499d0e1802eb5285f6c6888d4d935e4a1a
1 /*
2 * vlc embed based on: http://people.videolan.org/~damienf/plugin-0.8.6.html
3 * javascript api: http://www.videolan.org/doc/play-howto/en/ch04.html
4 *  assume version > 0.8.5.1
5 */
6 var vlcEmbed = {
7         instanceOf : 'vlcEmbed',
8         supports : { 
9                 'play_head':true,
10                 'pause':true,
11                 'stop':true,
12                 'fullscreen':true,
13                 'time_display':true,
14                 'volume_control':true,
15                 
16                 'playlist_driver':true, // if the object supports playlist functions
17                 'overlay':false
18         },
19         // init vars: 
20         monitorTimerId : 0,
21         prevState : 0,
22         pejs_count:0, // post embed js count
24         getEmbedHTML: function() {
25                 // give VLC 150ms to initialize before we start playback 
26                 // @@todo should be able to do this as an ready event
27                 this.pejs_count = 0;
28                 setTimeout( 'document.getElementById(\'' + this.id + '\').postEmbedJS()', 150 );
29                    return this.getEmbedObj();
30         },
31         getEmbedObj:function() {
32                 var embed_code = '<object classid="clsid:9BE31822-FDAD-461B-AD51-BE1D1C159921" ' +
33                         'codebase="http://downloads.videolan.org/pub/videolan/vlc/latest/win32/axvlc.cab#Version=0,8,6,0" ' +
34                         'id="' + this.pid + '" events="True" height="' + this.height + '" width="' + this.width + '"' +
35                         '>' +
36                                 '<param name="MRL" value="">' +
37                                 '<param name="ShowDisplay" value="True">' +
38                                 '<param name="AutoLoop" value="False">' +
39                                 '<param name="AutoPlay" value="False">' +
40                                 '<param name="Volume" value="50">' +
41                                 '<param name="StartTime" value="0">' +
42                                 '<embed pluginspage="http://www.videolan.org" type="application/x-vlc-plugin" ' +
43                                         'progid="VideoLAN.VLCPlugin.2" name="' + this.pid + '" ' +
44                                         'height="' + this.height + '" width="' + this.width + '" ' +
45                                         // set the style too 'just to be sure'
46                                         'style="width:' + this.width + 'px;height:' + this.height + 'px;" ' +
47                                 '>' +
48                         '</object>';
49                 js_log( 'embed with: ' + embed_code );
50                 return embed_code;
51         },
52         
53         /*
54         * some java script to start vlc playback after the embed:
55         */
56         postEmbedJS: function() {
57                 // load a pointer to the vlc into the object (this.vlc)
58                 this.getVLC();
59                 if ( this.vlc.log ) {
60                         // manipulate the dom object to make sure vlc has the correct size: 
61                         this.vlc.style.width = this.width;
62                         this.vlc.style.height = this.height;
63                         this.vlc.playlist.items.clear();
64                         var src = mw.absoluteUrl( this.getSrc() ) ;
65                         // @@todo if client supports seeking no need to send seek_offset to URI
66                         js_log( 'vlc play::' + src );
67                         var itemId = this.vlc.playlist.add( src );
68                         if ( itemId != -1 ) {
69                                 // play
70                                 this.vlc.playlist.playItem( itemId );
71                         } else {
72                                 js_log( "error:cannot play at the moment !" );
73                         }
74                         // if controls enabled start up javascript interface and monitor:
75                         if ( this.controls ) {
76                                 // activate the slider: scriptaculus based)
77                                 // this.activateSlider();  
78                                 // start doing status updates every 1/10th of a second                                                     
79                         }
80                         setTimeout( '$j(\'#' + this.id + '\').get(0).monitor()', 100 );
81                 } else {
82                         js_log( 'postEmbedJS:vlc not ready' );
83                         this.pejs_count++;
84                         if ( this.pejs_count < 10 ) {
85                                 setTimeout( 'document.getElementById(\'' + this.id + '\').postEmbedJS()', 100 );
86                         } else {
87                                 js_log( 'vlc never ready' );
88                         }
89                 }
90         },
91         // disable local seeking (while we don't know what we have avaliable)
92         doSeek : function( perc ) {
93                 this.getVLC();
94                 if ( this.supportsURLTimeEncoding() ) {
95                         this.parent_doSeek( perc );
96                 } else if ( this.vlc ) {
97                         this.seeking = true;
98                         js_log( "do vlc http seek to: " + perc )
99                         if ( ( this.vlc.input.state == 3 ) && ( this.vlc.input.position != perc ) )
100                         {
101                                 this.vlc.input.position = perc;
102                                 this.setStatus( 'seeking...' );
103                         }
104                 } else {
105                         this.doPlayThenSeek( perc );
106                 }
107                 this.parent_monitor();
108         },
109         doPlayThenSeek:function( perc ) {
110                 js_log( 'doPlayThenSeekHack' );
111                 var _this = this;
112                 this.play();
113                 var rfsCount = 0;
114                 var readyForSeek = function() {
115                         _this.getVLC();
116                         var newState = _this.vlc.input.state;
117                         // if playing we are ready to do the 
118                         if ( newState == 3 ) {
119                                 _this.doSeek( perc );
120                         } else {
121                                 // try to get player for 10 seconds: 
122                                 if ( rfsCount < 200 ) {
123                                         setTimeout( readyForSeek, 50 );
124                                         rfsCount++;
125                                 } else {
126                                         js_log( 'error:doPlayThenSeek failed' );
127                                 }
128                         }
129                 }
130                 readyForSeek();
131         },
132         playMovieAt: function ( order ) {
133                 // @@todo add clips to playlist after (order) and then play
134                 this.play();
135         },
136         /* 
137         * updates the status time
138         */
139         monitor: function() {
140                 this.getVLC();
141                 if ( !this.vlc )
142                         return ;
143                 if ( this.vlc.log ) {
144                         // js_log( 'state:' + this.vlc.input.state);
145                         // js_log('time: ' + this.vlc.input.time);
146                         // js_log('pos: ' + this.vlc.input.position);
147                         if ( this.vlc.log.messages.count > 0 ) {
148                                 // there is one or more messages in the log
149                                 var iter = this.vlc.log.messages.iterator();
150                                 while ( iter.hasNext ) {
151                                         var msg = iter.next();
152                                    var msgtype = msg.type.toString();
153                                    if ( ( msg.severity == 1 ) && ( msgtype == "input" ) )
154                                    {
155                                                    js_log( msg.message );
156                                    }
157                                 }
158                                 // clear the log once finished to avoid clogging
159                                 this.vlc.log.messages.clear();
160                         }
161                         var newState = this.vlc.input.state;
162                         if ( this.prevState != newState ) {
163                                    if ( newState == 0 )
164                                 {
165                                         // current media has stopped 
166                                         this.onStop();
167                                 }
168                                 else if ( newState == 1 )
169                                 {
170                                         // current media is opening/connecting
171                                         this.onOpen();
172                                 }
173                                 else if ( newState == 2 )
174                                 {
175                                         // current media is buffering data
176                                         this.onBuffer();
177                                 }
178                                 else if ( newState == 3 )
179                                 {
180                                    // current media is now playing
181                                    this.onPlay();
182                                 }
183                                    else if ( this.vlc.input.state == 4 )
184                                 {
185                                         // current media is now paused
186                                         this.onPause();
187                                 }
188                                 this.prevState = newState;
189                         } else if ( newState == 3 ) {
190                                 // current media is playing
191                                 this.onPlaying();
192                         }
193                 }
194                 // update the status and check timmer via universal parent monitor
195                 this.parent_monitor();
196         },
197         /* events */
198         onOpen: function() {
199                 this.setStatus( "Opening..." );
200         },
201         onBuffer: function() {
202                 this.setStatus( "Buffering..." );
203         },
204         onPlay: function() {
205                 this.onPlaying();
206         },
207         liveFeedRoll: 0,
208         onPlaying: function() {
209                 this.seeking = false;
210                 // for now trust the duration from url over vlc input.length
211                 if ( !this.getDuration() && this.vlc.input.length > 0 )
212                 {
213                         // js_log('setting duration to ' + this.vlc.input.length /1000);                        
214                         this.duration = this.vlc.input.length / 1000;
215                 }
216                 this.currentTime = this.vlc.input.time / 1000;
217         },
218         onPause: function() {
219                 this.parent_pause(); // update the inteface if paused via native control
220         },
221         onStop: function() {
222                 js_log( 'vlc:onStop:' );
223                 if ( !this.seeking )
224                         this.onClipDone();
225         },
226         /* js hooks/controls */
227         play : function() {
228                 js_log( 'f:vlcPlay' );
229                         this.getVLC();
230                         // call the parent
231                 this.parent_play();
232                 if ( this.vlc ) {
233                         // plugin is already being present send play call: 
234                         // clear the message log and enable error logging
235                         if ( this.vlc.log ) {
236                                 this.vlc.log.messages.clear();
237                         }
238                         if ( this.vlc.playlist )
239                                 this.vlc.playlist.play();
240                                 
241                         this.monitor();
242                         this.paused = false;
243                 }
244         },
245         stop : function() {
246                 if ( this.vlc ) {
247                         if ( typeof this.vlc != 'undefined' ) {
248                                 if ( typeof this.vlc.playlist != 'undefined' ) {
249                                         // dont' stop (issues all the plugin-stop actions) 
250                                         // this.vlc.playlist.stop();
251                                         if ( this.monitorTimerId != 0 )
252                                         {
253                                                 clearInterval( this.monitorTimerId );
254                                                 this.monitorTimerId = 0;
255                                         }
256                                 }
257                         }
258                 }
259                 // this.onStop();
260                 // do parent stop
261                 this.parent_stop();
262         },
263         pause : function() {
264                 this.parent_pause(); // update the interface if paused via native control
265                 if ( this.vlc ) {
266                         this.vlc.playlist.togglePause();
267                 }
268         },
269         toggleMute:function() {
270                 this.parent_toggleMute();
271                 this.getVLC();
272                 if ( this.vlc )
273                         this.vlc.audio.toggleMute();
274         },
275         // @@ Support UpDateVolumen 
276         updateVolumen:function( perc ) {
277                 this.getVLC();
278                 if ( this.vlc )
279                         this.vlc.audio.volume = perc * 100;
280         },
281         // @@ Get Volumen 
282         getVolumen:function() {
283                 this.getVLC();
284                 if ( this.vlc )
285                 return this.vlc.audio.volume / 100;
286         },
287         fullscreen : function() {
288                 if ( this.vlc ) {
289                         if ( this.vlc.video )
290                                 this.vlc.video.toggleFullscreen();
291                 }
292         },      
293         // get the embed vlc object 
294         getVLC : function() {
295                 this.vlc = this.getPluginEmbed();
296         }