getMediaPlayer=function(id){ var el=getDomById(id); if(!el){ console.log(1000); return; } if(!isIE && el.tagName == 'OBJECT'){ var embed = el.getElementsByTagName('EMBED')[0]; if(embed){ el=embed; } } if(el.tagName == 'VIDEO'){ return new Html5Player(el); }else if(el.type=='application/x-shockwave-flash' || el.tagName == 'EMBED'){ return new FlashPlayer(el); }else if(el.type=='application/x-oleobject' || el.type == 'application/x-ms-wmp'){ return new MSMediaPlayer(el); } } FlashPlayer=function(el){ this.playerType='flash'; this._player=jwplayer(el); } FlashPlayer.prototype={ getPlayState: function(){ //PLAYING=播放,PAUSED=暂停,IDLE=停止(空闲),BUFFERING=正在缓冲,COMPLETED=结束 var status=this._player.getState(); switch(status){ case 'PLAYING': return 3; case 'PAUSED': return 2; case 'IDLE': return 1; case 'BUFFERING': return 6; } return ; }, play:function(){ this._player.play(); }, pause:function(){ this._player.pause(); }, stop:function(){ this._player.stop(); }, setMute:function(b){ return this._player.setMute(b); }, getMute:function(){ return this._player.getMute(); }, setVolume:function(v){ return this._player.setVolume(v); }, setCurrentTime:function(v){ return this._player.seek(v); }, getCurrentTime:function(){ return this._player.getPosition(); }, getCurrentTimeString:function(){ return second2LocalString(this._player.getPosition()); }, getDuration:function(){ return this._player.getDuration(); }, getDurationString:function(){ return second2LocalString(this._player.getDuration()); }, getFullScreenState:function(){ return this._player.getFullscreen(); }, setFullScreen:function(b){ return this._player.setFullscreen(b); }, onBufferChange:function(fn){ this._player.onBufferChange(fn); }, onPlay:function(fn){ this._player.onPlay(fn); }, onPause:function(fn){ this._player.onPause(fn); }, onSeek:function(fn){ this._player.onSeek(fn); }, onTime:function(fn){ this._player.onTime(fn); }, onIdle:function(fn){ this._player.onIdle(fn); } }; MSMediaPlayer=function(el){ this.playerType='msmedia'; this._player=el; this.custEvent=CustEvent(this); } MSMediaPlayer.prototype={ getPlayState: function(){ return this._player.playState; //1=停止,2=暂停,3=播放,6=正在缓冲,7=等待,8=结束,9=正在连接,10=准备就绪 }, play:function(){ this._player.controls.play(); }, pause:function(){ this._player.controls.pause(); }, stop:function(){ this._player.controls.stop(); }, setMute:function(b){ return this._player.settings.mute=b; }, getMute:function(){ return this._player.settings.mute; }, setVolume:function(v){ return this._player.settings.volume=v; }, setCurrentTime:function(v){ return this._player.controls.currentPosition=v; }, getCurrentTime:function(){ return this._player.controls.currentPosition; }, getCurrentTimeString:function(){ return this._player.controls.currentPositionString; }, getDuration:function(){ return this._player.currentMedia.duration; }, getDurationString:function(){ return this._player.currentMedia.durationString; }, getFullScreenState:function(){ var b=this._player.fullScreen; playerObj._player.fullScreen=b; return b; }, setFullScreen:function(b){ return this._player.fullScreen=b; }, setMode:function(mode){ //播放器控制条模式,可为full, mini, none, invisible return this._player.uiMode=mode; }, onSeek:function(fn){ this.custEvent.add('seek',fn); }, onTime:function(fn){ this.custEvent.add('time',fn); }, onIdle:function(fn){ this.custEvent.add('idle',fn); }, onFullScreen:function(fn){ this.custEvent.add('fullscreen',fn); } }; Html5Player=function(el){ this.playerType='html5'; this._player=el; this.custEvent=CustEvent(this); } Html5Player.prototype={ getPlayState: function(){ //1=停止,2=暂停 if(this._player.ended ){ return 1; } if(this._player.paused){ return 2; } if(!this._player.paused && this._player.currentTime != 0){ return 3; } return ; }, play:function(){ this._player.play(); }, pause:function(){ this._player.pause(); }, stop:function(){ this._player.pause(); this._player.currentTime = 0; }, setMute:function(b){ return this._player.muted=b; }, getMute:function(){ return this._player.muted; }, setVolume:function(v){ return this._player.volume=v; }, setCurrentTime:function(v){ return this._player.currentTime=v; }, getCurrentTime:function(){ return this._player.currentTime; }, getCurrentTimeString:function(){ return second2LocalString(this._player.currentTime); }, getDuration:function(){ return this._player.duration; }, getDurationString:function(){ return second2LocalString(this._player.duration); }, setFullScreen:function(){ return this._player.webkitRequestFullScreen(); }, onSeek:function(fn){ this.custEvent.add('seek',fn); }, onTime:function(fn){ this.custEvent.add('time',fn); }, onIdle:function(fn){ this.custEvent.add('idle',fn); } }; CustEvent=function(space){ var _events={}; return { fire:function(evtName){ if(_events[evtName] && _events[evtName].length>0){ for(var i=0;i<_events[evtName].length;i++){ //console.log(_events,evtName,i); _events[evtName][i].call(space||window); } } }, add:function(evtName,func){ if(!_events[evtName]){ _events[evtName]=[]; } _events[evtName].push(func); }, remove:function(evtName,func){ if(!func){ _events[evtName]=[]; }else{ for(var i=0;i<_events[evtName].length;i++){ _events[evtName][i]==func; _events[evtName].splice(i,1); } } } } };