1 //native embed library:
3 instanceOf:'nativeEmbed',
13 'volume_control':true,
16 'playlist_swap_loader':true //if the object supports playlist functions
18 getEmbedHTML : function (){
19 var embed_code = this.getEmbedObj();
20 js_log("embed code: " + embed_code)
21 setTimeout('$j(\'#' + this.id + '\').get(0).postEmbedJS()', 150);
22 return this.wrapEmebedContainer( embed_code);
24 getEmbedObj:function(){
25 //we want to let mv_embed handle the controls so notice the absence of control attribute
26 // controls=false results in controls being displayed:
27 //http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2008-August/016159.html
28 js_log("native play url:" + this.getSrc() + ' start_offset: '+ this.start_ntp + ' end: ' + this.end_ntp);
30 'id="' + this.pid + '" ' +
31 'style="width:' + this.width+'px;height:' + this.height + 'px;" ' +
32 'width="' + this.width + '" height="'+this.height+'" '+
33 'src="' + this.getSrc() + '" ';
35 /*if(!this.onlyLoadFlag)
36 eb+='autoplay="true" ';*/
38 //continue with the other attr:
39 eb+= 'oncanplaythrough="$j(\'#'+this.id+'\').get(0).oncanplaythrough();return false;" ' +
40 'onloadedmetadata="$j(\'#'+this.id+'\').get(0).onloadedmetadata();return false;" ' +
41 'loadedmetadata="$j(\'#'+this.id+'\').get(0).onloadedmetadata();return false;" ' +
42 'onprogress="$j(\'#'+this.id+'\').get(0).onprogress( event );return false;" '+
43 'onended="$j(\'#'+this.id+'\').get(0).onended();return false;" >' +
47 //@@todo : loading progress
48 postEmbedJS:function(){
50 js_log("f:native:postEmbedJS:");
52 var doActualPlay= function(){
53 js_log("doActualPlay ");
56 if(typeof this.vid != 'undefined'){
57 //always load the media:
58 if( this.onlyLoadFlag ){
62 setTimeout(doActualPlay, 500);
64 setTimeout('$j(\'#'+this.id+'\').get(0).monitor()',100);
66 js_log('could not grab vid obj trying again:' + typeof this.vid);
67 this.grab_try_count++;
68 if( this.grab_count == 10 ){
69 js_log(' could not get vid object after 10 tries re-run: getEmbedObj()' ) ;
71 setTimeout('$j(\'#'+this.id+'\').get(0).postEmbedJS()',100);
75 doSeek:function(perc){
76 //js_log('native:seek:p: ' + perc+ ' : ' + this.supportsURLTimeEncoding() + ' dur: ' + this.getDuration() + ' sts:' + this.seek_time_sec );
77 //@@todo check if the clip is loaded here (if so we can do a local seek)
78 if( this.supportsURLTimeEncoding() || !this.vid){
79 //make sure we could not do a local seek instead:
80 if( perc < this.bufferedPercent && this.vid.duration && !this.didSeekJump ){
81 js_log("do local seek " + perc + ' is already buffered < ' + this.bufferedPercent);
82 this.doNativeSeek(perc);
84 this.parent_doSeek(perc);
86 }else if(this.vid && this.vid.duration ){
87 //(could also check bufferedPercent > perc seek (and issue oggz_chop request or not)
88 this.doNativeSeek( perc );
90 this.doPlayThenSeek( perc )
93 doNativeSeek:function(perc){
95 this.vid.currentTime = perc * this.vid.duration;
96 this.parent_monitor();
98 doPlayThenSeek:function(perc){
99 js_log('native::doPlayThenSeek::');
103 var readyForSeek = function(){
105 //if we have duration then we are ready to do the seek
106 if(this.vid && this.vid.duration){
109 //try to get player for 10 seconds:
110 if( rfsCount < 200 ){
111 setTimeout(readyForSeek, 50);
114 js_log('error:doPlayThenSeek failed');
120 setCurrentTime: function(pos, callback){
125 var loaded = function(event) {
126 js_log('native:setCurrentTime (after load): ' + pos + ' : dur: ' + this.getDuration());
127 _this.vid.currentTime = pos;
128 var once = function(event) {
130 _this.vid.removeEventListener('seeked', once, false)
132 _this.vid.addEventListener('seeked', once, false);
133 _this.removeEventListener('loadedmetadata', loaded, false);
135 _this.addEventListener('loadedmetadata', loaded, false);
137 //js_log('native:setCurrentTime: ' + pos + ' : ' + this.supportsURLTimeEncoding() + ' dur: ' + this.getDuration() + ' sts:' + this.seek_time_sec );
138 _this.vid.currentTime = pos;
139 var once = function(event) {
141 _this.vid.removeEventListener('seeked', once, false)
143 _this.vid.addEventListener('seeked', once, false);
146 monitor : function(){
147 this.getVID(); //make shure we have .vid obj
149 js_log('could not find video embed: '+this.id + ' stop monitor');
153 //don't update status if we are not the current clip (playlist leekage?) .. should move to playlist overwite of monitor?
155 if(this.pc.pp.cur_clip.id != this.pc.id)
160 this.currentTime = this.vid.currentTime;
161 this.addPresTimeOffset();
163 //js_log('currentTime:' + this.currentTime);
164 //js_log('this.currentTime: ' + this.currentTime );
165 //once currentTime is updated call parent_monitor
166 this.parent_monitor();
169 var src = this.parent_getSrc();
170 if( this.urlAppend != '')
171 return src + ( (src.indexOf('?')==-1)?'?':'&') + this.urlAppend;
175 * native callbacks for the video tag:
177 oncanplaythrough : function(){
178 //js_log('f:oncanplaythrough');
183 onloadedmetadata: function(){
185 js_log('f:onloadedmetadata metadata ready (update duration)');
186 //update duration if not set (for now trust the getDuration more than this.vid.duration
187 if( this.getDuration()==0 && !isNaN( this.vid.duration )){
188 js_log('updaed duration via native video duration: '+ this.vid.duration)
189 this.duration = this.vid.duration;
192 onprogress: function(e){
193 this.bufferedPercent = e.loaded / e.total;
194 //js_log("onprogress:" +e.loaded + ' / ' + (e.total) + ' = ' + this.bufferedPercent);
199 js_log('native:onended:' + this.vid.currentTime + ' real dur:' + this.getDuration() );
200 //if we just started (under 1 second played) & duration is much longer.. don't run onClipDone just yet . (bug in firefox native sending onended event early)
201 if(this.vid.currentTime < 1 && this.getDuration() > 1 && this.grab_try_count < 5){
202 js_log('native on ended called with time:' + this.vid.currentTime + ' of total real dur: ' + this.getDuration() + ' attempting to reload src...');
203 var doRetry = function(){
204 _this.urlAppend = 'retry_src=' + _this.grab_try_count;
206 _this.grab_try_count++;
208 setTimeout(doRetry, 100);
215 this.parent_pause(); //update interface
224 this.parent_play(); //update interface
227 //re-start the monitor:
231 toggleMute:function(){
232 this.parent_toggleMute();
235 this.vid.muted = this.muted;
237 updateVolumen:function(perc){
240 this.vid.volume = perc;
242 getVolumen:function(){
245 return this.vid.volume;
247 getNativeDuration:function(){
249 return this.vid.duration;
255 js_log('native::load() ... doEmbed');
256 this.onlyLoadFlag = true;
259 //won't happen offten
263 // get the embed vlc object
264 getVID : function (){
265 this.vid = $j('#'+this.pid).get(0);
269 * mannages native playlist calls