
function onunload(){XMPMonitor.stop(); };

var XMPMonitor={	
	tasks:new Array(),
	addTask:function(obj){
				this.tasks.push(obj);
			},
	start:function(){
					this.execute();					
				},
	execute:function(){
						for (var i=0; i<this.tasks.length; i++)
							if(typeof this.tasks[i].start == "function")
								 this.tasks[i].start( );
					},
	stop:function(){
					for (var i=0; i<this.tasks.length; i++)
							if(typeof this.tasks[i].stop == "function")
								 this.tasks[i].stop();
				}
}

var playContinueTask ={
	timerID:0,
	period:1000,
	count:0,
	start:function ( ){
						var pThis=this;						
						this.timerID=setInterval(function(){
																		pThis.execute()
																	},
											 pThis.period);						
					},
	execute:function(){
					  
						if(!this.PlayControl){
							this.xmpPlayer=getAddin("xmpplayer");
							if(this.xmpPlayer)
								this.PlayControl=this.xmpPlayer.PlayControl;
						}
						if(!this.dapCtrl && this.PlayControl)
							this.dapCtrl = this.PlayControl.GetDapPtr();
						if(this.PlayControl && this.dapCtrl){
							//PS_PLAYING			 
						//	a =undefind;
								trace(" this.PlayControl.GetStatus() == " + this.PlayControl.GetStatus()+", this.PlayControl.GetFileURL()="+this.PlayControl.GetFileURL());
								var status = this.PlayControl.GetStatus();
								if(5 == status){
									var url = this.PlayControl.GetFileURL();
									trace(" url == " + url);							
									if(url && url.length > 4){
											var ext=url.substr(url.length-4, 4);
											trace(" ext == " + ext);
											if(ext.toUpperCase()==".SWF")
												return;
									}
									if(url && url.length > 12){
										var ext=url.substr(url.length-12, 12);
										trace(" ext == " + ext);
										if(ext.toUpperCase()=="VIDEO_TS.IFO")
												return;
									}
								
									var _currentPos = this.PlayControl.GetPosition();
									trace("_currentPos = "+_currentPos);
									var currentPos=Math.round(this.PlayControl.GetPosition());
									currentPos = currentPos?currentPos*1:0;								
									var playDuration=this.dapCtrl.Get("DPLAYDURATION");
									playDuration = playDuration?playDuration*1000:0
									trace(" currentPos = "+currentPos+", playDuration = " + playDuration + ", this.lastPos = " + this.lastPos+", this.count="+this.count);
									if(this.lastPos == currentPos && ((playDuration > currentPos+2000) || url[1]==":"))
									{
										if(!this.count)
											this.count=0;									
										this.count++;
										if(this.count>5){
											this.count=0;	
											this.PlayControl.SetPosition(currentPos+1000);
										}
									
									}
									else
										this.count=0;
									this.lastPos=currentPos;
								}
								//1、对于第一次状态为3的时候，单独处理，当可播长度 > 10 时候，一次拖动3秒, 2、只对 WMV 格式的文件做这种处理
								else if(3 == status)
								{
									var url = this.PlayControl.GetFileURL();
									trace(" url == " + url);							
									if(url && url.length > 4){
											var ext=url.substr(url.length-4, 4);
											trace(" ext == " + ext);
											if(ext.toUpperCase()!=".WMV")
												return;
									}
									var _currentPos = this.PlayControl.GetPosition();
									trace("_currentPos = "+_currentPos);
									var currentPos=Math.round(this.PlayControl.GetPosition());
									currentPos = currentPos?currentPos*1:0;								
									var playDuration=this.dapCtrl.Get("DPLAYDURATION");
									playDuration = playDuration?playDuration*1000:0
									trace(" currentPos = "+currentPos+", playDuration = " + playDuration + ", this.lastPos = " + this.lastPos+", this.count="+this.count);
									if(this.lastPos == currentPos && ((playDuration > currentPos+8000)))
									{
										if(!this.count)
											this.count=0;									
										this.count++;
										if(this.count>5){
											this.count=0;	
											this.PlayControl.SetPosition(currentPos+2000);
											//this.PlayControl.Play();
										}
									
									}
									else
										this.count=0;
									this.lastPos=currentPos;										
								}
								else 
									this.count=0;
										
							}
					},
	stop:function()	{
				//alert("stop ");
					clearInterval(this.timerID);
				}
}
XMPMonitor.addTask(playContinueTask);
XMPMonitor.start();
