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
8 supports: {'play_head':true,
13 'volume_control':true,
15 'playlist_driver':true, //if the object supports playlist functions
21 pejs_count:0, //post embed js count
23 getEmbedHTML: function(){
24 //give VLC 150ms to initialize before we start playback
25 //@@todo should be able to do this as an ready event
27 setTimeout('document.getElementById(\''+this.id+'\').postEmbedJS()', 150);
28 return this.getEmbedObj();
30 getEmbedObj:function(){
31 var embed_code = '<object classid="clsid:9BE31822-FDAD-461B-AD51-BE1D1C159921" '+
32 'codebase="http://downloads.videolan.org/pub/videolan/vlc/latest/win32/axvlc.cab#Version=0,8,6,0" '+
33 'id="' + this.pid + '" events="True" height="'+this.height+'" width="'+this.width+'"' +
35 '<param name="MRL" value="">'+
36 '<param name="ShowDisplay" value="True">'+
37 '<param name="AutoLoop" value="False">'+
38 '<param name="AutoPlay" value="False">'+
39 '<param name="Volume" value="50">'+
40 '<param name="StartTime" value="0">'+
41 '<embed pluginspage="http://www.videolan.org" type="application/x-vlc-plugin" '+
42 'progid="VideoLAN.VLCPlugin.2" name="' + this.pid + '" '+
43 'height="'+this.height+'" width="'+this.width+'" ' +
44 //set the style too 'just to be sure'
45 'style="width:'+this.width+'px;height:'+this.height+'px;" '+
48 js_log('embed with: ' + embed_code);
53 * some java script to start vlc playback after the embed:
55 postEmbedJS: function(){
56 //load a pointer to the vlc into the object (this.vlc)
59 //manipulate the dom object to make sure vlc has the correct size:
60 this.vlc.style.width=this.width;
61 this.vlc.style.height=this.height;
62 this.vlc.playlist.items.clear();
63 //@@todo if client supports seeking no need to send seek_offset to URI
64 js_log('vlc play::' + this.getSrc() );
65 var itemId = this.vlc.playlist.add( this.getSrc() );
68 this.vlc.playlist.playItem(itemId);
70 js_log("error:cannot play at the moment !");
72 //if controls enabled start up javascript interface and monitor:
74 //activate the slider: scriptaculus based)
75 //this.activateSlider();
76 //start doing status updates every 1/10th of a second
78 setTimeout('$j(\'#'+this.id+'\').get(0).monitor()',100);
80 js_log('postEmbedJS:vlc not ready');
82 if( this.pejs_count < 10 ){
83 setTimeout('document.getElementById(\''+this.id+'\').postEmbedJS()',100);
85 js_log('vlc never ready');
89 //disable local seeking (while we don't know what we have avaliable)
90 doSeek : function(perc){
91 if( this.supportsURLTimeEncoding() ){
92 this.parent_doSeek(perc);
93 }else if( this.vlc ) {
95 js_log("do vlc http seek to: " + perc)
96 if( (this.vlc.input.state == 3) && (this.vlc.input.position != perc) )
98 this.vlc.input.position = perc;
99 this.setStatus( 'seeking...' );
102 this.doPlayThenSeek(perc);
104 this.parent_monitor();
106 doPlayThenSeek:function(perc){
107 js_log('doPlayThenSeekHack');
111 var readyForSeek = function(){
113 var newState = _this.vlc.input.state;
114 //if playing we are ready to do the
118 //try to get player for 10 seconds:
119 if( rfsCount < 200 ){
120 setTimeout(readyForSeek, 50);
123 js_log('error:doPlayThenSeek failed');
129 playMovieAt: function (order){
130 //@@todo add clips to playlist after (order) and then play
134 * updates the status time
141 //js_log( 'state:' + this.vlc.input.state);
142 //js_log('time: ' + this.vlc.input.time);
143 //js_log('pos: ' + this.vlc.input.position);
144 if( this.vlc.log.messages.count > 0 ){
145 // there is one or more messages in the log
146 var iter = this.vlc.log.messages.iterator();
147 while( iter.hasNext ){
148 var msg = iter.next();
149 var msgtype = msg.type.toString();
150 if( (msg.severity == 1) && (msgtype == "input") )
152 js_log( msg.message );
155 // clear the log once finished to avoid clogging
156 this.vlc.log.messages.clear();
158 var newState = this.vlc.input.state;
159 if( this.prevState != newState ){
162 // current media has stopped
165 else if( newState == 1 )
167 // current media is opening/connecting
170 else if( newState == 2 )
172 // current media is buffering data
175 else if( newState == 3 )
177 // current media is now playing
180 else if( this.vlc.input.state == 4 )
182 // current media is now paused
185 this.prevState = newState;
186 }else if( newState == 3 ){
187 // current media is playing
191 //update the status and check timmer via universal parent monitor
192 this.parent_monitor();
196 this.setStatus("Opening...");
197 //document.getElementById("info_"+this.id).innerHTML = "Opening...";
198 //document.getElementById("PlayOrPause").disabled = true;
199 //document.getElementById("Stop").disabled = false;
201 onBuffer: function(){
202 this.setStatus("Buffering...");
203 //document.getElementById("info_"+this.id).innerHTML = "Buffering...";
204 //document.getElementById("PlayOrPause").disabled = true;
205 //document.getElementById("Stop").disabled = false;
208 //document.getElementById("PlayOrPause").value = "Pause";
209 //document.getElementById("PlayOrPause").disabled = false;
210 //document.getElementById("Stop").disabled = false;
214 onPlaying: function(){
216 //for now trust the duration from url over vlc input.length
217 if( !this.getDuration() && this.vlc.input.length > 0 )
219 //js_log('setting duration to ' + this.vlc.input.length /1000);
220 this.duration = this.vlc.input.length /1000;
222 this.currentTime = this.vlc.input.time/1000;
225 this.parent_pause(); //update the inteface if paused via native control
228 js_log('vlc:onStop:');
232 /* js hooks/controls */
239 //plugin is already being present send play call:
240 // clear the message log and enable error logging
242 this.vlc.log.messages.clear();
244 if(this.vlc.playlist)
245 this.vlc.playlist.play();
253 if(typeof this.vlc != 'undefined' ){
254 if(typeof this.vlc.playlist != 'undefined'){
255 //dont' stop (issues all the plugin-stop actions)
256 //this.vlc.playlist.stop();
257 if( this.monitorTimerId != 0 )
259 clearInterval(this.monitorTimerId);
260 this.monitorTimerId = 0;
270 this.parent_pause(); //update the inteface if paused via native control
272 this.vlc.playlist.togglePause();
275 toggleMute:function(){
276 this.parent_toggleMute();
279 this.vlc.audio.toggleMute();
281 //@@ Suport UpDateVolumen
282 updateVolumen:function(perc){
285 this.vlc.audio.volume = perc*100;
288 getVolumen:function(){
291 return this.vlc.audio.volume / 100;
293 fullscreen : function(){
296 this.vlc.video.toggleFullscreen();
299 /* returns current time in float seconds
300 * as per html5 we should just have an attribute by name of CurrentTime
301 * http://www.whatwg.org/specs/web-apps/current-work/#currenttime
302 currentTime : function(){
303 if(typeof this.vlc != 'undefined' ){
304 if(typeof this.vlc.input != 'undefined' ){
305 return this.vlc.input.time/1000;
311 // get the embed vlc object
313 this.vlc = this.getPluginEmbed();