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
){
124 js_log('native:setCurrentTime: load video');
126 var loaded = function(event
) {
127 js_log('native:setCurrentTime (after load): ' + pos
+ ' : dur: ' + this.getDuration());
128 _this
.vid
.currentTime
= pos
;
129 var once = function(event
) { callback(); _this
.vid
.removeEventListener('seeked', once
, false) };
130 _this
.vid
.addEventListener('seeked', once
, false);
131 _this
.removeEventListener('loadedmetadata', loaded
, false);
133 _this
.addEventListener('loadedmetadata', loaded
, false);
135 js_log('native:setCurrentTime: ' + pos
+ ' : ' + this.supportsURLTimeEncoding() + ' dur: ' + this.getDuration() + ' sts:' + this.seek_time_sec
);
136 _this
.vid
.currentTime
= pos
;
137 var once = function(event
) { callback(); _this
.vid
.removeEventListener('seeked', once
, false) };
138 _this
.vid
.addEventListener('seeked', once
, false);
141 monitor : function(){
142 this.getVID(); //make shure we have .vid obj
144 js_log('could not find video embed: '+this.id
+ ' stop monitor');
148 //don't update status if we are not the current clip (playlist leekage?) .. should move to playlist overwite of monitor?
150 if(this.pc
.pp
.cur_clip
.id
!= this.pc
.id
)
155 this.currentTime
= this.vid
.currentTime
;
156 this.addPresTimeOffset();
157 //js_log('currentTime:' + this.currentTime);
158 //js_log('this.currentTime: ' + this.currentTime );
159 //once currentTime is updated call parent_monitor
160 this.parent_monitor();
163 var src
= this.parent_getSrc();
164 if( this.urlAppend
!= '')
165 return src
+ ( (src
.indexOf('?')==-1)?'?':'&') + this.urlAppend
;
169 * native callbacks for the video tag:
171 oncanplaythrough : function(){
172 js_log('f:oncanplaythrough');
177 onloadedmetadata: function(){
179 js_log('f:onloadedmetadata metadata ready (update duration)');
180 //update duration if not set (for now trust the getDuration more than this.vid.duration
181 if( this.getDuration()==0 && !isNaN( this.vid
.duration
)){
182 js_log('updaed duration via native video duration: '+ this.vid
.duration
)
183 this.duration
= this.vid
.duration
;
186 onprogress: function(e
){
187 this.bufferedPercent
= e
.loaded
/ e
.total
;
188 //js_log("onprogress:" +e.loaded + ' / ' + (e.total) + ' = ' + this.bufferedPercent);
193 js_log('native:onended:' + this.vid
.currentTime
+ ' real dur:' + this.getDuration() );
194 //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)
195 if(this.vid
.currentTime
< 1 && this.getDuration() > 1 && this.grab_try_count
< 5){
196 js_log('native on ended called with time:' + this.vid
.currentTime
+ ' of total real dur: ' + this.getDuration() + ' attempting to reload src...');
197 var doRetry = function(){
198 _this
.urlAppend
= 'retry_src=' + _this
.grab_try_count
;
200 _this
.grab_try_count
++;
202 setTimeout(doRetry
, 100);
209 this.parent_pause(); //update interface
218 this.parent_play(); //update interface
221 //re-start the monitor:
225 toggleMute:function(){
226 this.parent_toggleMute();
229 this.vid
.muted
= this.muted
;
231 updateVolumen:function(perc
){
234 this.vid
.volume
= perc
;
236 getVolumen:function(){
239 return this.vid
.volume
;
245 js_log('native::load() ... doEmbed');
246 this.onlyLoadFlag
= true;
249 //won't happen offten
253 // get the embed vlc object
254 getVID : function (){
255 this.vid
= $j('#'+this.pid
).get(0);
259 * mannages native playlist calls