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
7 instanceOf : 'vlcEmbed',
14 'volume_control':true,
16 'playlist_driver':true, // if the object supports playlist functions
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
28 setTimeout( 'document.getElementById(\'' + this.id + '\').postEmbedJS()', 150 );
29 return this.getEmbedObj();
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 + '"' +
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;" ' +
49 js_log( 'embed with: ' + embed_code );
54 * some java script to start vlc playback after the embed:
56 postEmbedJS: function() {
57 // load a pointer to the vlc into the object (this.vlc)
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 );
70 this.vlc.playlist.playItem( itemId );
72 js_log( "error:cannot play at the moment !" );
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
80 setTimeout( '$j(\'#' + this.id + '\').get(0).monitor()', 100 );
82 js_log( 'postEmbedJS:vlc not ready' );
84 if ( this.pejs_count < 10 ) {
85 setTimeout( 'document.getElementById(\'' + this.id + '\').postEmbedJS()', 100 );
87 js_log( 'vlc never ready' );
91 // disable local seeking (while we don't know what we have avaliable)
92 doSeek : function( perc ) {
94 if ( this.supportsURLTimeEncoding() ) {
95 this.parent_doSeek( perc );
96 } else if ( this.vlc ) {
98 js_log( "do vlc http seek to: " + perc )
99 if ( ( this.vlc.input.state == 3 ) && ( this.vlc.input.position != perc ) )
101 this.vlc.input.position = perc;
102 this.setStatus( 'seeking...' );
105 this.doPlayThenSeek( perc );
107 this.parent_monitor();
109 doPlayThenSeek:function( perc ) {
110 js_log( 'doPlayThenSeekHack' );
114 var readyForSeek = function() {
116 var newState = _this.vlc.input.state;
117 // if playing we are ready to do the
118 if ( newState == 3 ) {
119 _this.doSeek( perc );
121 // try to get player for 10 seconds:
122 if ( rfsCount < 200 ) {
123 setTimeout( readyForSeek, 50 );
126 js_log( 'error:doPlayThenSeek failed' );
132 playMovieAt: function ( order ) {
133 // @@todo add clips to playlist after (order) and then play
137 * updates the status time
139 monitor: function() {
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" ) )
155 js_log( msg.message );
158 // clear the log once finished to avoid clogging
159 this.vlc.log.messages.clear();
161 var newState = this.vlc.input.state;
162 if ( this.prevState != newState ) {
165 // current media has stopped
168 else if ( newState == 1 )
170 // current media is opening/connecting
173 else if ( newState == 2 )
175 // current media is buffering data
178 else if ( newState == 3 )
180 // current media is now playing
183 else if ( this.vlc.input.state == 4 )
185 // current media is now paused
188 this.prevState = newState;
189 } else if ( newState == 3 ) {
190 // current media is playing
194 // update the status and check timmer via universal parent monitor
195 this.parent_monitor();
199 this.setStatus( "Opening..." );
201 onBuffer: function() {
202 this.setStatus( "Buffering..." );
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 )
213 // js_log('setting duration to ' + this.vlc.input.length /1000);
214 this.duration = this.vlc.input.length / 1000;
216 this.currentTime = this.vlc.input.time / 1000;
218 onPause: function() {
219 this.parent_pause(); // update the inteface if paused via native control
222 js_log( 'vlc:onStop:' );
226 /* js hooks/controls */
228 js_log( 'f:vlcPlay' );
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();
238 if ( this.vlc.playlist )
239 this.vlc.playlist.play();
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 )
253 clearInterval( this.monitorTimerId );
254 this.monitorTimerId = 0;
264 this.parent_pause(); // update the interface if paused via native control
266 this.vlc.playlist.togglePause();
269 toggleMute:function() {
270 this.parent_toggleMute();
273 this.vlc.audio.toggleMute();
275 // @@ Support UpDateVolumen
276 updateVolumen:function( perc ) {
279 this.vlc.audio.volume = perc * 100;
282 getVolumen:function() {
285 return this.vlc.audio.volume / 100;
287 fullscreen : function() {
289 if ( this.vlc.video )
290 this.vlc.video.toggleFullscreen();
293 // get the embed vlc object
294 getVLC : function() {
295 this.vlc = this.getPluginEmbed();