/* ������ƣ�chplayer ����汾��v1.0 ������ߣ�http://www.chplayer.com ��դ���э�飺mozilla public license, version 2.0(mpl 2.0) mpl 2.0э��ӣ�ģ�ԭ�ģ��������鿴��ַ��https://www.mozilla.org/en-us/mpl/2.0/ mpl 2.0э�����ģ����룩�鿴��ַ��http://www.chplayer.com/res/mozilla_public_license_2.0_simplified_chinese_reference.txt --------------------------------------------------------------------------------------------- ����˵���� ʹ�õ���ҫ�������ԣ�javascript(js)��actionscript3.0(as3.0)(as3.0��ҫ����flashplayer���ֵŀ��������ڸ�ҳ�����) ���ܣ�������ƶ �ص㣺����html5-video(����)�լ�flashplayer ===================================================================================================================== */ !(function() { var javascriptpath = ''; ! function() { var scriptlist = document.scripts, thispath = scriptlist[scriptlist.length - 1].src; javascriptpath = thispath.substring(0, thispath.lastindexof('/') + 1); }(); var chplayer = function(obj) { if(obj) { this.embed(obj); } }; chplayer.prototype = { /* javascript���ֿ������õ�ע��˵���� 1����ʼ��-�������ʱ�����еĵ��벿�� 2��������ʽ-����������div,p,canvas�ȣ�����ʽ�����css 3����������-����Ԫ�ؽڵ㣨����-click��������-mouseover������뿪-mouseout������ƶ�-mousemove�ȣ��¼� 4�������¼�-������ƶ��״̬�����ţ���ͣ��ȫ�����������ڵȣ��¼� 5�����ú���-���ຯ�����ⲿҳ����ʹ�� 6��ȫ�ֱ���-�����ȫ��ʹ�õı��� 7���������ע�� ȫ�ֱ���˵���� �ڱ��������ʹ�õ���ȫ�ֱ��������������ͣ�����boolean��string��int��object������Ԫ�ض���ͱ������󣩣�array��function�ȣ� �����г���ҫ��ȫ�ֱ����� v:object����ƶ���� va:array����ƶ�б��������ƶ��ַ�����ͣ�������˵���� id:string����ƶid cb:object����������Ԫ�صļ��϶��� pd:object���ڲ���ƶ�������� --------------------------------------------------------------------------------------------- ����ʼ ����ϊ��ҫ��ʼ�����õ�ȫ�ֱ��� ��ʼ������ config��ȫ�ֱ���/�������ͣ�object/���ܣ�����һщ�������� */ config: { videoclick: true, //�ƿ�֧�ֵ�������/��ͣ���� videodbclick: true, //�ƿ�֧��˫��ȫ��/�˳�ȫ������ errortime: 100, //�ӳ��ж�ʧ�ܵ�ʱ�䣬��λ������ videodrawimage: false //�ƿ�ʹ����ƶdrawimage���ܣ�ע�⣬�ù������ƶ��˱��ֲ��� }, //ȫ�ֱ���/�������ͣ�object/���ܣ�������ĭ�����ã����ⲿ���ݹ�����ӧ���ú����������滻 varsconfig: { container: '', //��ƶ������id variable: 'chplayer', //���ź���(����)���� volume: 0.8, //ĭ����������χ0-1 poster: '', //����ͼƭ��ַ autoplay: true, //�ƿ��զ����� loop: false, //�ƿ���ҫѭ������ live: false, //�ƿ���ֱ�� seek: 0, //ĭ����ҫ��ת������ drag: '', //�϶�ʱ֧�ֵ�ǰ�ò��� front: '', //ǰһ����ť���� next: '', //��һ����ť���� loaded: '', //���ز���������õĺ��� flashplayer: false, //���ó�true��ǿ��ʹ��flashplayer html5m3u8: false, //pcƽ̨���ƿ�ʹ��h5����������m3u8 track: null, //��ļ��� chtrack: null, //ch��ļ preview: null, //Ԥ��ͼƭ���� prompt: null, //��ʾ�㹦�� video: null, //��ƶ��ַ debug:false//�ƿ������ģʽ }, vars: {}, //ȫ�ֱ���/�������ͣ�object/���ܣ��������� language: { volume: '������', play: '�������', pause: '�����ͣ', full: '���ȫ��', escfull: '�˳�ȫ��', mute: '�������', escmute: 'ȡ������', front: '��һ��', next: '��һ��', definition: '���ѡ��������', error: '���س���' }, //ȫ�ֱ���/�������ͣ�array/���ܣ��ҽ��˵���[�˵�����,����(link:���ӣ�default:��ɫ��function�����ú�����javascript:����js����),ִ������(�������ӵ�ַ����������),[line(�����)]] contextmenu: [ ['chplayer', 'link', 'http://www.chplayer.com'], ['v1.0', 'default'], ['������ƶ', 'function', 'play', 'line'], ['��ͣ��ƶ', 'function', 'pause'], ['����/��ͣ', 'function', 'playorpause'] ], //ȫ�ֱ���/�������ͣ�array/���ܣ������б� errorlist: [ ['000', 'object does not exist'], ['001', 'variables type is not a object'], ['002', 'video object does not exist'], ['003', 'video object format error'], ['004', 'video object format error'], ['005', 'video object format error'], ['006', '[error] does not exist '], ['007', 'ajax error'], ['008', 'ajax error'], ['009', 'ajax object format error'], ['010', 'ajax.status:[error]'] ], //ȫ�ֱ���/�������ͣ�string/���ܣ�����logo logo: '', //ȫ�ֱ���/�������ͣ�boolean/���ܣ��ƿ�����˲����� loaded: false, //ȫ�ֱ���/�������ͣ���ʱ��/���ܣ�������ƶ���س����״̬ timererror: null, //ȫ�ֱ���/�������ͣ�boolean/���ܣ��ƿ���� error: false, //ȫ�ֱ���/�������ͣ�array/���ܣ������ַ������ errorurl: [], //ȫ�ֱ���/�������ͣ�array/���ܣ������洢��������ĺ����б����ƶ���ش���ʱ��������ĺ���������յ���ϣ errorfunarr: [], //ȫ�ֱ���/�������ͣ���ʱ��/���ܣ�����ȫ�����ȫ��״̬ timerfull: null, //ȫ�ֱ���/�������ͣ�boolean/���ܣ��ƿ�ȫ��״̬ full: false, //ȫ�ֱ���/�������ͣ�array/���ܣ������洢ȫ�����ȫ�������ĺ����б������ȫ�����ȫ��ʱ��������ĺ���������յ���ϣ fullfunarr: [], //ȫ�ֱ���/�������ͣ�array/���ܣ������洢���ŵ�ַ�ı�ļ��������ĺ����б�������ŵ�ַ�����ı�ʱ��������ĺ���������յ���ϣ videochangefunarr: [], //ȫ�ֱ���/�������ͣ���ʱ��/���ܣ�������ǰ����/�� ʱ:��:�� timertime: null, //ȫ�ֱ���/�������ͣ���ʱ��/���ܣ�������ƶ���� timerbuffer: null, //ȫ�ֱ���/�������ͣ�boolean/���ܣ����ý��ȱ�ť���������ƿ����ʱ��仯����������ҫ�����ڰ��½��ȱ�ťʱ��ͣ���ȱ�ť�ƶ��ͽ������ij��ȱ仯 istimebuttonmove: true, //ȫ�ֱ���/�������ͣ�boolean/���ܣ��������ƿ���ч�������ֱ��������ҫ����ʱ���ý��ȱ�ť�ͽ������仯 istimebuttondown: false, //ȫ�ֱ���/�������ͣ�boolean/���ܣ�����ģ��˫�����ܵ��ж� isclick: false, //ȫ�ֱ���/�������ͣ���ʱ��/���ܣ�����ģ��˫�����ܵļ�ʱ�� timerclick: null, //ȫ�ֱ���/�������ͣ���ʱ��/���ܣ���תloading timerloading: null, //ȫ�ֱ���/�������ͣ���ʱ��/���ܣ������������ƶ���ƶ���ʾ������ timercbar: 0, //ȫ�ֱ���/�������ͣ�int/���ܣ�������ƶʱ����ñ�����ֵ����0���������ת�����ø�ֵϊ0 needseek: 0, //ȫ�ֱ���/�������ͣ�int/���ܣ���ǰ���� volume: 0, //ȫ�ֱ���/�������ͣ�number/���ܣ���ǰ����ʱ�� time: 0, //ȫ�ֱ���/�������ͣ�boolean/���ܣ������״ε��� isfirst: true, //ȫ�ֱ���/�������ͣ�boolean/���ܣ��ƿ�ʹ��html5-video���� html5video: true, //ȫ�ֱ���/�������ͣ�object/���ܣ���¼��ƶ�����ڵ��x,y pdcoor: { x: 0, y: 0 }, //ȫ�ֱ���/�������ͣ�string/���ܣ��жϵ�ǰʹ�õij��������ͣ�html5video��flashplayer playertype: '', //ȫ�ֱ���/�������ͣ�int/���ܣ����ؽ������ij��� loadtime: 0, //ȫ�ֱ���/body���� body: document.body || document.documentelement, //ȫ�ֱ���/v/������ v: null, //ȫ�ֱ���/��������¼����飬ͳһ���� listenerarr: [], //ȫ�ֱ���/�����������ʾԪ�ص��ܿ�� buttonlen: 0, //ȫ�ֱ���/�����������ʾԪ�ص����� buttonarr: [], //ȫ�ֱ���/���水ťԪ�صŀ� buttonwidth: {}, //ȫ�ֱ���/���沥����������Ԫ�������� elementarr: [], //ȫ�ֱ���/��ļ���� track: [], //ȫ�ֱ���/��ļ���� trackindex: 0, //ȫ�ֱ���/��ǰ��ʾ����ļ���� nowtrackshow: { sn: '' }, //ȫ�ֱ���/������ļԪ������ trackelement: [], //ȫ�ֱ���/����ƶת��ϊͼƭ timervcanvas: null, //ȫ�ֱ���/animate animatearray: [], //ȫ�ֱ���/����animate��Ԫ�� animateelementarray: [], //ȫ�ֱ���/������ҫ����ͣʱֹͣ���������� animatepausearray: [], //ȫ�ֱ���/Ԥ��ͼƭ����״̬/0=û�м��أ�1=���ڼ��أ�2=������� previewstart: 0, //ȫ�ֱ���/Ԥ��ͼƭ���� previewdiv: null, //ȫ�ֱ���/Ԥ���� previewtop: null, //ȫ�ֱ���/Ԥ����ŀ� previewwidth: 120, //ȫ�ֱ���/Ԥ��ͼƭ������������ previewtween: null, //ȫ�ֱ���/�ƿ���m3u8��ʽ���ǵļ�����լ���hls.js ism3u8: false, //ȫ�ֱ���/������ʾ������ promptarr: [], //ȫ�ֱ���/��ʾ��ʾ���ļ������� promptelement: null, /* ��ҫ�������ֿ�ʼ ���ӿں����� ���ò��������ʼ���ú��� */ embed: function(c) { //c:object���ǵ��ýӿڴ��ݵ����զ��� if(c == undefined || !c) { this.eject(this.errorlist[0]); return; } if(typeof(c) != 'object') { this.eject(this.errorlist[1]); } this.vars = this.standardization(this.varsconfig, c); if((!this.supportvideo() && this.vars['flashplayer'] != '') || this.vars['flashplayer']) { this.html5video = false; } if(this.vars['video']) { //�ж���ƶ�������� this.analysedvideourl(this.vars['video']); return this; } else { this.eject(this.errorlist[2]); } }, /* �ڲ����� �����ⲿ���ݹ�����video��ʼ������ƶ��ַ */ analysedvideourl: function(video) { var i = 0, y = 0; var thistemp = this; //����ȫ�ֱ���va:array����ƶ�б��������ƶ��ַ�����ͣ�������˵���� this.va = []; if(typeof(video) == 'string') { //������ַ���ʽ�����жϻ�׺������� this.va = [ [video, '', '', 0] ]; var fileext = this.getfileext(video); switch(fileext) { case '.mp4': this.va[0][1] = 'video/mp4'; break; case '.ogg': this.va[0][1] = 'video/ogg'; break; case '.webm': this.va[0][1] = 'video/webm'; break; default: break; } this.getvideo(); } else if(typeof(video) == 'object') { //��������� if(!this.isundefined(typeof(video.length))) { //˵�������� if(typeof(video[0]) == 'string') { /* ������ı���ʽ������ video:['url','type','url','type'] */ if(video.length % 2 == 1) { this.eject(this.errorlist[3]); return; } for(i = 0; i < video.length; i++) { if(i % 2 == 0) { this.va.push([video[i], video[i + 1], '', 0]); } } } else if(!this.isundefined(typeof(video[0].length))) { //˵����������ʽ������ this.va = video; } else { /* �����ʽ��˵���dz�׼����ƶ��ַ��ʽ video: [ { definition: '', list: [ { url: '', type: '', weight:0 }, { url: '', type: '', weight:10 } ] }, { definition: '', list: [ { url: '', type: '', weight:0 } ] } ] */ //������ƶ��ַ for(i = 0; i < video.length; i++) { var vlist = video[i]['list']; for(y = 0; y < vlist.length; y++) { this.va.push([vlist[y]['url'], vlist[y]['type'], video[i]['definition'], this.isundefined(vlist[y]['weight']) ? 0 : vlist[y]['weight']]); } } } this.getvideo(); } else { /* ���video��ʽ�ƕ�����ʽ����ֶ��� ���video���������type����ֱ�ӳ��� */ if(!this.isundefined(video['type'])) { this.va.push([video['url'], video['type'], '', 0]); this.getvideo(); } /* ���video���������ajax����ʹ��ajax���� */ else if(!this.isundefined(video['url'])) { //ֻҫ����url������ϊ��ajax���� video.success = function(data) { thistemp.analysedvideourl(data); }; this.ajax(video); } else { this.eject(this.errorlist[5]); } } } else { this.eject(this.errorlist[4]); } }, /* �ڲ����� ��������֧�ֵ���ƶ��ʽ���������֧�ֵ���ƶ��ʽ���·���������б� */ gethtml5video: function() { var va = this.va; var nva = []; var mobile = false; var video = document.createelement('video'); var codecs = function(type) { var cod = ''; switch(type) { case 'video/mp4': cod = 'avc1.4d401e, mp4a.40.2'; break; case 'video/ogg': cod = 'theora, vorbis'; break; case 'video/webm': cod = 'vp8.0, vorbis'; break; default: break; } return cod; }; var supporttype = function(vidtype, codtype) { if(!video.canplaytype) { this.html5video = false; return; } var issupp = video.canplaytype(vidtype + ';codecs="' + codtype + '"'); if(issupp == '') { return false } return true; }; if(this.vars['flashplayer']) { this.html5video = false; return; } if(navigator.useragent.match(/(iphone|ipod|android|ios)/i)) { mobile = true; } for(var i = 0; i < va.length; i++) { var v = va[i]; if(v){ if(v[1] != '' && !mobile && supporttype(v[1], codecs(v[1])) && v[0].substr(0, 4) != 'rtmp') { nva.push(v); } if(this.getfileext(v[0]) == '.m3u8' && this.vars['html5m3u8']) { this.ism3u8 = true; nva.push(v); } } } if(nva.length > 0) { this.va = nva; } else { if(!mobile) { this.html5video = false; } } }, /* �ڲ����� ������ƶ��ַ��ʼ���������� */ getvideo: function() { //���������ļ����� if(this.v) { //����������ѵ��ڣ�����ϊ�ǵ�newvideo�������͹��������� this.changevideo(); return; } if(this.vars['chtrack']) { this.loadtrack(); } this.gethtml5video(); //�ж������֧�ֵ���ƶ��ʽ var thistemp = this; var v = this.vars; var src = '', source = '', poster = '', loop = '', autoplay = '', track = ''; var video = v['video']; var i = 0; this.cd = this.getbyelement(v['container']); volume = v['volume']; if(!this.cd) { this.eject(this.errorlist[6], v['container']); return false; } //��ʼ������������ var playerid = 'chplayer' + this.randomstring(); var playerdiv = document.createelement('div'); playerdiv.classname = playerid; this.v = undefined; this.cd.innerhtml = ''; this.cd.appendchild(playerdiv); this.pd = this.getbyelement(playerid); //pd:���岥������������ȫ�ֱ��� this.css(this.cd, { backgroundcolor: '#000000', overflow: 'hidden', position: 'relative' }); this.css(this.pd, { backgroundcolor: '#000000', width: '100%', height: '100%', fontfamily: '"microsoft yahei", yahei, "΢���ź�", simhei,"\5fae\8f6f\96c5\9ed1", "����",arial' }); if(this.html5video) { //���֧��html5-video��ĭ��ʹ��html5-video������ //��ֹ���������������ѡ���ı� this.pd.onselectstart = this.pd.ondrag = function() { return false; }; //��������������ɲ������ú���ʽ //���������� if(this.va.length == 1) { src = ' src="' + this.va[0][0] + '"'; } else { var videoarr = this.va.slice(0); videoarr = this.arrsort(videoarr); for(i = 0; i < videoarr.length; i++) { var type = ''; var va = videoarr[i]; if(va[1]) { type = ' type="' + va[1] + '"'; } source += ''; } } //������ƶ��ַ���� if(v['autoplay']) { autoplay = ' autoplay="autoplay"'; } if(v['poster']) { poster = ' poster="' + v['poster'] + '"'; } if(v['loop']) { loop = ' loop="loop"'; } if(v['seek'] > 0) { this.needseek = v['seek']; } if(v['track'] != null && v['chtrack'] == null) { var trackarr = v['track']; var trackdefault = ''; var defaulthave = false; for(i = 0; i < trackarr.length; i++) { var trackobj = trackarr[i]; if(trackobj['default'] && !defaulthave) { trackdefault = ' default'; defaulthave = true; } else { trackdefault = ''; } track += ''; } } var vid = this.randomstring(); var html = ''; if(!this.ism3u8) { html = ''; } else { html = ''; } this.pd.innerhtml = html; this.v = this.getbyelement('#'+vid); //v�����岥��������ȫ�ֱ��� this.v.volume = volume; //�������� if(this.ism3u8) { var loadjshandler = function() { thistemp.embedhls(thistemp.va[0][0], v['autoplay']); }; this.loadjs(javascriptpath + 'hls/hls.min.js', loadjshandler); } this.css(this.v, 'backgroundcolor', '#000000'); //����һ���������� if(this.config['videodrawimage']) { var canvasid = 'vcanvas' + this.randomstring(); var canvasdiv = document.createelement('div'); canvasdiv.classname = canvasid; this.pd.appendchild(canvasdiv); this.md = this.getbyelement(canvasid); //���廭���洢���� this.css(this.md, { backgroundcolor: '#000000', width: '100%', height: '100%', position: 'absolute', display: 'none', cursor: 'pointer', left: '0px', top: '0px', zindex: '10' }); var cvid = 'ccanvas' + this.randomstring(); this.md.innerhtml = this.newcanvas(cvid, this.pd.offsetwidth, this.pd.offsetheight); this.mdc = this.getbyelement(cvid + '-canvas'); this.mdcx = this.mdc.getcontext('2d'); } this.playertype = 'html5video'; //������������ɲ������ú���ʽ //�����������ļ������������������������¼����� this.addvevent(); //���������ȵ�ֵ�����������л���ť this.definition(); this.playerload(); } else { //�����֧��html5-video�����flashplayer this.embedswf(); } }, /* �ڲ����� ���ͳ��������سɹ�����ϣ */ playerload: function() { var thistemp = this; if(this.isfirst) { this.isfirst = false; window.settimeout(function() { thistemp.loadedhandler(); }, 1); } }, /* �ڲ����� �����������ļ������������������������¼����� */ addvevent: function() { var thistemp = this; //������ƶ�����¼� var eventvideoclick = function(event) { thistemp.videoclick(); }; this.addlistener('click', eventvideoclick); this.addlistener('click', eventvideoclick, this.mdc); //�ӳټ������ʧ���¼� this.timererrorfun(); //������ƶ���ص�Ԫ�����¼� var eventjudgeislive = function(event) { thistemp.judgeislive(); }; this.addlistener('loadedmetadata', eventjudgeislive); //������ƶ�����¼� var eventplaying = function(event) { thistemp.playinghandler(); }; this.addlistener('playing', eventplaying); //������ƶ��ͣ�¼� var eventpause = function(event) { thistemp.pausehandler(); }; this.addlistener('pause', eventpause); //������ƶ����ʱ���¼� var eventtimeupdate = function(event) { if(thistemp.timerloading != null) { thistemp.loadingstart(false); } }; this.addlistener('timeupdate', eventtimeupdate); //������ƶ�����¼� var eventwaiting = function(event) { thistemp.loadingstart(true); }; this.addlistener('waiting', eventwaiting); //������ƶseek�����¼� var eventseeked = function(event) { thistemp.seekedhandler(); }; this.addlistener('seeked', eventseeked); //������ƶ���ž����¼� var eventended = function(event) { thistemp.endedhandler(); }; this.addlistener('ended', eventended); //������ƶ���� var eventvolumechange = function(event) { try { thistemp.volumechangehandler(); } catch(event) {} }; this.addlistener('volumechange', eventvolumechange); //�������� this.interface(); }, /* �ڲ����� ���ý���Ԫ�� */ resetplayer: function() { this.timetexthandler(); this.timeprogress(0, 1); //�ı�ʱ��������� this.initplaypause(); //�ж���ʾ���ż���ͣ��ť this.definition(); //���������ȱ�ť this.showfrontnext(); //������һ����һ����ť this.deleteprompt(); //ɾ����ʾ�� this.deletepreview(); //ɾ��Ԥ��ͼ this.trackhide(); //������ļ this.resettrack(); this.trackelement = []; this.track = []; }, /* �ڲ����� ��������Ԫ�� */ interface: function() { var thistemp = this; var html = ''; //���������� var i = 0; var bwidth = 38, //��ť�ŀ� bheight = 38; //��ť�ĸ� var bbgcolor = '#ffffff', //��ťԪ��ĭ����ɫ bovercolor = '#0782f5'; //��ťԪ����꾭��ʱ����ɫ var timeinto = '00:00 / 00:00'; //ʱ����ʾ��ĭ����ʾ���� var randoms = this.randomstring(10); //��ȡһ������ַ��� /* ���¶�������Ԫ�ص�id��ͳһ��id���� */ var controlbarbgid = 'controlbgbar' + randoms, //���������� controlbarid = 'controlbar' + randoms, //���������� timeprogressbgid = 'timeprogressbg' + randoms, //���ž��������� loadprogressid = 'loadprogress' + randoms, //���ؽ����� timeprogressid = 'timeprogress' + randoms, //���ž����� timebobgid = 'timebobg' + randoms, //���ž��ȱ�ť��������Ԫ��ϊһ��͸�������ڲ��ž������� timeboid = 'timebo' + randoms, //���ž��ȿ��϶���ť��� timebwid = 'timebw' + randoms, //���ž��ȿ��϶���ť�ڿ� timetextid = 'timetext' + randoms, //ʱ���ı��� playid = 'play' + randoms, //���ű�ť pauseid = 'pause' + randoms, //��ͣ��ť frontid = 'front' + randoms, //ǰһ����ť nextid = 'next' + randoms, //��һ����ť fullid = 'full' + randoms, //ȫ����ť escfullid = 'escfull' + randoms, //�˳�ȫ����ť muteid = 'mute' + randoms, //�����ť escmuteid = 'escmute' + randoms, //ȡ�������ť volumeid = 'volume' + randoms, //�������ڿ����� volumedbgid = 'volumedbg' + randoms, //�������ڿ��������� volumebgid = 'volumebg' + randoms, //�������ڿ򱳾��� volumeupid = 'volumeup' + randoms, //�������ڿ�ɱ��ȳ� volumeboid = 'volumebo' + randoms, //�������ڰ�ť��� volumebwid = 'volumebw' + randoms, //�������ڰ�ť�ڿ� definitionid = 'definition' + randoms, //���������� definitionpid = 'definitionp' + randoms, //�������б����� promptbgid = 'promptbg' + randoms, //��ʾ�򱳾� promptid = 'prompt' + randoms, //��ʾ�� dlineid = 'dline' + randoms, //�ָ��߹���ǰ׺ menuid = 'menu' + randoms, //�ҽ����� pausecenterid = 'pausecenter' + randoms, //�м���ͣ��ť loadingid = 'loading' + randoms, //���� errortextid = 'errortext' + randoms, //�����ı��� logoid = 'logo' + randoms; //logo //����һщpd����������������ʹ�õ�Ԫ�� var controlbarbg = document.createelement('div'), controlbar = document.createelement('div'), timeprogressbg = document.createelement('div'), timebobg = document.createelement('div'), pausecenter = document.createelement('div'), errortext = document.createelement('div'), promptbg = document.createelement('div'), prompt = document.createelement('div'), menudiv = document.createelement('div'), definitionp = document.createelement('div'), loading = document.createelement('div'), logo = document.createelement('div'); controlbarbg.classname = controlbarbgid; controlbar.classname = controlbarid; timeprogressbg.classname = timeprogressbgid; timebobg.classname = timebobgid; promptbg.classname = promptbgid; prompt.classname = promptid; menudiv.classname = menuid; definitionp.classname = definitionpid; pausecenter.classname = pausecenterid; loading.classname = loadingid; logo.classname = logoid; errortext.classname = errortextid; this.pd.appendchild(controlbarbg); this.pd.appendchild(controlbar); this.pd.appendchild(timeprogressbg); this.pd.appendchild(timebobg); this.pd.appendchild(promptbg); this.pd.appendchild(prompt); this.pd.appendchild(definitionp); this.pd.appendchild(pausecenter); this.pd.appendchild(loading); this.pd.appendchild(errortext); this.pd.appendchild(logo); this.body.appendchild(menudiv); //����һщpd����������������ʹ�õ�Ԫ�ؽ��� if(this.vars['live']) { //�����ֱ����ʱ����ʾ�ı�������ʾ��ǰϵͳʱ�� timeinto = this.getnowdate(); } //���������������� html += '
' + this.newcanvas(playid, bwidth, bheight) + '
'; //���ű�ť html += '
' + this.newcanvas(pauseid, bwidth, bheight) + '
'; //��ͣ��ť html += '
'; //�ָ��� html += '
' + this.newcanvas(frontid, bwidth, bheight) + '
'; //ǰһ����ť html += '
'; //�ָ��� html += '
' + this.newcanvas(nextid, bwidth, bheight) + '
'; //��һ����ť html += '
'; //�ָ��� html += '
' + timeinto + '
'; //ʱ���ı� html += '
' + this.newcanvas(fullid, bwidth, bheight) + '
'; //ȫ����ť html += '
' + this.newcanvas(escfullid, bwidth, bheight) + '
'; //�˳�ȫ����ť html += '
'; //�ָ��� html += '
'; //���������� html += '
'; //�ָ��� html += '
'; //�������ڿ�,�������ڰ�ť html += '
' + this.newcanvas(muteid, bwidth, bheight) + '
'; //�����ť html += '
' + this.newcanvas(escmuteid, bwidth, bheight) + '
'; //�˳������ť html += '
'; //�ָ��� this.getbyelement(controlbarid).innerhtml = html; //�������������ݽ��� //�������������� this.getbyelement(timeprogressbgid).innerhtml = '
'; this.getbyelement(timebobgid).innerhtml = '
'; //�������������ݽ��� this.getbyelement(pausecenterid).innerhtml = this.newcanvas(pausecenterid, 80, 80); //�����м���ͣ��ť this.getbyelement(loadingid).innerhtml = this.newcanvas(loadingid, 60, 60); //�����м仺��ʱ��ʾ��ͼ�� this.getbyelement(errortextid).innerhtml = this.language['error']; //��������ʱ��ʾ���ı��� this.getbyelement(logoid).innerhtml = this.vars['logo'] || this.logo; //����logo //cb:object��ȫ�ֱ�������һщȫ����ҫ�õ���Ԫ��ͳһ����cb������ var pd=this.pd; this.cb = { controlbarbg: this.getbyelement(controlbarbgid,pd), controlbar: this.getbyelement(controlbarid,pd), promptbg: this.getbyelement(promptbgid,pd), prompt: this.getbyelement(promptid,pd), timeprogressbg: this.getbyelement(timeprogressbgid,pd), loadprogress: this.getbyelement(loadprogressid,pd), timeprogress: this.getbyelement(timeprogressid,pd), timebobg: this.getbyelement(timebobgid,pd), timebutton: this.getbyelement(timeboid,pd), timetext: this.getbyelement(timetextid,pd), play: this.getbyelement(playid,pd), front: this.getbyelement(frontid,pd), next: this.getbyelement(nextid,pd), pause: this.getbyelement(pauseid,pd), definition: this.getbyelement(definitionid,pd), definitionp: this.getbyelement(definitionpid,pd), definitionline: this.getbyelement(dlineid + '-rb',pd), full: this.getbyelement(fullid,pd), escfull: this.getbyelement(escfullid,pd), mute: this.getbyelement(muteid,pd), escmute: this.getbyelement(escmuteid,pd), volume: this.getbyelement(volumeid,pd), volumebg: this.getbyelement(volumebgid,pd), volumeup: this.getbyelement(volumeupid,pd), volumebo: this.getbyelement(volumeboid,pd), pausecenter: this.getbyelement(pausecenterid,pd), menu: this.getbyelement(menuid), loading: this.getbyelement(loadingid,pd), loadingcanvas: this.getbyelement(loadingid + '-canvas',pd), errortext: this.getbyelement(errortextid,pd), logo: this.getbyelement(logoid,pd), playline: this.getbyelement(dlineid + '-la',pd), frontline: this.getbyelement(dlineid + '-lb',pd), nextline: this.getbyelement(dlineid + '-lc',pd), fullline: this.getbyelement(dlineid + '-ra'), definitionline: this.getbyelement(dlineid + '-rb',pd), muteline: this.getbyelement(dlineid + '-rc',pd) }; this.buttonwidth = { play: bwidth, full: bwidth, front: bwidth, next: bwidth, mute: bwidth }; //�������Ԫ�ص���ʽ //���������� this.css(controlbarbgid, { width: '100%', height: bheight + 'px', backgroundcolor: '#000000', position: 'absolute', bottom: '0px', filter: 'alpha(opacity:0.8)', opacity: '0.8', zindex: '90' }); //���������� this.css(controlbarid, { width: '100%', height: bheight + 'px', position: 'absolute', bottom: '0px', zindex: '90' }); //�м���ͣ��ť this.css(pausecenterid, { width: '80px', height: '80px', borderradius: '50%', position: 'absolute', display: 'none', cursor: 'pointer', zindex: '100' }); //loading this.css(loadingid, { width: '60px', height: '60px', position: 'absolute', display: 'none', zindex: '100' }); //�����ı��� this.css(errortextid, { width: '120px', height: '30px', lineheight: '30px', color: '#ffffff', fontsize: '14px', textalign: 'center', position: 'absolute', display: 'none', zindex: '101', cursor: 'default', zindex: '100' }); //����logo���ֵ���ʽ this.css(logoid, { height: '30px', lineheight: '30px', color: '#ffffff', fontfamily: 'arial', fontsize: '28px', textalign: 'center', position: 'absolute', float: 'left', left: '-1000px', top: '20px', zindex: '100', filter: 'alpha(opacity:0.8)', opacity: '0.8', cursor: 'default' }); this.css(this.cb['loadingcanvas'], { transform: 'rotate(0deg)', mstransform: 'rotate(0deg)', moztransform: 'rotate(0deg)', webkittransform: 'rotate(0deg)', otransform: 'rotate(0deg)' }); //������ʾ�����ʽ this.css([promptbgid, promptid], { height: '30px', lineheight: '30px', color: '#ffffff', fontsize: '14px', textalign: 'center', position: 'absolute', borderradius: '5px', paddingleft: '5px', paddingright: '5px', bottom: '0px', display: 'none', zindex: '95' }); this.css(promptbgid, { backgroundcolor: '#000000', filter: 'alpha(opacity:0.5)', opacity: '0.5' }); //ʱ��������������� this.css(timeprogressbgid, { width: '100%', height: '6px', backgroundcolor: '#3f3f3f', overflow: 'hidden', position: 'absolute', bottom: '38px', zindex: '88' }); //���ؽ��ⱥ�ʱ����� this.css([loadprogressid, timeprogressid], { width: '1px', height: '6px', position: 'absolute', bottom: '38px', top: '0px', zindex: '91' }); this.css(loadprogressid, 'backgroundcolor', '#6f6f6f'); this.css(timeprogressid, 'backgroundcolor', bovercolor); //ʱ����ȱ�ť this.css(timebobgid, { width: '100%', height: '14px', overflow: 'hidden', position: 'absolute', bottom: '34px', cursor: 'pointer', zindex: '92' }); this.css(timeboid, { width: '14px', height: '14px', overflow: 'hidden', borderradius: '50%', backgroundcolor: bbgcolor, cursor: 'pointer', position: 'absolute', top: '0px', zindex: '20' }); this.css(timebwid, { width: '8px', height: '8px', overflow: 'hidden', borderradius: '50%', position: 'absolute', backgroundcolor: bovercolor, left: '3px', top: '3px' }); this.css(timetextid, { lineheight: bheight + 'px', color: '#ffffff', fontfamily: 'arial', fontsize: '16px', paddingleft: '10px', float: 'left', overflow: 'hidden', cursor: 'default' }); //�ָ��� this.css([dlineid + '-la', dlineid + '-lb', dlineid + '-lc', dlineid + '-ra', dlineid + '-rb', dlineid + '-rc'], { width: '0px', height: bheight + 'px', overflow: 'hidden', borderleft: '1px solid #303030', borderright: '1px solid #151515', filter: 'alpha(opacity:0.9)', opacity: '0.9' }); this.css([dlineid + '-la', dlineid + '-lb', dlineid + '-lc'], 'float', 'left'); this.css([dlineid + '-ra', dlineid + '-rb', dlineid + '-rc'], 'float', 'right'); this.css([dlineid + '-lb', dlineid + '-lc', dlineid + '-rb'], 'display', 'none'); //����/��ͣ/��һ��/��һ����ť this.css([playid, pauseid, frontid, nextid], { width: bwidth + 'px', height: bheight + 'px', float: 'left', overflow: 'hidden', cursor: 'pointer' }); this.css([frontid, nextid], 'display', 'none'); //��ʼ���жϲ���/��ͣ��ť������ this.initplaypause(); //���þ���/ȡ������i�ť��ʽ this.css([muteid, escmuteid], { width: bwidth + 'px', height: bheight + 'px', float: 'right', overflow: 'hidden', cursor: 'pointer' }); if(this.vars['volume'] > 0) { this.css(escmuteid, 'display', 'none'); } else { this.css(muteid, 'display', 'none'); } //�������ڿ� this.css([volumeid, volumedbgid], { width: '110px', height: bheight + 'px', overflow: 'hidden', float: 'right' }); this.css(volumedbgid, { position: 'absolute' }); this.css([volumebgid, volumeupid], { width: '100px', height: '6px', overflow: 'hidden', borderradius: '5px', cursor: 'pointer' }); this.css(volumebgid, { position: 'absolute', top: '16px' }); this.css(volumebgid, 'backgroundcolor', '#666666'); this.css(volumeupid, 'backgroundcolor', bovercolor); this.buttonwidth['volume'] = 100; //�������ڰ�ť this.css(volumeboid, { width: '12px', height: '12px', overflow: 'hidden', borderradius: '50%', position: 'absolute', backgroundcolor: bbgcolor, top: '13px', left: '0px', cursor: 'pointer' }); this.css(volumebwid, { width: '6px', height: '6px', overflow: 'hidden', borderradius: '50%', position: 'absolute', backgroundcolor: bovercolor, left: '3px', top: '3px' }); //���������� this.css(definitionid, { lineheight: bheight + 'px', color: '#ffffff', float: 'right', fontsize: '14px', textalign: 'center', overflow: 'hidden', display: 'none', cursor: 'pointer' }); this.css(definitionpid, { lineheight: (bheight - 8) + 'px', color: '#ffffff', overflow: 'hidden', position: 'absolute', bottom: '4px', backgroundcolor: '#000000', textalign: 'center', zindex: '95', cursor: 'pointer', display: 'none' }); //����ȫ��/�˳�ȫ����ť��ʽ this.css([fullid, escfullid], { width: bwidth + 'px', height: bheight + 'px', float: 'right', overflow: 'hidden', cursor: 'pointer' }); this.css(escfullid, 'display', 'none'); //��������ť����״ //���ű�ť var cplay = this.getbyelement(playid + '-canvas').getcontext('2d'); var cplayfillrect = function() { thistemp.canvasfill(cplay, [ [12, 10], [29, 19], [12, 28] ]); }; cplay.fillstyle = bbgcolor; cplayfillrect(); var cplayover = function(event) { cplay.clearrect(0, 0, bwidth, bheight); cplay.fillstyle = bovercolor; cplayfillrect(); }; var cplayout = function(event) { cplay.clearrect(0, 0, bwidth, bheight); cplay.fillstyle = bbgcolor; cplayfillrect(); }; this.addlistener('mouseover', cplayover, this.getbyelement(playid + '-canvas')); this.addlistener('mouseout', cplayout, this.getbyelement(playid + '-canvas')); //��ͣ��ť var cpause = this.getbyelement(pauseid + '-canvas').getcontext('2d'); var cpausefillrect = function() { thistemp.canvasfillrect(cpause, [ [10, 10, 5, 18], [22, 10, 5, 18] ]); }; cpause.fillstyle = bbgcolor; cpausefillrect(); var cpauseover = function(event) { cpause.clearrect(0, 0, bwidth, bheight); cpause.fillstyle = bovercolor; cpausefillrect(); }; var cpauseout = function(event) { cpause.clearrect(0, 0, bwidth, bheight); cpause.fillstyle = bbgcolor; cpausefillrect(); }; this.addlistener('mouseover', cpauseover, this.getbyelement(pauseid + '-canvas')); this.addlistener('mouseout', cpauseout, this.getbyelement(pauseid + '-canvas')); //ǰһ����ť var cfront = this.getbyelement(frontid + '-canvas').getcontext('2d'); var cfrontfillrect = function() { thistemp.canvasfill(cfront, [ [16, 19], [30, 10], [30, 28] ]); thistemp.canvasfillrect(cfront, [ [8, 10, 5, 18] ]); }; cfront.fillstyle = bbgcolor; cfrontfillrect(); var cfrontover = function(event) { cfront.clearrect(0, 0, bwidth, bheight); cfront.fillstyle = bovercolor; cfrontfillrect(); }; var cfrontout = function(event) { cfront.clearrect(0, 0, bwidth, bheight); cfront.fillstyle = bbgcolor; cfrontfillrect(); }; this.addlistener('mouseover', cfrontover, this.getbyelement(frontid + '-canvas')); this.addlistener('mouseout', cfrontout, this.getbyelement(frontid + '-canvas')); //��һ����ť var cnext = this.getbyelement(nextid + '-canvas').getcontext('2d'); var cnextfillrect = function() { thistemp.canvasfill(cnext, [ [8, 10], [22, 19], [8, 28] ]); thistemp.canvasfillrect(cnext, [ [25, 10, 5, 18] ]); }; cnext.fillstyle = bbgcolor; cnextfillrect(); var cnextover = function(event) { cnext.clearrect(0, 0, bwidth, bheight); cnext.fillstyle = bovercolor; cnextfillrect(); }; var cnextout = function(event) { cnext.clearrect(0, 0, bwidth, bheight); cnext.fillstyle = bbgcolor; cnextfillrect(); }; this.addlistener('mouseover', cnextover, this.getbyelement(nextid + '-canvas')); this.addlistener('mouseout', cnextout, this.getbyelement(nextid + '-canvas')); //ȫ����ť var cfull = this.getbyelement(fullid + '-canvas').getcontext('2d'); var cfullfillrect = function() { thistemp.canvasfillrect(cfull, [ [19, 10, 9, 3], [25, 13, 3, 6], [10, 19, 3, 9], [13, 25, 6, 3] ]); }; cfull.fillstyle = bbgcolor; cfullfillrect(); var cfullover = function() { cfull.clearrect(0, 0, bwidth, bheight); cfull.fillstyle = bovercolor; cfullfillrect(); }; var cfullout = function() { cfull.clearrect(0, 0, bwidth, bheight); cfull.fillstyle = bbgcolor; cfullfillrect(); }; this.addlistener('mouseover', cfullover, this.getbyelement(fullid + '-canvas')); this.addlistener('mouseout', cfullout, this.getbyelement(fullid + '-canvas')); //�����˳�ȫ����ť��ʽ var cescfull = this.getbyelement(escfullid + '-canvas').getcontext('2d'); var cescfullfillrect = function() { thistemp.canvasfillrect(cescfull, [ [20, 9, 3, 9], [23, 15, 6, 3], [9, 20, 9, 3], [15, 23, 3, 6] ]); }; cescfull.fillstyle = bbgcolor; cescfullfillrect(); var cescfullover = function() { cescfull.clearrect(0, 0, bwidth, bheight); cescfull.fillstyle = bovercolor; cescfullfillrect(); }; var cescfullout = function() { cescfull.clearrect(0, 0, bwidth, bheight); cescfull.fillstyle = bbgcolor; cescfullfillrect(); }; this.addlistener('mouseover', cescfullover, this.getbyelement(escfullid + '-canvas')); this.addlistener('mouseout', cescfullout, this.getbyelement(escfullid + '-canvas')); //����ȫ����ť����ʽ var cmute = this.getbyelement(muteid + '-canvas').getcontext('2d'); var cmutefillrect = function() { thistemp.canvasfill(cmute, [ [10, 15], [15, 15], [21, 10], [21, 28], [15, 23], [10, 23] ]); thistemp.canvasfillrect(cmute, [ [23, 15, 2, 8], [27, 10, 2, 18] ]); }; cmute.fillstyle = bbgcolor; cmutefillrect(); var cmuteover = function() { cmute.clearrect(0, 0, bwidth, bheight); cmute.fillstyle = bovercolor; cmutefillrect(); }; var cmuteout = function() { cmute.clearrect(0, 0, bwidth, bheight); cmute.fillstyle = bbgcolor; cmutefillrect(); }; this.addlistener('mouseover', cmuteover, this.getbyelement(muteid + '-canvas')); this.addlistener('mouseout', cmuteout, this.getbyelement(muteid + '-canvas')); //�����˳�ȫ����ť��ʽ var cescmute = this.getbyelement(escmuteid + '-canvas').getcontext('2d'); var cescmutefillrect = function() { thistemp.canvasfill(cescmute, [ [10, 15], [15, 15], [21, 10], [21, 28], [15, 23], [10, 23] ]); thistemp.canvasfill(cescmute, [ [23, 13], [24, 13], [33, 25], [32, 25] ]); thistemp.canvasfill(cescmute, [ [32, 13], [33, 13], [24, 25], [23, 25] ]); }; cescmute.fillstyle = bbgcolor; cescmutefillrect(); var cescmuteover = function() { cescmute.clearrect(0, 0, bwidth, bheight); cescmute.fillstyle = bovercolor; cescmutefillrect(); }; var cescmuteout = function() { cescmute.clearrect(0, 0, bwidth, bheight); cescmute.fillstyle = bbgcolor; cescmutefillrect(); }; this.addlistener('mouseover', cescmuteover, this.getbyelement(escmuteid + '-canvas')); this.addlistener('mouseout', cescmuteout, this.getbyelement(escmuteid + '-canvas')); //����loading��ʽ var cloading = this.getbyelement(loadingid + '-canvas').getcontext('2d'); var cloadingfillrect = function() { cloading.save(); var grad = cloading.createlineargradient(0, 0, 60, 60); grad.addcolorstop(0, bbgcolor); var grad2 = cloading.createlineargradient(0, 0, 80, 60); grad2.addcolorstop(1, bovercolor); cloading.strokestyle = grad; //���������ʽ cloading.linewidth = 8; //�����߿� cloading.beginpath(); //·����ʼ cloading.arc(30, 30, 25, 0.25 * math.pi, 2 * math.pi, false); //���ڻ���բ��context.arc(x���꣬y���꣬�뾶����ʼ�ƕȣ���ֹ�ƕȣ�˳ʱ��/��ʱ��) cloading.stroke(); //���� cloading.closepath(); //·������ cloading.beginpath(); //·����ʼ cloading.strokestyle = grad2; //���������ʽ cloading.arc(30, 30, 25, 0, 0.25 * math.pi, false); //���ڻ���բ��context.arc(x���꣬y���꣬�뾶����ʼ�ƕȣ���ֹ�ƕȣ�˳ʱ��/��ʱ��) cloading.stroke(); //���� cloading.closepath(); //·������ cloading.restore(); }; cloading.fillstyle = bbgcolor; cloadingfillrect(); //�����м���ͣ��ť����ʽ var cpausecenter = this.getbyelement(pausecenterid + '-canvas').getcontext('2d'); var cpausecenterfillrect = function() { thistemp.canvasfill(cpausecenter, [ [28, 22], [59, 38], [28, 58] ]); /* ָ��������ɫ */ cpausecenter.save(); cpausecenter.linewidth = 5; //�����߿� cpausecenter.beginpath(); //·����ʼ cpausecenter.arc(40, 40, 35, 0, 2 * math.pi, false); //���ڻ���բ��context.arc(x���꣬y���꣬�뾶����ʼ�ƕȣ���ֹ�ƕȣ�˳ʱ��/��ʱ��) cpausecenter.stroke(); //���� cpausecenter.closepath(); //·������ cpausecenter.restore(); }; cpausecenter.fillstyle = bbgcolor; cpausecenter.strokestyle = bbgcolor; cpausecenterfillrect(); var cpausecenterover = function() { cpausecenter.clearrect(0, 0, 80, 80); cpausecenter.fillstyle = bovercolor; cpausecenter.strokestyle = bovercolor; cpausecenterfillrect(); }; var cpausecenterout = function() { cpausecenter.clearrect(0, 0, 80, 80); cpausecenter.fillstyle = bbgcolor; cpausecenter.strokestyle = bbgcolor; cpausecenterfillrect(); }; this.addlistener('mouseover', cpausecenterover, this.getbyelement(pausecenterid + '-canvas')); this.addlistener('mouseout', cpausecenterout, this.getbyelement(pausecenterid + '-canvas')); //��꾭��/�뿪�������ڰ�ť var volumeboover = function() { thistemp.css(volumeboid, 'backgroundcolor', bovercolor); thistemp.css(volumebwid, 'backgroundcolor', bbgcolor); }; var volumeboout = function() { thistemp.css(volumeboid, 'backgroundcolor', bbgcolor); thistemp.css(volumebwid, 'backgroundcolor', bovercolor); }; this.addlistener('mouseover', volumeboover, this.getbyelement(volumeboid)); this.addlistener('mouseout', volumeboout, this.getbyelement(volumeboid)); //��꾭��/�뿪���ȱ�ť var timeboover = function() { thistemp.css(timeboid, 'backgroundcolor', bovercolor); thistemp.css(timebwid, 'backgroundcolor', bbgcolor); }; var timeboout = function() { thistemp.css(timeboid, 'backgroundcolor', bbgcolor); thistemp.css(timebwid, 'backgroundcolor', bovercolor); }; this.addlistener('mouseover', timeboover, this.getbyelement(timeboid)); this.addlistener('mouseout', timeboout, this.getbyelement(timeboid)); this.addbuttonevent(); //ע�ᰴť���������ڣ����ȳ����¼� this.newmenu(); //���������ҽ�����ʽ���¼� this.controlbarhide(); //����ע������������¼� this.keypress(); //����ע������¼� //��ʼ���������ڿ� this.changevolume(this.vars['volume']); //��ʼ���ж��ƿ���ҫ��ʾ��һ������һ����ť this.showfrontnext(); window.settimeout(function() { thistemp.elementcoordinate(); //�����м���ͣ��ť/loading��λ��/error��λ�� }, 100); this.checkbarwidth(); var resize = function() { thistemp.elementcoordinate(); thistemp.timeupdatehandler(); thistemp.changeload(); thistemp.checkbarwidth(); thistemp.changeelementcoor(); //�޸��¼�Ԫ�������� thistemp.changeprompt(); }; this.addlistener('resize', resize, window); }, /* �ڲ����� ������ť��ʹ��canvas���� */ newcanvas: function(id, width, height) { return ''; }, /* �ڲ����� ע�ᰴť���������ڿ򣬽��ȳ������¼� */ addbuttonevent: function() { var thistemp = this; //���尴ť�ĵ����¼� var playclick = function(event) { thistemp.play(); }; this.addlistener('click', playclick, this.cb['play']); this.addlistener('click', playclick, this.cb['pausecenter']); var pauseclick = function(event) { thistemp.pause(); }; this.addlistener('click', pauseclick, this.cb['pause']); var frontclick = function(event) { if(thistemp.vars['front']) { eval(thistemp.vars['front'] + '()'); } }; this.addlistener('click', frontclick, this.cb['front']); var nextclick = function(event) { if(thistemp.vars['next']) { eval(thistemp.vars['next'] + '()'); } }; this.addlistener('click', nextclick, this.cb['next']); var muteclick = function(event) { thistemp.changevolumetemp = thistemp.v ? (thistemp.v.volume > 0 ? thistemp.v.volume : thistemp.vars['volume']) : thistemp.vars['volume']; thistemp.changevolume(0); }; this.addlistener('click', muteclick, this.cb['mute']); var escmuteclick = function(event) { thistemp.changevolume(thistemp.changevolumetemp > 0 ? thistemp.changevolumetemp : thistemp.vars['volume']); }; this.addlistener('click', escmuteclick, this.cb['escmute']); var fullclick = function(event) { thistemp.fullscreen(); }; this.addlistener('click', fullclick, this.cb['full']); var escfullclick = function(event) { thistemp.quitfullscreen(); }; this.addlistener('click', escfullclick, this.cb['escfull']); //���������ť����꾭��/�뿪�¼� var prompthide = function(event) { thistemp.promptshow(false); }; var playover = function(event) { thistemp.promptshow(thistemp.cb['play']); }; this.addlistener('mouseover', playover, this.cb['play']); this.addlistener('mouseout', prompthide, this.cb['play']); var pauseover = function(event) { thistemp.promptshow(thistemp.cb['pause']); }; this.addlistener('mouseover', pauseover, this.cb['pause']); this.addlistener('mouseout', prompthide, this.cb['pause']); var frontover = function(event) { thistemp.promptshow(thistemp.cb['front']); }; this.addlistener('mouseover', frontover, this.cb['front']); this.addlistener('mouseout', prompthide, this.cb['front']); var nextover = function(event) { thistemp.promptshow(thistemp.cb['next']); }; this.addlistener('mouseover', nextover, this.cb['next']); this.addlistener('mouseout', prompthide, this.cb['next']); var muteover = function(event) { thistemp.promptshow(thistemp.cb['mute']); }; this.addlistener('mouseover', muteover, this.cb['mute']); this.addlistener('mouseout', prompthide, this.cb['mute']); var escmuteover = function(event) { thistemp.promptshow(thistemp.cb['escmute']); }; this.addlistener('mouseover', escmuteover, this.cb['escmute']); this.addlistener('mouseout', prompthide, this.cb['escmute']); var fullover = function(event) { thistemp.promptshow(thistemp.cb['full']); }; this.addlistener('mouseover', fullover, this.cb['full']); this.addlistener('mouseout', prompthide, this.cb['full']); var escfullover = function(event) { thistemp.promptshow(thistemp.cb['escfull']); }; this.addlistener('mouseover', escfullover, this.cb['escfull']); this.addlistener('mouseout', prompthide, this.cb['escfull']); var definitionover = function(event) { thistemp.promptshow(thistemp.cb['definition']); }; this.addlistener('mouseover', definitionover, this.cb['definition']); this.addlistener('mouseout', prompthide, this.cb['definition']); //���������ͽ��ȱ�ť�ļ����¼� var volumeprompt = function(vol) { var volumeboxy = thistemp.getcoor(thistemp.cb['volumebo']); var promptobj = { title: thistemp.language['volume'] + vol + '%', x: volumeboxy['x'] + thistemp.cb['volumebo'].offsetwidth * 0.5, y: volumeboxy['y'] }; thistemp.promptshow(false, promptobj); }; var volumeobj = { slider: this.cb['volumebo'], follow: this.cb['volumeup'], refer: this.cb['volumebg'], grossvalue: 'volume', pd: true, startfun: function(vol) {}, monitorfun: function(vol) { thistemp.changevolume(vol * 0.01, false, false); volumeprompt(vol); }, endfun: function(vol) {}, overfun: function(vol) { volumeprompt(vol); } }; this.slider(volumeobj); var volumeclickobj = { refer: this.cb['volumebg'], grossvalue: 'volume', fun: function(vol) { thistemp.changevolume(vol * 0.01, true, true); } }; this.progressclick(volumeclickobj); this.timebuttonmousedown(); //�õ����ĺ������ж��ƿ���ҫ�������������� //��꾭��/�뿪�������ڿ�ʱ�� var volumebgmove = function(event) { var volumebgxy = thistemp.getcoor(thistemp.cb['volumebg']); var eventx = thistemp.client(event)['x']; var eventvolume = parseint((eventx -volumebgxy['x']) * 100 / thistemp.cb['volumebg'].offsetwidth); var buttonpromptobj = { title: thistemp.language['volume'] + eventvolume + '%', x: eventx, y: volumebgxy['y'] }; thistemp.promptshow(false, buttonpromptobj); }; this.addlistener('mousemove', volumebgmove, this.cb['volumebg']); this.addlistener('mouseout', prompthide, this.cb['volumebg']); this.addlistener('mouseout', prompthide, this.cb['volumebo']); //ע������������¼� this.adddeflistener(); }, /* �ڲ����� ע�ᵥ����ƶ���� */ videoclick: function() { var thistemp = this; var cleartimerclick = function() { if(thistemp.timerclick != null) { if(thistemp.timerclick.runing) { thistemp.timerclick.stop(); } thistemp.timerclick = null; } }; var timerclickfun = function() { cleartimerclick(); thistemp.isclick = false; thistemp.playorpause(); }; cleartimerclick(); if(this.isclick) { this.isclick = false; if(thistemp.config['videodbclick']) { if(!this.full) { thistemp.fullscreen(); } else { thistemp.quitfullscreen(); } } } else { this.isclick = true; this.timerclick = new this.timer(300, timerclickfun, 1) //this.timerclick.start(); } }, /* �ڲ����� ע����꾭�����ȼ�����¼� */ timebuttonmousedown: function() { var thistemp = this; var timeprompt = function(time) { if(isnan(time)) { time = 0; } var timebuttonxy = thistemp.getcoor(thistemp.cb['timebutton']); var promptobj = { title: thistemp.formattime(time), x: timebuttonxy['x'] - thistemp.pdcoor['x'] + thistemp.cb['timebutton'].offsetwidth * 0.5, y: timebuttonxy['y'] - thistemp.pdcoor['y'] }; thistemp.promptshow(false, promptobj); }; var timeobj = { slider: this.cb['timebutton'], follow: this.cb['timeprogress'], refer: this.cb['timebobg'], grossvalue: 'time', pd: false, startfun: function(time) { thistemp.istimebuttonmove = false; }, monitorfun: function(time) {}, endfun: function(time) { if(thistemp.v) { if(thistemp.v.duration > 0) { thistemp.needseek = 0; thistemp.seek(parseint(time)); } } }, overfun: function(time) { timeprompt(time); }, }; var timeclickobj = { refer: this.cb['timebobg'], grossvalue: 'time', fun: function(time) { if(thistemp.v) { if(thistemp.v.duration > 0) { thistemp.needseek = 0; thistemp.seek(parseint(time)); } } }, }; var timebobgmousemove = function(event) { var timebobgxy = thistemp.getcoor(thistemp.cb['timebobg']); var eventx = thistemp.client(event)['x']; var eventtime = parseint((eventx - timebobgxy['x']) * thistemp.v.duration / thistemp.cb['timebobg'].offsetwidth); var buttonpromptobj = { title: thistemp.formattime(eventtime), x: eventx, y: timebobgxy['y'] }; thistemp.promptshow(false, buttonpromptobj); var def = false; if(!thistemp.isundefined(thistemp.cb['definitionp'])) { if(thistemp.css(thistemp.cb['definitionp'], 'display') != 'block') { def = true; } } if(thistemp.vars['preview'] != null && def) { buttonpromptobj['time'] = eventtime; thistemp.preview(buttonpromptobj); } }; var prompthide = function(event) { thistemp.promptshow(false); if(thistemp.previewdiv != null) { thistemp.css([thistemp.previewdiv, thistemp.previewtop], 'display', 'none'); } }; if(!this.vars['live']) { //�������ֱ�� this.istimebuttondown = true; this.addlistener('mousemove', timebobgmousemove, this.cb['timebobg']); this.addlistener('mouseout', prompthide, this.cb['timebobg']); } else { this.istimebuttondown = false; timeobj['removelistener'] = true; timeclickobj['removelistener'] = true; } this.slider(timeobj); this.progressclick(timeclickobj); }, /* �ڲ����� ע����ڿ��ϵ����¼��������������ڿ�ͳ���ʱ�ȵ��ڿ� */ progressclick: function(obj) { /* refer:�ο����� fun:���غ��� refer:�ο�Ԫ�أ������� grossvalue:���õijο�ֵ���� pd: */ //�����ο�Ԫ�ص�mouseclick�¼���������ϊ��������ϰ���ʱ������״̬ var thistemp = this; var refermouseclick = function(event) { var referx = thistemp.client(event)['x']-thistemp.getcoor(obj['refer'])['x']; var rwidth = obj['refer'].offsetwidth; var grossvalue = 0; if(obj['grossvalue'] == 'volume') { grossvalue = 100; } else { if(thistemp.v) { grossvalue = thistemp.v.duration; } } var nowz = parseint(referx * grossvalue / rwidth); if(obj['fun']) { obj['fun'](nowz); } }; if(this.isundefined(obj['removelistener'])) { this.addlistener('click', refermouseclick, obj['refer']); } else { this.removelistener('click', refermouseclick, obj['refer']); } }, /* �ڲ����� ���õ�ע�ử���¼� */ slider: function(obj) { /* obj={ slider:����Ԫ�� follow:���滬���Ԫ�� refer:�ο�Ԫ�أ������� grossvalue:���õijο�ֵ���� startfun:��ʼ���õ�Ԫ�� monitorfun:�������� endfun:�������õĺ��� overfun:������ȥ����õĺ��� pd:�ƿ���ҫ���� } */ var thistemp = this; var clientx = 0, criterionwidth = 0, sliderleft = 0, referleft = 0; var value = 0; var calculation = function() { //���ݻ����left����ٷֱ� var sleft = parseint(thistemp.css(obj['slider'], 'left')); var rwidth = obj['refer'].offsetwidth - obj['slider'].offsetwidth; var grossvalue = 0; if(thistemp.isundefined(sleft) || isnan(sleft)) { sleft = 0; } if(obj['grossvalue'] == 'volume') { grossvalue = 100; } else { if(thistemp.v) { grossvalue = thistemp.v.duration; } } return parseint(sleft * grossvalue / rwidth); }; var mdown = function(event) { thistemp.addlistener('mousemove', mmove, document); thistemp.addlistener('mouseup', mup, document); var referxy = thistemp.getcoor(obj['refer']); var sliderxy = thistemp.getcoor(obj['slider']); clientx = thistemp.client(event)['x']; referleft = referxy['x']; sliderleft = sliderxy['x']; criterionwidth = clientx - sliderleft; if(obj['startfun']) { obj['startfun'](calculation()); } }; var mmove = function(event) { clientx = thistemp.client(event)['x']; var newx = clientx - criterionwidth - referleft; if(newx < 0) { newx = 0; } if(newx > obj['refer'].offsetwidth - obj['slider'].offsetwidth) { newx = obj['refer'].offsetwidth - obj['slider'].offsetwidth; } thistemp.css(obj['slider'], 'left', newx + 'px'); thistemp.css(obj['follow'], 'width', (newx + obj['slider'].offsetwidth * 0.5) + 'px'); var nowz = calculation(); if(obj['monitorfun']) { obj['monitorfun'](nowz); } }; var mup = function(event) { thistemp.removelistener('mousemove', mmove, document); thistemp.removelistener('mouseup', mup, document); if(obj['endfun']) { obj['endfun'](calculation()); } }; var mover = function(event) { if(obj['overfun']) { obj['overfun'](calculation()); } }; if(this.isundefined(obj['removelistener'])) { this.addlistener('mousedown', mdown, obj['slider']); this.addlistener('mouseover', mover, obj['slider']); } else { this.removelistener('mousedown', mdown, obj['slider']); this.removelistener('mouseover', mover, obj['slider']); } }, /* �ڲ����� ��ʾloading */ loadingstart: function(rot) { var thistemp = this; if(this.isundefined(rot)) { rot = true; } this.css(thistemp.cb['loading'], 'display', 'none'); if(this.timerloading != null) { if(this.timerloading.runing) { this.timerloading.stop(); } this.timerloading = null; } var loadingfun = function() { var nowrotate = '0'; try { nowrotate = thistemp.css(thistemp.cb['loadingcanvas'], 'transform') || thistemp.css(thistemp.cb['loadingcanvas'], '-ms-transform') || thistemp.css(thistemp.cb['loadingcanvas'], '-moz-transform') || thistemp.css(thistemp.cb['loadingcanvas'], '-webkit-transform') || thistemp.css(thistemp.cb['loadingcanvas'], '-o-transform') || '0'; } catch(event) {} nowrotate = parseint(nowrotate.replace('rotate(', '').replace('deg);', '')); nowrotate += 4; if(nowrotate > 360) { nowrotate = 0; } thistemp.css(thistemp.cb['loadingcanvas'], { transform: 'rotate(' + nowrotate + 'deg)', mstransform: 'rotate(' + nowrotate + 'deg)', moztransform: 'rotate(' + nowrotate + 'deg)', webkittransform: 'rotate(' + nowrotate + 'deg)', otransform: 'rotate(' + nowrotate + 'deg)' }); }; if(rot) { this.timerloading = new this.timer(10, loadingfun); //this.timerloading.start(); this.css(thistemp.cb['loading'], 'display', 'block'); } }, /* �ڲ����� �ж��ƿ���ҫ��ʾ��һ������һ�� */ showfrontnext: function() { if(this.vars['front']) { this.css([this.cb['front'], this.cb['frontline']], 'display', 'block'); } else { this.css([this.cb['front'], this.cb['frontline']], 'display', 'none'); } if(this.vars['next']) { this.css([this.cb['next'], this.cb['nextline']], 'display', 'block'); } else { this.css([this.cb['next'], this.cb['nextline']], 'display', 'none'); } }, /* �ڲ����� ��ʾ��ʾ�� */ promptshow: function(ele, data) { var obj = {}; if(ele || data) { if(!this.isundefined(data)) { obj = data; } else { var offsetcoor = this.getcoor(ele); obj = { title: ele.dataset.title, x: offsetcoor['x'] + ele.offsetwidth * 0.5, y: offsetcoor['y'] }; } this.cb['prompt'].innerhtml = obj['title']; this.css(this.cb['prompt'], 'display', 'block'); var promoptwidth = this.getstringlen(obj['title']) * 10; this.css(this.cb['promptbg'], 'width', promoptwidth + 'px'); this.css(this.cb['prompt'], 'width', promoptwidth + 'px'); promoptwidth += 10; var x = obj['x'] - (promoptwidth * 0.5); var y = this.pd.offsetheight - obj['y'] + 8; if(x < 0) { x = 0; } if(x > this.pd.offsetwidth - promoptwidth) { x = this.pd.offsetwidth - promoptwidth; } this.css([this.cb['promptbg'], this.cb['prompt']], { display: 'block', left: x + 'px', bottom: y + 'px' }); } else { this.css([this.cb['promptbg'], this.cb['prompt']], { display: 'none' }); } }, /* �ڲ����� �������� */ timererrorfun: function() { var thistemp = this; var clearintervalerror = function(event) { if(thistemp.timererror != null) { if(thistemp.timererror.runing) { thistemp.timererror.stop(); } thistemp.timererror = null; } }; var errorfun = function(event) { clearintervalerror(); thistemp.error = true; //��ȡ���󲥷ŵ�ַ thistemp.errorurl = thistemp.getvideourl(); //��ȡ���󲥷ŵ�ַ���� thistemp.addlistenererror(); thistemp.css(thistemp.cb['errortext'], 'display', 'block'); thistemp.css(thistemp.cb['pausecenter'], 'display', 'none'); thistemp.css(thistemp.cb['loading'], 'display', 'none'); thistemp.v.removeattribute('poster'); thistemp.resetplayer(); }; var errorlistenerfun = function(event) { window.settimeout(function() { if(isnan(thistemp.v.duration)) { errorfun(event); } }, 500); }; this.addlistener('error', errorlistenerfun, this.v); clearintervalerror(); var timererrorfun = function() { if(thistemp.v && parseint(thistemp.v.networkstate) == 3) { errorfun(); } }; this.timererror = new this.timer(this.config['errortime'], timererrorfun); //this.timererror.start(); }, /* �ڲ����� �����ж�ȫ�����ƿ�ȫ�����ж� */ judgefullscreen: function() { var thistemp = this; if(this.timerfull != null) { if(this.timerfull.runing) { this.timerfull.stop(); } this.timerfull = null; } var fullfun = function() { thistemp.isfullscreen(); }; this.timerfull = new this.timer(20, fullfun); //this.timerfull.start(); }, /* �ڲ����� �ж��ƿ���ȫ�� */ isfullscreen: function() { var controlbarbgw = this.cb['controlbarbg'].offsetwidth; var containerw = this.cd.offsetwidth; if(controlbarbgw != containerw && !this.full) { this.full = true; this.addlistenerfull(); this.elementcoordinate(); this.css(this.cb['full'], 'display', 'none'); this.css(this.cb['escfull'], 'display', 'block'); if(this.vars['live'] == 0) { this.timeupdatehandler(); } this.pd.appendchild(this.cb['menu']); } if(controlbarbgw == containerw && this.full) { this.full = false; this.addlistenerfull(); this.elementcoordinate(); this.css(this.cb['full'], 'display', 'block'); this.css(this.cb['escfull'], 'display', 'none'); if(this.timerfull != null) { if(this.timerfull.runing) { this.timerfull.stop(); } this.timerfull = null; } if(this.vars['live'] == 0) { this.timeupdatehandler(); } this.body.appendchild(this.cb['menu']); } }, /* �ڲ����� �����ҽ����ݼ�ע����ض����¼� */ newmenu: function() { var thistemp = this; var i = 0; this.css(this.cb['menu'], { backgroundcolor: '#ffffff', padding: '5px', position: 'absolute', left: '10px', top: '20px', display: 'none', zindex: '999', color: '#a1a9be', boxshadow: '2px 2px 3px #aaaaaa' }); var marr = this.contextmenu; var html = ''; for(i = 0; i < marr.length; i++) { var me = marr[i]; switch(me[1]) { case 'default': html += '

' + me[0] + '

'; break; case 'link': html += '

' + me[0] + '

'; break; case 'javascript': html += '

' + me[0] + '

'; break; case 'function': html += '

' + me[0] + '

'; break; default: break; } } this.cb['menu'].innerhtml = html; var parr = this.cb['menu'].childnodes; for(i = 0; i < parr.length; i++) { this.css(parr[i], { height: '30px', lineheight: '30px', margin: '0px', fontfamily: '"microsoft yahei", yahei, "΢���ź�", simhei,"\5fae\8f6f\96c5\9ed1", "����",arial', fontsize: '12px', paddingleft: '10px', paddingright: '30px' }); if(marr[i].length >= 4) { if(marr[i][3] == 'line') { this.css(parr[i], 'bordertop', '1px solid #e9e9e9'); } } var aarr = parr[i].childnodes; for(var n = 0; n < aarr.length; n++) { if(aarr[n].localname == 'a') { this.css(aarr[n], { color: '#000000', textdecoration: 'none' }); } } } this.pd.oncontextmenu = function(event) { var eve = event || window.event; var client = thistemp.client(event); if(eve.button == 2) { eve.returnvalue = false; var x = client['x'] + thistemp.pdcoor['x'] - 2; var y = client['y'] + thistemp.pdcoor['y'] - 2; thistemp.css(thistemp.cb['menu'], { display: 'block', left: x + 'px', top: y + 'px' }); return false; } return true; }; var settimeoutpclose = function() { if(settimeoutp) { window.cleartimeout(settimeoutp); settimeoutp = null; } }; var settimeoutp = null; var mouseout = function(event) { settimeoutpclose(); settimeoutp = window.settimeout(function(event) { thistemp.css(thistemp.cb['menu'], 'display', 'none'); }, 500); }; this.addlistener('mouseout', mouseout, thistemp.cb['menu']); var mouseover = function(event) { settimeoutpclose(); }; this.addlistener('mouseover', mouseover, thistemp.cb['menu']); }, /* �ڲ����� ���������������¼� */ controlbarhide: function() { var thistemp = this; var client = { x: 0, y: 0 }, oldclient = { x: 0, y: 0 }; var cshow = true; var oldcoor = [0, 0]; var controlbarshow = function(show) { if(show && !cshow) { cshow = true; thistemp.css(thistemp.cb['controlbarbg'], 'display', 'block'); thistemp.css(thistemp.cb['controlbar'], 'display', 'block'); thistemp.css(thistemp.cb['timeprogressbg'], 'display', 'block'); thistemp.css(thistemp.cb['timebobg'], 'display', 'block'); } else { if(cshow) { cshow = false; var paused = thistemp.getmetadate()['paused']; if(!paused) { thistemp.css(thistemp.cb['controlbarbg'], 'display', 'none'); thistemp.css(thistemp.cb['controlbar'], 'display', 'none'); thistemp.css(thistemp.cb['timeprogressbg'], 'display', 'none'); thistemp.css(thistemp.cb['timebobg'], 'display', 'none'); thistemp.promptshow(false); } } } }; var cbarfun = function(event) { if(client['x'] == oldclient['x'] && client['y'] == oldclient['y']) { var cdh = parseint(thistemp.cd.offsetheight); if((client['y'] < cdh - 50 || client['y'] > cdh - 2) && cshow) { controlbarshow(false); } } else { if(!cshow) { controlbarshow(true); } } oldclient = { x: client['x'], y: client['y'] } }; this.timercbar = new this.timer(2000, cbarfun); var cdmove = function(event) { var getclient = thistemp.client(event); client['x'] = getclient['x']; client['y'] = getclient['y']; if(!cshow) { controlbarshow(true); } }; this.addlistener('mousemove', cdmove, thistemp.cd); this.addlistener('ended', cdmove); this.addlistener('resize', cdmove, window); }, /* �ڲ����� ע����̰����¼� */ keypress: function() { var thistemp = this; var keydown = function(eve) { var keycode = eve.keycode || eve.which; var now = 0; switch(keycode) { case 32: thistemp.playorpause(); break; case 37: now = thistemp.time - 10; thistemp.seek(now < 0 ? 0 : now); break; case 39: now = thistemp.time + 10; thistemp.seek(now); break; case 38: now = thistemp.volume + 0.1; thistemp.changevolume(now > 1 ? 1 : now); break; case 40: now = thistemp.volume - 0.1; thistemp.changevolume(now < 0 ? 0 : now); break; default: break; } }; this.addlistener('keydown', keydown, window || document); }, /* �ڲ����� ���������ȱ�ť���л��¼�(click�¼�) */ definition: function() { var thistemp = this; var varr = this.va; var darr = []; var html = ''; var nowd = ''; //��ǰ�������� var i = 0; for(i = 0; i < varr.length; i++) { var d = varr[i][2]; if(darr.indexof(d) == -1) { darr.push(d); } if(this.v) { if(varr[i][0] == this.v.currentsrc) { nowd = d; } } } if(!nowd) { nowd = darr[0]; } if(darr.length > 1) { var zlen = 0; for(i = 0; i < darr.length; i++) { html = '

' + darr[i] + '

' + html; var dlen = this.getstringlen(darr[i]); if(dlen > zlen) { zlen = dlen; } } if(html) { html += '

' + nowd + '

'; } this.cb['definition'].innerhtml = nowd; this.cb['definitionp'].innerhtml = html; this.css([this.cb['definition'], this.cb['definitionline']], 'display', 'block'); var parr = this.cb['definitionp'].childnodes; for(var i = 0; i < parr.length; i++) { var fontcolor = '#ffffff'; if(parr[i].innerhtml == nowd) { fontcolor = '#0782f5'; } this.css(parr[i], { color: fontcolor, margin: '0px', padding: '0px', fontsize: '14px' }); if(i < parr.length - 1) { this.css(parr[i], 'borderbottom', '1px solid #282828') } var defclick = function() { if(nowd != this.innerhtml) { thistemp.css(thistemp.cb['definitionp'], 'display', 'none'); thistemp.newdefinition(this.innerhtml); } }; this.addlistener('click', defclick, parr[i]); } var pw = (zlen * 10) + 20; this.css(this.cb['definitionp'], { width: pw + 'px' }); this.css(this.cb['definition'], { width: pw + 'px', }); this.buttonwidth['definition'] = this.cb['definition'].offsetwidth; } else { this.cb['definition'].innerhtml = ''; this.cb['definitionp'].innerhtml = ''; this.css([this.cb['definition'], this.cb['definitionline']], 'display', 'none'); } }, /* �ڲ����� ע������������¼� */ adddeflistener: function() { var thistemp = this; var settimeoutp = null; var defclick = function(event) { thistemp.css(thistemp.cb['definitionp'], { left: thistemp.getcoor(thistemp.cb['definition'])['x'] + 'px', display: 'block' }); }; this.addlistener('click', defclick, this.cb['definition']); var defmouseout = function(event) { if(settimeoutp) { window.cleartimeout(settimeoutp); settimeoutp = null; } settimeoutp = window.settimeout(function(event) { thistemp.css(thistemp.cb['definitionp'], 'display', 'none'); }, 500); }; this.addlistener('mouseout', defmouseout, thistemp.cb['definitionp']); var defmouseover = function(event) { if(settimeoutp) { window.cleartimeout(settimeoutp); settimeoutp = null; } }; this.addlistener('mouseover', defmouseover, thistemp.cb['definitionp']); }, /* �ڲ����� �л������ⱥ����ķ��� */ newdefinition: function(title) { var varr = this.va; var nvarr = []; var i = 0; for(i = 0; i < varr.length; i++) { var v = varr[i]; if(v[2] == title) { nvarr.push(v); } } if(nvarr.length < 1) { return; } if(this.v != null && this.needseek == 0) { this.needseek = this.v.currenttime; } if(this.getfileext(nvarr[0][0]) != '.m3u8') { this.ism3u8 = false; } if(!this.ism3u8) { if(nvarr.length == 1) { this.v.innerhtml = ''; this.v.src = nvarr[0][0]; } else { var source = ''; nvarr = this.arrsort(nvarr); for(i = 0; i < nvarr.length; i++) { var type = ''; var va = nvarr[i]; if(va[1]) { type = ' type="' + va[1] + '"'; } source += ''; } this.v.removeattribute('src'); this.v.innerhtml = source; } } else { this.embedhls(varr[0][0], this.vars['autoplay']); } this.v.autoplay = 'autoplay'; this.v.load(); this.timererrorfun(); this.addlistenervideochange(); }, /* ���ú��� ����hls */ embedhls: function(url, autoplay) { var thistemp = this; if(hls.issupported()) { var hls = new hls(); hls.loadsource(url); hls.attachmedia(this.v); hls.on(hls.events.manifest_parsed, function() { thistemp.playerload(); if(autoplay) { thistemp.play(); } }); } }, /* �ڲ����� ������ʾ�� */ prompt: function() { var thistemp = this; var prompt = this.vars['prompt']; if(prompt == null || this.promptarr.length > 0) { return; } var showprompt = function(event) { if(thistemp.promptelement == null) { var random2 = 'prompte' + thistemp.randomstring(5); var ele2 = document.createelement('div'); ele2.classname = random2; thistemp.pd.appendchild(ele2); thistemp.promptelement = thistemp.getbyelement(random2); thistemp.css(thistemp.promptelement, { overflowx: 'hidden', lineheight: '22px', fontsize: '14px', color: '#ffffff', position: 'absolute', display: 'block', zindex: '90' }); } var pcon = thistemp.getprompttest(); var pw = pcon['pw'], pt = pcon['pt'], pl = parseint(thistemp.css(this, 'left')) - parseint(pw * 0.5); if(pcon['pl'] > 10) { pl = pcon['pl']; } if(pl < 0) { pl = 0; } thistemp.css(thistemp.promptelement, { width: pw + 'px', left: (-pw - 10) + 'px', display: 'block' }); thistemp.promptelement.innerhtml = this.dataset.words; thistemp.css(thistemp.promptelement, { left: pl + 'px', top: (pt - thistemp.promptelement.offsetheight) + 'px' }); }; var hideprompt = function(event) { if(thistemp.promptelement != null) { thistemp.css(thistemp.promptelement, { display: 'none' }); } }; var i = 0; for(i = 0; i < prompt.length; i++) { var pr = prompt[i]; var words = pr['words']; var time = pr['time']; var random = 'prompt' + this.randomstring(5); var ele = document.createelement('div'); ele.classname = random; this.cb['timebobg'].appendchild(ele); var div = this.getbyelement(random); div.setattribute('data-time', time); div.setattribute('data-words', words); this.css(div, { width: '6px', height: '6px', backgroundcolor: '#ffffff', position: 'absolute', top: '4px', left: '-100px', display: 'none', zindex: '1' }); this.addlistener('mouseover', showprompt, div); this.addlistener('mouseout', hideprompt, div); this.promptarr.push(div); } this.changeprompt(); }, /* �ڲ����� ������ʾ�ı���λ�� */ getprompttest: function() { var pw = this.previewwidth, pt = this.getcoor(this.cb['timebutton'])['y'], pl = 0; if(this.previewtop != null) { pt -= parseint(this.css(this.previewtop, 'height')); pl = parseint(this.css(this.previewtop, 'left')); } else { pt -= 35; } pl += 2; if(pl < 0) { pl = 0; } if(pl > this.pd.offsetwidth - pw) { pl = this.pd.offsetwidth - pw; } return { pw: pw, pt: pt, pl: pl }; }, /* �ڲ����� ɾ����ʾ�� */ deleteprompt: function() { var arr = this.promptarr; if(arr.length > 0) { for(var i = 0; i < arr.length; i++) { if(arr[i]) { this.deletechild(arr[i]); } } } this.promptarr = []; }, /* �ڲ����� ������ʾ������ */ changeprompt: function() { if(this.promptarr.length == 0) { return; } var arr = this.promptarr; var duration = this.getmetadate()['duration']; var bw = this.cb['timebobg'].offsetwidth; for(var i = 0; i < arr.length; i++) { var time = parseint(arr[i].dataset.time); var left = parseint(time * bw / duration) - parseint(arr[i].offsetwidth * 0.5); if(left < 0) { left = 0; } if(left > bw - parseint(arr[i].offsetwidth * 0.5)) { left = bw - parseint(arr[i].offsetwidth * 0.5); } this.css(arr[i], { left: left + 'px', display: 'block' }); } }, /* �ڲ����� ����Ԥ��ͼƭч�� */ preview: function(obj) { var thistemp = this; var preview = { src: null, scale: 0 }; preview = this.standardization(preview, this.vars['preview']); if(preview['src'] == null || preview['scale'] <= 0) { return; } var srcarr = preview['src']; if(this.previewstart == 0) { //�����û�й��������ƚ��й��� this.previewstart = 1; if(srcarr.length > 0) { var i = 0; var imgw = 0, imgh = 0; var random = thistemp.randomstring(10); var loadnum = 0; var loadimg = function(i) { srcarr[i] = thistemp.getnewurl(srcarr[i]); var n = 0; var img = new image(); img.src = srcarr[i]; img.classname = random + i; img.onload = function(event) { loadnum++; if(thistemp.previewdiv == null) { //���û�н���div���� imgw = img.width; imgh = img.height; thistemp.previewwidth = parseint(imgw * 0.1); var ele = document.createelement('div'); ele.classname = random; thistemp.pd.appendchild(ele); thistemp.previewdiv = thistemp.getbyelement(random); var eletop = (obj['y'] - parseint(imgh * 0.1) + 2); thistemp.css(thistemp.previewdiv, { width: srcarr.length * imgw * 10 + 'px', height: parseint(imgh * 0.1) + 'px', backgroundcolor: '#000000', position: 'absolute', left: '0px', top: eletop + 'px', display: 'none', zindex: '80' }); ele.setattribute('data-x', '0'); ele.setattribute('data-y', eletop); var ele2 = document.createelement('div'); ele2.classname = random + 'd2'; thistemp.pd.appendchild(ele2); thistemp.previewtop = thistemp.getbyelement(ele2.classname); thistemp.css(thistemp.previewtop, { width: parseint(imgw * 0.1) + 'px', height: parseint(imgh * 0.1) + 'px', position: 'absolute', border: '5px solid ' + thistemp.css(thistemp.cb['timeprogress'], 'backgroundcolor'), left: '0px', top: (obj['y'] - parseint(imgh * 0.1) + 2) + 'px', display: 'none', zindex: '81' }); var html = ''; for(n = 0; n < srcarr.length; n++) { html += thistemp.newcanvas(random + n, imgw * 10, parseint(imgh * 0.1)) } thistemp.previewdiv.innerhtml = html; } thistemp.previewdiv.appendchild(img); var cimg = thistemp.getbyelement(img.classname); var canvas = thistemp.getbyelement(img.classname + '-canvas'); var context = canvas.getcontext('2d'); var sx = 0, sy = 0, x = 0, h = parseint(imgh * 0.1); for(n = 0; n < 100; n++) { x = parseint(n * imgw * 0.1); context.drawimage(cimg, sx, sy, parseint(imgw * 0.1), h, x, 0, parseint(imgw * 0.1), h); sx += parseint(imgw * 0.1); if(sx >= imgw) { sx = 0; sy += h; } thistemp.css(cimg, 'display', 'none'); } if(loadnum == srcarr.length) { thistemp.previewstart = 2; } else { i++; loadimg(i); } }; }; } loadimg(i); return; } if(this.previewstart == 2) { var istween = true; var nownum = parseint(obj['time'] / this.vars['preview']['scale']); var numtotal = parseint(thistemp.getmetadate()['duration'] / this.vars['preview']['scale']); if(thistemp.css(thistemp.previewdiv, 'display') == 'none') { istween = false; } thistemp.css(thistemp.previewdiv, 'display', 'block'); var imgwidth = thistemp.previewdiv.offsetwidth * 0.01 / srcarr.length; var left = (imgwidth * nownum) - obj['x'] + parseint(imgwidth * 0.5), top = obj['y'] - thistemp.previewdiv.offsetheight; thistemp.css(thistemp.previewdiv, 'top', top + 2 + 'px'); var topleft = obj['x'] - parseint(imgwidth * 0.5); var timepieces = 0; if(topleft < 0) { topleft = 0; timepieces = obj['x'] - topleft - imgwidth * 0.5; } if(topleft > thistemp.pd.offsetwidth - imgwidth) { topleft = thistemp.pd.offsetwidth - imgwidth; timepieces = obj['x'] - topleft - imgwidth * 0.5; } if(left < 0) { left = 0; } if(left > numtotal * imgwidth - thistemp.pd.offsetwidth) { left = numtotal * imgwidth - thistemp.pd.offsetwidth; } thistemp.css(thistemp.previewtop, { left: topleft + 'px', top: top + 2 + 'px', display: 'block' }); if(thistemp.previewtop.offsetheight>thistemp.previewdiv.offsetheight){ thistemp.css(thistemp.previewtop, { height:thistemp.previewdiv.offsetheight-(thistemp.previewtop.offsetheight-thistemp.previewdiv.offsetheight)+'px' }); } if(this.previewtween != null) { this.animatepause(this.previewtween); this.previewtween = null } var nowleft = parseint(thistemp.css(thistemp.previewdiv, 'left')); var leftc = nowleft + left; if(nowleft == -(left + timepieces)) { return; } if(istween) { var obj = { element: thistemp.previewdiv, start: null, end: -(left + timepieces), speed: 0.3 }; this.previewtween = this.animate(obj); } else { thistemp.css(thistemp.previewdiv, 'left', -(left + timepieces) + 'px') } } }, /* �ڲ����� ɾ��Ԥ��ͼ�ڵ� */ deletepreview: function() { if(this.previewdiv != null) { this.deletechild(this.previewdiv); this.previewdiv = null; this.previewstart = 0; } }, /* �ڲ����� �޸���ƶ��ַ������ */ changevideo: function() { if(!this.html5video) { this.getvarsobject(); this.v.newvideo(this.vars); return; } var varr = this.va; var v = this.vars; var i = 0; if(varr.length < 1) { return; } if(this.v != null && this.needseek == 0) { this.needseek = this.v.currenttime; } if(v['poster']) { this.v.poster = v['poster']; } else { this.v.removeattribute('poster'); } if(v['loop']) { this.v.loop = 'loop'; } else { this.v.removeattribute('loop'); } if(v['seek'] > 0) { this.needseek = v['seek']; } else { this.needseek = 0; } if(this.getfileext(varr[0][0]) != '.m3u8') { this.ism3u8 = false; } if(!this.ism3u8) { if(varr.length == 1) { this.v.innerhtml = ''; this.v.src = varr[0][0]; } else { var source = ''; varr = this.arrsort(varr); for(i = 0; i < varr.length; i++) { var type = ''; var va = varr[i]; if(va[1]) { type = ' type="' + va[1] + '"'; } source += ''; } this.v.removeattribute('src'); this.v.innerhtml = source; } //������ƶ��ַ���� if(v['autoplay']) { this.v.autoplay = 'autoplay'; } else { this.v.removeattribute('autoplay'); } this.v.load(); } else { this.embedhls(varr[0][0], v['autoplay']); } if(!this.isundefined(v['volume'])) { this.changevolume(v['volume']); } this.resetplayer(); //���ý���Ԫ�� this.timererrorfun(); this.addlistenervideochange(); //���������ļ����� if(this.vars['chtrack']) { this.loadtrack(); } }, /* �ڲ����� �����м���ͣ��ť,����loading��������ʾ�ı����λ�� */ elementcoordinate: function() { this.pdcoor = this.getxy(this.pd); this.css(this.cb['pausecenter'], { left: parseint((this.pd.offsetwidth - 80) * 0.5) + 'px', top: parseint((this.pd.offsetheight - 80) * 0.5) + 'px' }); this.css(this.cb['loading'], { left: parseint((this.pd.offsetwidth - 60) * 0.5) + 'px', top: parseint((this.pd.offsetheight - 60) * 0.5) + 'px' }); this.css(this.cb['errortext'], { left: parseint((this.pd.offsetwidth - 120) * 0.5) + 'px', top: parseint((this.pd.offsetheight - 30) * 0.5) + 'px' }); this.css(this.cb['logo'], { left: parseint(this.pd.offsetwidth - this.cb['logo'].offsetwidth - 20) + 'px', top: '20px' }); this.checkbarwidth(); }, /* �ڲ����� ���������ߴ�仯ʱ����ʾ��������ؽڵ� */ checkbarwidth: function() { var controlbarw = this.cb['controlbar'].offsetwidth; var ele = []; ele.push([ [this.cb['full'], this.cb['escfull'], this.cb['fullline']], this.buttonwidth['full'] + 2, 'full' ]); if(this.vars['front'] != '') { ele.push([ [this.cb['front'], this.cb['frontline']], this.buttonwidth['front'] + 2 ]); } if(this.vars['next'] != '') { ele.push([ [this.cb['next'], this.cb['nextline']], this.buttonwidth['next'] + 2 ]); } if(this.cb['definition'].innerhtml != '') { ele.push([ [this.cb['definition'], this.cb['definitionline']], this.buttonwidth['definition'] + 2 ]); } ele.push([ [this.cb['volume']], this.buttonwidth['volume'] ]); ele.push([ [this.cb['mute'], this.cb['escmute'], this.cb['muteline']], this.buttonwidth['mute'] + 2, 'mute' ]); ele.push([ [this.cb['timetext']], this.buttonwidth['timetext'] ]); ele.push([ [this.cb['play'], this.cb['pause'], this.cb['playline']], this.buttonwidth['play'] + 2, 'play' ]); var i = 0; var len = 0; var isc = true; //��������ҫ��ʾ�ľڵ���ܿ�� for(var i = 0; i < ele.length; i++) { var nlen = ele[i][1]; if(nlen > 2) { len += nlen; } else { isc = false; } } if(isc) { this.buttonlen = len; this.buttonarr = ele; } len = this.buttonlen; ele = this.buttonarr; for(var i = 0; i < ele.length; i++) { if(len > controlbarw) { len -= ele[i][1]; this.css(ele[i][0], 'display', 'none'); } else { this.css(ele[i][0], 'display', 'block'); if(ele[i].length == 3) { var name = ele[i][2]; switch(name) { case 'mute': if(this.volume == 0) { this.css(this.cb['mute'], 'display', 'none'); } else { this.css(this.cb['escmute'], 'display', 'none'); } break; case 'play': this.playshow(this.v.paused ? false : true); break; case 'full': if(this.full) { this.css(this.cb['full'], 'display', 'none'); } else { this.css(this.cb['escfull'], 'display', 'none'); } break; } } } } }, /* �ڲ����� ��ʼ����ͣ�򲥷ű�ť */ initplaypause: function() { if(this.vars['autoplay']) { this.css([this.cb['play'], this.cb['pausecenter']], 'display', 'none'); this.css(this.cb['pause'], 'display', 'block'); } else { this.css(this.cb['play'], 'display', 'block'); if(this.css(this.cb['errortext'], 'display') == 'none') { this.css(this.cb['pausecenter'], 'display', 'block'); } this.css(this.cb['pause'], 'display', 'none'); } }, /* ������ĸ�����������ģ�����ƶ�ļ����¼������������ȫ��״̬�¼� �ڲ����� ������������¼����� */ addlistenererror: function() { for(var i = 0; i < this.errorfunarr.length; i++) { var fun = this.errorfunarr[i]; if(typeof(fun) == 'string') { fun = fun.replace('()', ''); eval(fun + '()'); } else { fun(); } } }, /* �ڲ����� ɾ����������¼����� */ delerrorfunarr: function(f) { try { var index = this.errorfunarr.indexof(f); if(index > -1) { this.errorfunarr.splice(index, 1); } } catch(e) {} }, /* �ڲ����� �����ƿ�ȫ��״̬�ı�ʱҫ���õļ����¼����� */ addlistenerfull: function() { for(var i = 0; i < this.fullfunarr.length; i++) { var fun = this.fullfunarr[i]; if(typeof(fun) == 'string') { fun = fun.replace('()', ''); eval(fun + '()'); } else { fun(); } } }, /* �ڲ����� ɾ���ƿ�ȫ��״̬�¼����� */ delfullfunarr: function(f) { try { var index = this.fullfunarr.indexof(f); if(index > -1) { this.fullfunarr.splice(index, 1); } } catch(e) {} }, /* �ڲ����� �������ŵ�ַ�ı�ʱҫ���õļ����¼����� */ addlistenervideochange: function() { for(var i = 0; i < this.videochangefunarr.length; i++) { var fun = this.videochangefunarr[i]; if(typeof(fun) == 'string') { fun = fun.replace('()', ''); eval(fun + '()'); } else { fun(); } } }, /* �ڲ����� ɾ�����ŵ�ַ�ı�ʱ״̬�¼����� */ delvideochangefunarr: function(f) { try { var index = this.videochangefunarr.indexof(f); if(index > -1) { this.videochangefunarr.splice(index, 1); } } catch(e) {} }, /* ����ϊ�����¼� �ڲ����� ����Ԫ�����ѽ��� */ loadedhandler: function() { this.loaded = true; if(this.playertype != 'html5video') { this.v.changelanguage(this.language); if(this.contextmenu.length > 0) { this.v.newmenu(this.contextmenu); } if(this.config) { this.v.config(this.config); } } if(this.vars['loaded'] != '') { try { eval(this.vars['loaded'] + '()'); } catch(event) { } this.addlistenervideochange(); } }, /* �ڲ����� �������� */ playinghandler: function() { this.playshow(true); if(this.needseek > 0) { this.seek(this.needseek); this.needseek = 0; } if(this.animatepausearray.length > 0) { this.animateresume('pause'); } if(this.playertype == 'html5video' && this.v != null && this.config['videodrawimage']) { this.sendvcanvas(); } }, /* �ڲ����� ʹ�û���������ƶ */ sendvcanvas: function() { if(this.timervcanvas == null) { this.css(this.v, 'display', 'none'); this.css(this.md, 'display', 'block'); var thistemp = this; var videocanvas = function() { if(thistemp.mdcx.width != thistemp.pd.offsetwidth) { thistemp.mdc.width = thistemp.pd.offsetwidth; } if(thistemp.mdcx.height != thistemp.pd.offsetheight) { thistemp.mdc.height = thistemp.pd.offsetheight; } thistemp.mdcx.clearrect(0, 0, thistemp.mdcx.width, thistemp.mdcx.height); var coor = thistemp.getproportioncoor(thistemp.pd.offsetwidth, thistemp.pd.offsetheight, thistemp.v.videowidth, thistemp.v.videoheight); thistemp.mdcx.drawimage(thistemp.v, 0, 0, thistemp.v.videowidth, thistemp.v.videoheight, coor['x'], coor['y'], coor['width'], coor['height']); }; this.timervcanvas = new this.timer(0, videocanvas); } }, /* �ڲ����� ������ͣ */ pausehandler: function() { this.playshow(false); if(this.animatepausearray.length > 0) { this.animatepause('pause'); } if(this.playertype == 'html5video' && this.v != null && this.config['videodrawimage']) { this.stopvcanvas(); } }, /* �ڲ����� ֹͣ���� */ stopvcanvas: function() { if(this.timervcanvas != null) { this.css(this.v, 'display', 'block'); this.css(this.md, 'display', 'none'); if(this.timervcanvas.runing) { this.timervcanvas.stop(); } this.timervcanvas = null; } }, /* �ڲ����� ���ݵ�ǰ���ż�����ͣȷ��ͼ����ʾ */ playshow: function(b) { if(b) { this.css(this.cb['play'], 'display', 'none'); this.css(this.cb['pausecenter'], 'display', 'none'); this.css(this.cb['pause'], 'display', 'block'); } else { this.css(this.cb['play'], 'display', 'block'); if(this.css(this.cb['errortext'], 'display') == 'none') { this.css(this.cb['pausecenter'], 'display', 'block'); } else { this.css(this.cb['pausecenter'], 'display', 'none'); } this.css(this.cb['pause'], 'display', 'none'); } }, /* �ڲ����� ����seek���� */ seekedhandler: function() { this.resettrack(); this.istimebuttonmove = true; if(this.v.paused) { this.play(); } }, /* �ڲ����� �������ž��� */ endedhandler: function() { if(!this.vars['loop']) { this.pause(); } }, /* �ڲ����� ���������ı� */ volumechangehandler: function() { try { if(this.v.volume > 0) { this.css(this.cb['mute'], 'display', 'block'); this.css(this.cb['escmute'], 'display', 'none'); } else { this.css(this.cb['mute'], 'display', 'none'); this.css(this.cb['escmute'], 'display', 'block'); } } catch(event) {} }, /* �ڲ����� ��������ʱ����ڽ����� */ timeupdatehandler: function() { var duration = 0; if(this.playertype == 'html5video') { try { duration = this.v.duration; } catch(event) {} } if(duration > 0) { this.time = this.v.currenttime; this.timetexthandler(); this.trackshowhandler(); if(this.istimebuttonmove) { this.timeprogress(this.time, duration); } } }, /* �ڲ����� ��ʱ��ı������ */ timeprogress: function(time, duration) { var timeprogressbgw = this.cb['timeprogressbg'].offsetwidth; var timebow = parseint((time * timeprogressbgw / duration) - (this.cb['timebutton'].offsetwidth * 0.5)); if(timebow > timeprogressbgw - this.cb['timebutton'].offsetwidth) { timebow = timeprogressbgw - this.cb['timebutton'].offsetwidth; } if(timebow < 0) { timebow = 0; } this.css(this.cb['timeprogress'], 'width', timebow + 'px'); this.css(this.cb['timebutton'], 'left', parseint(timebow) + 'px'); }, /* �ڲ����� ��������ʱ��ı�ʱ����ʾ�ı��� */ timetexthandler: function() { //��ʾʱ��/��ʱ�� var duration = this.v.duration; var time = this.v.currenttime; if(isnan(duration)) { duration = 0; } this.cb['timetext'].innerhtml = this.formattime(time) + ' / ' + this.formattime(duration); if(this.cb['timetext'].offsetwidth > 0) { this.buttonwidth['timetext'] = this.cb['timetext'].offsetwidth; } }, /* �ڲ����� �����ƿ��ǻ���״̬ */ bufferedhandler: function() { var thistemp = this; var cleartimerbuffer = function() { if(thistemp.timerbuffer != null) { if(thistemp.timerbuffer.runing) { thistemp.timerbuffer.stop(); } thistemp.timerbuffer = null; } }; cleartimerbuffer(); var bufferfun = function() { if(thistemp.v.buffered.length > 0) { var duration = thistemp.v.duration; var len = thistemp.v.buffered.length; var bufferstart = thistemp.v.buffered.start(len - 1); var bufferend = thistemp.v.buffered.end(len - 1); var loadtime = bufferstart + bufferend; var loadprogressbgw = thistemp.cb['timeprogressbg'].offsetwidth; var timebuttonw = thistemp.cb['timebutton'].offsetwidth; var loadw = parseint((loadtime * loadprogressbgw / duration) + timebuttonw); if(loadw >= loadprogressbgw) { loadw = loadprogressbgw; cleartimerbuffer(); } thistemp.changeload(loadtime); } }; this.timerbuffer = new this.timer(200, bufferfun); //this.timerbuffer.start(); }, /* �ڲ����� ����������ؽ��� */ changeload: function(loadtime) { if(this.v == null) { return; } var loadprogressbgw = this.cb['timeprogressbg'].offsetwidth; var timebuttonw = this.cb['timebutton'].offsetwidth; var duration = this.v.duration; if(this.isundefined(loadtime)) { loadtime = this.loadtime; } else { this.loadtime = loadtime; } var loadw = parseint((loadtime * loadprogressbgw / duration) + timebuttonw); this.css(this.cb['loadprogress'], 'width', loadw + 'px'); }, /* �ڲ����� �ж��ƿ���ֱ�� */ judgeislive: function() { var thistemp = this; if(this.timererror != null) { if(this.timererror.runing) { this.timererror.stop(); } this.timererror = null; } this.error = false; this.css(this.cb['errortext'], 'display', 'none'); var timeupdate = function(event) { thistemp.timeupdatehandler(); }; if(!this.vars['live']) { if(this.v != null && this.playertype == 'html5video') { this.addlistener('timeupdate', timeupdate); thistemp.timetexthandler(); thistemp.prompt(); //�����ʾ�� window.settimeout(function() { thistemp.bufferedhandler(); }, 200); } } else { this.removelistener('timeupdate', timeupdate); if(this.timertime != null) { window.clearinterval(this.timertime); timertime = null; } if(this.timertime != null) { if(this.timertime.runing) { this.timertime.stop(); } this.timertime = null; } var timefun = function() { if(thistemp.v != null && !thistemp.v.paused) { thistemp.cb['timetext'].innerhtml = thistemp.getnowdate(); } }; this.timertime = new this.timer(1000, timefun); //timertime.start(); } this.definition(); }, /* �ڲ����� ������ļ */ loadtrack: function() { var thistemp = this; var track = this.vars['chtrack']; var obj = { method: 'get', datatype: 'text', url: track['src'], charset: track['charset'], success: function(data) { thistemp.track = thistemp.parsesrtsubtitles(data); thistemp.trackindex = 0; thistemp.nowtrackshow = { sn: '' }; } }; this.ajax(obj); }, /* �ڲ����� ������ļ */ resettrack: function() { this.trackindex = 0; this.nowtrackshow = { sn: '' }; }, /* �ڲ����� ����ʱ��ı��ȡ��ʾ��ļ */ trackshowhandler: function() { if(this.track.length < 1) { return; } if(this.trackindex >= this.track.length) { this.trackindex = 0; } var nowtrack = this.track[this.trackindex]; //��ǰ��ŷ�ӧ����ļ���� /* this.nowtrackshow=��ǰ��ʾ�ڽ����ϵ����� �����ǰʱ��������nowtrackʱ���ڣ�����ҫ�ж� */ if(this.time >= nowtrack['starttime'] && this.time <= nowtrack['endtime']) { /* �����ǰ��ʾ�����ݲ����ڵ�ǰ��ҫ��ʾ������ʱ������ҫ��ʾ��ȷ������ */ var nowshow = this.nowtrackshow; if(nowshow['sn'] != nowtrack['sn']) { this.trackhide(); this.trackshow(nowtrack); } } else { /* * �����ǰ����ʱ�䲻�ڵ�ǰ�����ļ�ڣ�����ҫ����յ�ǰ����ļ���ݣ�����ʾ�µ���ļ���� */ this.trackhide(); this.checktrack(); } }, /* �ڲ����� ��ʾ��ļ���� */ trackshow: function(track) { this.nowtrackshow = track; var arr = track['content']; for(var i = 0; i < arr.length; i++) { var obj = { list: [{ type: 'text', text: arr[i], fontcolor: '#ffffff', fontsize: 16, fontfamily: '"microsoft yahei", yahei, "΢���ź�", simhei,"\5fae\8f6f\96c5\9ed1", "����",arial', lineheight: 30, }], position: [1, 2, null, -(arr.length - i) * 30 - 50] }; var ele = this.addelement(obj); this.trackelement.push(ele); } }, /* �ڲ����� ��������ļ���� */ trackhide: function() { for(var i = 0; i < this.trackelement.length; i++) { this.deleteelement(this.trackelement[i]); } this.trackelement = []; }, /* �ڲ����� ���¼�����ļ�ı�� */ checktrack: function() { var num = this.trackindex; var arr = this.track; var i = 0; for(i = num; i < arr.length; i++) { if(this.time >= arr[i]['starttime'] && this.time <= arr[i]['endtime']) { this.trackindex = i; break; } } }, /* -----------------------------------------------------------------------------�ӿں�����ʼ �ӿں��� �ڲ��ź���֮ͣ���л� */ playorpause: function() { if(this.config['videoclick']) { if(this.v == null) { return; } if(this.playertype=='flashplayer'){ this.v.playorpause(); return; } if(this.v.paused) { this.play(); } else { this.pause(); } } }, /* �ӿں��� ���ŷ��� */ play: function() { if(this.v != null && !this.error && this.loaded) { if(this.playertype=='html5video'){ this.v.play(); } else{ this.v.videoplay(); } } }, /* �ӿں��� ��ͣ���� */ pause: function() { if(this.v != null && !this.error && this.loaded) { if(this.playertype=='html5video'){ this.v.pause(); } else{ this.v.videopause(); } } }, /* �ӿں��� ��תʱ�䶯�� */ seek: function(time) { if(!this.loaded) { return; } var meta = this.getmetadate(); var duration = meta['duration']; if(duration > 0 && time > duration) { time = duration; } if(this.html5video && this.playertype == 'html5video' && !this.error) { this.v.currenttime = time; } else { this.v.seek(time); } }, /* �ӿں��� ��������/��ȡ���� */ changevolume: function(vol, bg, button) { if(isnan(vol) || this.isundefined(vol)) { vol = 0; } if(!this.loaded) { this.vars['volume'] = vol; } if(!this.html5video) { this.v.changevolume(vol); return; } try { if(this.isundefined(bg)) { bg = true; } } catch(e) {} try { if(this.isundefined(button)) { button = true; } } catch(e) {} if(vol<0){ vol=0; } if(vol>1){ vol=1; } this.v.volume = vol; this.volume = vol; if(bg) { var bgw = vol * this.cb['volumebg'].offsetwidth; if(bgw < 0) { bgw = 0; } if(bgw > this.cb['volumebg'].offsetwidth) { bgw = this.cb['volumebg'].offsetwidth; } this.css(this.cb['volumeup'], 'width', bgw + 'px'); } if(button) { var buleft = parseint(this.cb['volumeup'].offsetwidth - (this.cb['volumebo'].offsetwidth * 0.5)); if(buleft > this.cb['volumebg'].offsetwidth - this.cb['volumebo'].offsetwidth) { buleft = this.cb['volumebg'].offsetwidth - this.cb['volumebo'].offsetwidth } if(buleft < 0) { buleft = 0; } this.css(this.cb['volumebo'], 'left', buleft + 'px'); } }, /* ���ú��� ȫ��/�˳�ȫ���������ö���ֻ�����û������ſ��դ����������û������ť�������¼� */ switchfull: function() { if(this.full) { this.quitfullscreen(); } else { this.fullscreen(); } }, /* ���ú��� ȫ���������ö���ֻ�����û������ſ��դ����������û������ť�������¼� */ fullscreen: function() { if(this.html5video && this.playertype == 'html5video') { var element = this.pd; if(element.requestfullscreen) { element.requestfullscreen(); } else if(element.mozrequestfullscreen) { element.mozrequestfullscreen(); } else if(element.webkitrequestfullscreen) { element.webkitrequestfullscreen(); } else if(element.msrequestfullscreen) { element.msrequestfullscreen(); } this.judgefullscreen(); } }, /* ���ú��� �˳�ȫ������ */ quitfullscreen: function() { if(this.html5video && this.playertype == 'html5video') { if(document.exitfullscreen) { document.exitfullscreen(); } else if(document.msexitfullscreen) { document.msexitfullscreen(); } else if(document.mozcancelfullscreen) { document.mozcancelfullscreen(); } else if(document.orequestfullscreen) { document.ocancelfullscreen(); } else if(document.requestfullscreen) { document.requestfullscreen(); } else if(document.webkitexitfullscreen) { document.webkitexitfullscreen(); } else { this.css(document.documentelement, 'csstext', ''); this.css(document.document.body, 'csstext', ''); this.css(this.pd, 'csstext', ''); } this.judgefullscreen(); } }, /* �ӿں��� �ı䲥�����ߴ� */ changesize: function(w, h) { if(this.isundefined(w)) { w = 0; } if(this.isundefined(h)) { h = 0; } if(w > 0) { this.css(this.cd, 'width', w + 'px'); } if(h > 0) { this.css(this.cd, 'height', h + 'px'); } if(this.html5video) { this.elementcoordinate(); } }, /* �ӿں��� �򲥷��������µ���ƶ��ַ */ newvideo: function(c) { this.embed(c); }, /* ----------------------------------------------------------------------- ����flashplayer */ embedswf: function() { var vid = this.randomstring(); var flashvars = this.getflashvars(); var param = this.getflashplayerparam(); var flashplayerurl = 'http://www.macromedia.com/go/getflashplayer'; var html = '', src = javascriptpath + 'chplayer.swf'; id = 'id="' + vid + '" name="' + vid + '" '; html += ''; html += param['v']; html += ''; html += ''; html += ''; html += ''; this.pd.innerhtml = html; this.v = this.getobjectbyid(vid); //v�����岥��������ȫ�ֱ��� this.playertype = 'flashplayer'; }, /* ���ú��� ��vars����ת�����ַ� */ getflashvars: function() { this.getvarsobject(); var v = this.vars; var z = ''; for(k in v) { if(k != 'flashplayer' && k != 'container' && v[k] != '') { if(z != '') { z += '&'; } var vk = v[k]; if(vk == true) { vk = 1; } if(vk == false) { vk = 0; } z += k + '=' + vk; } } return z; }, /* ���ú��� ��vars��ʽ����flash�ܽ��ܵķ�������getflashvars����ת�����ַ�������newvideoֱ��ʹ�� */ getvarsobject: function() { var v = this.vars; var f = '', d = '', w = ''; //f=��ƶ��ַ��d=�����ȵ�ַ,w=ȩ�أ�z=���յ�ַ var arr = this.va; var prompt = v['prompt']; var i = 0; for(i = 0; i < arr.length; i++) { var arr2 = arr[i]; if(arr2){ if(f != '') { f += '|'; d += '|'; w += '|'; } f += arr2[0].replace(/&/g, '%26'); d += arr2[2]; w += arr2[3]; } } if(v['preview'] != null) { v['previewscale'] = v['preview']['scale']; v['preview'] = v['preview']['src'].join('|'); } if(prompt != null) { v['prompt'] = ''; v['prompttime'] = ''; for(i = 0; i < prompt.length; i++) { if(v['prompt'] != '') { v['prompt'] += '|'; v['prompttime'] += '|'; } v['prompt'] += prompt[i]['words']; v['prompttime'] += prompt[i]['time']; } } v['video'] = f; v['definition'] = d; v['weight'] = w; v['logo'] = this.logo; var newv={}; for(var k in v){ if(v[k]!=null){ newv[k]=v[k]; } } this.vars = newv; }, /* ���ú��� ��embedswf���param�ķ������ת�� */ getflashplayerparam: function() { var w = '', v = '', o = { allowscriptaccess: 'always', allowfullscreen: true, quality: 'high', bgcolor: '#000' }; for(var e in o) { w += e + '="' + o[e] + '" '; v += ''; } w = w.replace('movie=', 'src='); return { w: w, v: v }; }, /* ���ú��� flashplayer����д��timeֵ */ sendtime: function(time) { this.time = time; this.trackshowhandler(); }, /* ���ú��� flashplayer����д��volumeֵ */ sendvolume: function(vol) { this.volume = vol; }, /* ���ú��� flashplayer����д��fullֵ */ sendfull: function(b) { this.full = b; }, /* ������������ ----------------------------------------------------------------------- �ӿں��� ��ȡԪ���ݲ��� */ getmetadate: function() { if(!this.loaded || this.v==null) { return false; } if(this.playertype == 'html5video') { var duration=0; try{ duration=!isnan(this.v.duration) ? this.v.duration : 0; } catch(event){} var data = { duration: duration, volume: this.v.volume, width: this.pd.offsetwidth || this.v.offsetwidth || this.v.width, height: this.pd.offsetheight || this.v.offsetheight || this.v.height, videowidth: this.v.videowidth, videoheight: this.v.videoheight, paused: this.v.paused }; return data; } else { return this.v.getmetadate(); } return false; }, /* �ӿں��� ȡ��ǰ�ṩ�����������ŵ���ƶ�б� */ getvideourl: function() { var arr = []; if(this.v.src) { arr.push(this.v.src); } else { var uarr = this.v.childnodes; for(var i = 0; i < uarr.length; i++) { arr.push(uarr[i].src); } } return arr; }, /* ���ú��� �򲥷����������һ���ı� */ addelement: function(attribute) { if(this.playertype == 'flashplayer') { return this.v.addelement(attribute); } var i = 0; var obj = { list: null, x: '100%', y: "50%", position: null, alpha: 1, backgroundcolor: '', backalpha: 1, backradius: 0 }; obj = this.standardization(obj, attribute); var list = obj['list']; if(list == null) { return ''; } var id = 'element' + this.randomstring(10); var ele = document.createelement('div'); ele.classname = id; if(obj['x']) { ele.setattribute('data-x', obj['x']); } if(obj['y']) { ele.setattribute('data-y', obj['y']); } if(obj['position'] != null) { ele.setattribute('data-position', obj['position'].join(',')); } this.pd.appendchild(ele); var eid = this.getbyelement(id); this.css(eid, { position: 'absolute', filter: 'alpha(opacity:' + obj['alpha'] + ')', opacity: obj['alpha'].tostring(), width: '800px', zindex: '20' }); var bgid = 'elementbg' + this.randomstring(10); var bgalpha = obj['backalpha'].tostring(); var bgcolor = obj['backgroundcolor']; var html = ''; var idarr = []; if(!this.isundefined(list) && list.length > 0) { var textobj, returnobj; for(i = 0; i < list.length; i++) { var neweleid = 'elementnew' + this.randomstring(10); switch(list[i]['type']) { case 'image': textobj = { type: 'image', url: '', radius: 0, //բ�ǻ��� width: 30, //����������ҫ���� height: 30, //����ߣ�����ҫ���� alpha: 1, //͸���� paddingleft: 0, //��߾��� paddingright: 0, //�ұ߾��� paddingtop: 0, paddingbottom: 0, marginleft: 0, marginright: 0, margintop: 0, marginbottom: 0, backgroundcolor: '#ffffff', }; list[i] = this.standardization(textobj, list[i]); html += '
'; break; case 'text': textobj = { type: 'text', //˵�����ı� text: '', //�ı����� fontcolor: '#ffffff', fontsize: 14, fontfamily: '"microsoft yahei", yahei, "΢���ź�", simhei,"\5fae\8f6f\96c5\9ed1", "����",arial', lineheight: 0, alpha: 1, //͸���� paddingleft: 0, //��߾��� paddingright: 0, //�ұ߾��� paddingtop: 0, paddingbottom: 0, marginleft: 0, marginright: 0, margintop: 0, marginbottom: 0, backgroundcolor: '', backalpha: 1, backradius: 0 //����բ�ǻ��ȣ�֧������ͳһ���ã�ҳ֧�ַֿ�����[30,20,20,50]����ӧ�������ң����ң����� }; list[i] = this.standardization(textobj, list[i]); html += '
' + list[i]['text'] + '
'; break; default: break; } idarr.push(neweleid); } } eid.innerhtml = '
' + html + '
'; this.css(bgid + '_c', { position: 'absolute', zindex: '2' }); for(i = 0; i < idarr.length; i++) { switch(list[i]['type']) { case 'image': this.css(idarr[i], { float: 'left', width: list[i]['width'] + 'px', height: list[i]['height'] + 'px', filter: 'alpha(opacity:' + list[i]['alpha'] + ')', opacity: list[i]['alpha'].tostring(), marginleft: list[i]['marginleft'] + 'px', marginright: list[i]['marginright'] + 'px', margintop: list[i]['margintop'] + 'px', marginbottom: list[i]['marginbottom'] + 'px', borderradius: list[i]['radius'] + 'px', }); this.css(idarr[i] + '_image', { width: list[i]['width'] + 'px', height: list[i]['height'] + 'px', borderradius: list[i]['radius'] + 'px' }); break; case 'text': this.css(idarr[i] + '_text', { filter: 'alpha(opacity:' + list[i]['alpha'] + ')', opacity: list[i]['alpha'].tostring(), borderradius: list[i]['radius'] + 'px', fontfamily: list[i]['fontfamily'], fontsize: list[i]['fontsize'] + 'px', color: list[i]['fontcolor'], lineheight: list[i]['lineheight'] > 0 ? list[i]['lineheight'] + 'px' : '', paddingleft: list[i]['paddingleft'] + 'px', paddingright: list[i]['paddingright'] + 'px', paddingtop: list[i]['paddingtop'] + 'px', paddingbottom: list[i]['paddingbottom'] + 'px', whitespace: 'nowrap', position: 'absolute', zindex: '3' }); this.css(idarr[i], { float: 'left', width: this.getbyelement(idarr[i] + '_text').offsetwidth + 'px', height: this.getbyelement(idarr[i] + '_text').offsetheight + 'px', marginleft: list[i]['marginleft'] + 'px', marginright: list[i]['marginright'] + 'px', margintop: list[i]['margintop'] + 'px', marginbottom: list[i]['marginbottom'] + 'px' }); this.css(idarr[i] + '_bg', { width: this.getbyelement(idarr[i] + '_text').offsetwidth + 'px', height: this.getbyelement(idarr[i] + '_text').offsetheight + 'px', filter: 'alpha(opacity:' + list[i]['backalpha'] + ')', opacity: list[i]['backalpha'].tostring(), borderradius: list[i]['backradius'] + 'px', backgroundcolor: list[i]['backgroundcolor'], position: 'absolute', zindex: '2' }); break; default: break; } } this.css(bgid, { width: this.getbyelement(bgid + '_c').offsetwidth + 'px', height: this.getbyelement(bgid + '_c').offsetheight + 'px', position: 'absolute', filter: 'alpha(opacity:' + bgalpha + ')', opacity: bgalpha, backgroundcolor: bgcolor, borderradius: obj['backradius'] + 'px', zindex: '1' }); this.css(eid, { width: this.getbyelement(bgid).offsetwidth + 'px', height: this.getbyelement(bgid).offsetheight + 'px' }); var eidcoor = this.calculationcoor(eid); this.css(eid, { left: eidcoor['x'] + 'px', top: eidcoor['y'] + 'px' }); this.elementarr.push(eid.classname); return eid; }, /* ���ú��� ��ȡԪ�������ԣ�����x,y,width,height,alpha */ getelement: function(element) { if(this.playertype == 'flashplayer') { return this.v.getelement(element); } var ele = element; if(typeof(element) == 'string') { ele = this.getbyelement(element); } var coor = this.getcoor(ele); return { x: coor['x'], y: coor['y'], width: ele.offsetwidth, height: ele.offsetheight, alpha: !this.isundefined(this.css(ele, 'opacity')) ? parsefloat(this.css(ele, 'opacity')) : 1 }; }, /* ���ú��� ���ݽڵ��x,y�����ڲ������������ */ calculationcoor: function(ele) { if(this.playertype == 'flashplayer') { return this.v.calculationcoor(ele); } if(ele==[]){ return; } var x, y, position = []; var w = this.pd.offsetwidth, h = this.pd.offsetheight; var ew = ele.offsetwidth, eh = ele.offsetheight; if(!this.isundefined(ele.dataset['x'])) { x = ele.dataset['x'] } if(!this.isundefined(ele.dataset['y'])) { y = ele.dataset['y'] } if(!this.isundefined(ele.dataset['position'])) { position = ele.dataset['position'].split(','); } if(position.length > 0) { position.push(null, null, null, null); var i = 0; for(i = 0; i < position.length; i++) { if(this.isundefined(position[i]) || position[i] == null || position[i] == 'null' || position[i] == '') { position[i] = null; } else { position[i] = parsefloat(position[i]); } } if(position[2] == null) { switch(position[0]) { case 0: x = 0; break; case 1: x = parseint((w - ew) * 0.5); break; default: x = w - ew; break; } } else { switch(position[0]) { case 0: x = position[2]; break; case 1: x = parseint(w * 0.5) + position[2]; break; default: x = w + position[2]; break; } } if(position[3] == null) { switch(position[1]) { case 0: y = 0; break; case 1: y = parseint((h - eh) * 0.5); break; default: y = h - eh; break; } } else { switch(position[1]) { case 0: y = position[3]; break; case 1: y = parseint(h * 0.5) + position[3]; break; default: y = h + position[3]; break; } } } else { if(x.substring(x.length - 1, x.length) == '%') { x = math.floor(parseint(x.substring(0, x.length - 1)) * w * 0.01); } if(y.substring(y.length - 1, y.length) == '%') { y = math.floor(parseint(y.substring(0, y.length - 1)) * h * 0.01); } } return { x: x, y: y } }, /* ���ú��� �޸�����Ԫ�������� */ changeelementcoor: function() { for(var i = 0; i < this.elementarr.length; i++) { if(this.getbyelement(this.elementarr[i])!=[]){ var c = this.calculationcoor(this.getbyelement(this.elementarr[i])); this.css(this.elementarr[i], { top: c['y'] + 'px', left: c['x'] + 'px' }); } } }, /* ���ú��� ����ч���� */ tween: function() { var tween = { none: { //�����˶� easein: function(t, b, c, d) { return c * t / d + b; }, easeout: function(t, b, c, d) { return c * t / d + b; }, easeinout: function(t, b, c, d) { return c * t / d + b; } }, quadratic: { easein: function(t, b, c, d) { return c * (t /= d) * t + b; }, easeout: function(t, b, c, d) { return -c * (t /= d) * (t - 2) + b; }, easeinout: function(t, b, c, d) { if((t /= d / 2) < 1) return c / 2 * t * t + b; return -c / 2 * ((--t) * (t - 2) - 1) + b; } }, cubic: { easein: function(t, b, c, d) { return c * (t /= d) * t * t + b; }, easeout: function(t, b, c, d) { return c * ((t = t / d - 1) * t * t + 1) + b; }, easeinout: function(t, b, c, d) { if((t /= d / 2) < 1) return c / 2 * t * t * t + b; return c / 2 * ((t -= 2) * t * t + 2) + b; } }, quartic: { easein: function(t, b, c, d) { return c * (t /= d) * t * t * t + b; }, easeout: function(t, b, c, d) { return -c * ((t = t / d - 1) * t * t * t - 1) + b; }, easeinout: function(t, b, c, d) { if((t /= d / 2) < 1) return c / 2 * t * t * t * t + b; return -c / 2 * ((t -= 2) * t * t * t - 2) + b; } }, quintic: { easein: function(t, b, c, d) { return c * (t /= d) * t * t * t * t + b; }, easeout: function(t, b, c, d) { return c * ((t = t / d - 1) * t * t * t * t + 1) + b; }, easeinout: function(t, b, c, d) { if((t /= d / 2) < 1) return c / 2 * t * t * t * t * t + b; return c / 2 * ((t -= 2) * t * t * t * t + 2) + b; } }, sine: { easein: function(t, b, c, d) { return -c * math.cos(t / d * (math.pi / 2)) + c + b; }, easeout: function(t, b, c, d) { return c * math.sin(t / d * (math.pi / 2)) + b; }, easeinout: function(t, b, c, d) { return -c / 2 * (math.cos(math.pi * t / d) - 1) + b; } }, exponential: { easein: function(t, b, c, d) { return(t == 0) ? b : c * math.pow(2, 10 * (t / d - 1)) + b; }, easeout: function(t, b, c, d) { return(t == d) ? b + c : c * (-math.pow(2, -10 * t / d) + 1) + b; }, easeinout: function(t, b, c, d) { if(t == 0) return b; if(t == d) return b + c; if((t /= d / 2) < 1) return c / 2 * math.pow(2, 10 * (t - 1)) + b; return c / 2 * (-math.pow(2, -10 * --t) + 2) + b; } }, circular: { easein: function(t, b, c, d) { return -c * (math.sqrt(1 - (t /= d) * t) - 1) + b; }, easeout: function(t, b, c, d) { return c * math.sqrt(1 - (t = t / d - 1) * t) + b; }, easeinout: function(t, b, c, d) { if((t /= d / 2) < 1) return -c / 2 * (math.sqrt(1 - t * t) - 1) + b; return c / 2 * (math.sqrt(1 - (t -= 2) * t) + 1) + b; } }, elastic: { easein: function(t, b, c, d, a, p) { if(t == 0) return b; if((t /= d) == 1) return b + c; if(!p) p = d * .3; if(!a || a < math.abs(c)) { a = c; var s = p / 4; } else var s = p / (2 * math.pi) * math.asin(c / a); return -(a * math.pow(2, 10 * (t -= 1)) * math.sin((t * d - s) * (2 * math.pi) / p)) + b; }, easeout: function(t, b, c, d, a, p) { if(t == 0) return b; if((t /= d) == 1) return b + c; if(!p) p = d * .3; if(!a || a < math.abs(c)) { a = c; var s = p / 4; } else var s = p / (2 * math.pi) * math.asin(c / a); return(a * math.pow(2, -10 * t) * math.sin((t * d - s) * (2 * math.pi) / p) + c + b); }, easeinout: function(t, b, c, d, a, p) { if(t == 0) return b; if((t /= d / 2) == 2) return b + c; if(!p) p = d * (.3 * 1.5); if(!a || a < math.abs(c)) { a = c; var s = p / 4; } else var s = p / (2 * math.pi) * math.asin(c / a); if(t < 1) return -.5 * (a * math.pow(2, 10 * (t -= 1)) * math.sin((t * d - s) * (2 * math.pi) / p)) + b; return a * math.pow(2, -10 * (t -= 1)) * math.sin((t * d - s) * (2 * math.pi) / p) * .5 + c + b; } }, back: { easein: function(t, b, c, d, s) { if(s == undefined) s = 1.70158; return c * (t /= d) * t * ((s + 1) * t - s) + b; }, easeout: function(t, b, c, d, s) { if(s == undefined) s = 1.70158; return c * ((t = t / d - 1) * t * ((s + 1) * t + s) + 1) + b; }, easeinout: function(t, b, c, d, s) { if(s == undefined) s = 1.70158; if((t /= d / 2) < 1) return c / 2 * (t * t * (((s *= (1.525)) + 1) * t - s)) + b; return c / 2 * ((t -= 2) * t * (((s *= (1.525)) + 1) * t + s) + 2) + b; } }, bounce: { easein: function(t, b, c, d) { return c - tween.bounce.easeout(d - t, 0, c, d) + b; }, easeout: function(t, b, c, d) { if((t /= d) < (1 / 2.75)) { return c * (7.5625 * t * t) + b; } else if(t < (2 / 2.75)) { return c * (7.5625 * (t -= (1.5 / 2.75)) * t + .75) + b; } else if(t < (2.5 / 2.75)) { return c * (7.5625 * (t -= (2.25 / 2.75)) * t + .9375) + b; } else { return c * (7.5625 * (t -= (2.625 / 2.75)) * t + .984375) + b; } }, easeinout: function(t, b, c, d) { if(t < d / 2) return tween.bounce.easein(t * 2, 0, c, d) * .5 + b; else return tween.bounce.easeout(t * 2 - d, 0, c, d) * .5 + c * .5 + b; } } }; return tween; }, /* �ӿں��� ����ч�� ele:object=��ҫ�����ķ���, parameter:string=��ҫ�ı�����ԣ�x,y,width,height,alpha, effect:string=ч������, start:int=��ʼֵ, end:int=����ֵ, speed:number=�˶�����������֧��с�� */ animate: function(attribute) { if(this.playertype == 'flashplayer') { return this.v.animate(attribute); } var thistemp = this; var animateid = 'animate_' + this.randomstring(); var obj = { element: null, parameter: 'x', static: false, effect: 'none.easein', start: null, end: null, speed: 0, overstop: false, pausestop: false, //��ͣ����ʱ�����ƿ���ͣ callback: null }; obj = this.standardization(obj, attribute); if(obj['element'] == null || obj['speed'] == 0) { return false; } var w = this.pd.offsetwidth, h = this.pd.offsetheight; var effarr = (obj['effect'] + '.').split('.'); var tweenfun = this.tween()[effarr[0]][effarr[1]]; var elecoor = { x: 0, y: 0 }; if(this.isundefined(tweenfun)) { return false; } //�ƚ���Ԫ����Ԫ��������ɾ�������䲻�ٸ��沥�����ijߴ�ı���ı�λ�� var def = this.arrindexof(this.elementarr, obj['element'].classname); if(def > -1) { this.elementarr.splice(def, 1); } //var run = true; var css = {}; //�դ��ݵij�������ת����x��yת����left,top var pm = this.getelement(obj['element']); //����x,y,width,height,alpha���� var t = 0; //��ǰʱ�� var b = 0; //��ʼֵ var c = 0; //�仯�� var d = obj['speed'] * 1000; //����ʱ�� var timertween = null; var tweenobj = null; var start = obj['start'] == null ? '' : obj['start'].tostring(); var end = obj['end'] == null ? '' : obj['end'].tostring(); switch(obj['parameter']) { case 'x': if(obj['start'] == null) { b = pm['x']; } else { if(start.substring(start.length - 1, start.length) == '%') { b = parseint(start) * w * 0.01; } else { b = parseint(start); } } if(obj['end'] == null) { c = pm['x'] - b; } else { if(end.substring(end.length - 1, end.length) == '%') { c = parseint(end) * w * 0.01 - b; } else if(end.substring(0, 1) == '-' || end.substring(0, 1) == '+') { if(typeof(obj['end']) == 'number') { c = parseint(obj['end']) - b; } else { c = parseint(end); } } else { c = parseint(end) - b; } } break; case 'y': if(obj['start'] == null) { b = pm['y']; } else { if(start.substring(start.length - 1, start.length) == '%') { b = parseint(start) * h * 0.01; } else { b = parseint(start); } } if(obj['end'] == null) { c = pm['y'] - b; } else { if(end.substring(end.length - 1, end.length) == '%') { c = parseint(end) * h * 0.01 - b; } else if(end.substring(0, 1) == '-' || end.substring(0, 1) == '+') { if(typeof(obj['end']) == 'number') { c = parseint(obj['end']) - b; } else { c = parseint(end); } } else { c = parseint(end) - b; } } break; case 'alpha': if(obj['start'] == null) { b = pm['alpha'] * 100; } else { if(start.substring(start.length - 1, start.length) == '%') { b = parseint(obj['start']); } else { b = parseint(obj['start'] * 100); } } if(obj['end'] == null) { c = pm['alpha'] * 100 - b; } else { if(end.substring(end.length - 1, end.length) == '%') { c = parseint(end) - b; } else if(end.substring(0, 1) == '-' || end.substring(0, 1) == '+') { if(typeof(obj['end']) == 'number') { c = parseint(obj['end']) * 100 - b; } else { c = parseint(obj['end']) * 100; } } else { c = parseint(obj['end']) * 100 - b; } } break; } var callback = function() { var index = thistemp.arrindexof(thistemp.animateelementarray, animateid); if(index > -1) { thistemp.animatearray.splice(index, 1); thistemp.animateelementarray.splice(index, 1); } index = thistemp.arrindexof(thistemp.animatepausearray, animateid); if(index > -1) { thistemp.animatepausearray.splice(index, 1); } if(obj['callback'] != null && obj['element'] && obj['callback'] != 'callback' && obj['callback'] != 'tweenx' && obj['tweeny'] != 'callback' && obj['callback'] != 'tweenalpha') { var cb = eval(obj['callback']); cb(obj['element']); obj['callback'] = null; } }; var stoptween = function() { if(timertween != null) { if(timertween.runing) { timertween.stop(); } timertween = null; } }; var tweenx = function() { if(t < d) { t += 10; css = { left: math.ceil(tweenfun(t, b, c, d)) + 'px' }; if(obj['static']) { elecoor = thistemp.calculationcoor(obj['element']); css['top'] = elecoor['y'] + 'px'; } thistemp.css(obj['element'], css); } else { stoptween(); thistemp.elementarr.push(obj['element'].classname); callback(); } }; var tweeny = function() { if(t < d) { t += 10; css = { top: math.ceil(tweenfun(t, b, c, d)) + 'px' }; if(obj['static']) { elecoor = thistemp.calculationcoor(obj['element']); css['left'] = elecoor['x'] + 'px'; } thistemp.css(obj['element'], css); } else { stoptween(); thistemp.elementarr.push(obj['element'].classname); callback(); } }; var tweenalpha = function() { if(t < d) { t += 10; elecoor = thistemp.calculationcoor(obj['element']); var ap = math.ceil(tweenfun(t, b, c, d)) * 0.01; css = { filter: 'alpha(opacity:' + ap + ')', opacity: ap.tostring() }; if(obj['static']) { elecoor = thistemp.calculationcoor(obj['element']); css['top'] = elecoor['y'] + 'px'; css['left'] = elecoor['x'] + 'px'; } thistemp.css(obj['element'], css); } else { stoptween(); thistemp.elementarr.push(obj['element'].classname); callback(); } }; switch(obj['parameter']) { case 'x': tweenobj = tweenx; break; case 'y': tweenobj = tweeny; break; case 'alpha': tweenobj = tweenalpha; break; default: break; } timertween = new thistemp.timer(10, tweenobj); if(obj['overstop']) { var mouseover = function() { if(timertween != null && timertween.runing) { timertween.stop(); } }; this.addlistener('mouseover', mouseover, obj['element']); var mouseout = function() { var start = true; if(obj['pausestop'] && thistemp.getmetadate()['paused']) { start = false; } if(timertween != null && !timertween.runing && start) { timertween.start(); } }; this.addlistener('mouseout', mouseout, obj['element']); } this.animatearray.push(timertween); this.animateelementarray.push(animateid); if(obj['pausestop']) { this.animatepausearray.push(animateid); } return animateid; }, /* �ӿں������� ��������animate */ animateresume: function(id) { if(this.playertype == 'flashplayer') { this.v.animateresume(this.isundefined(id) ? '' : id); return; } var arr = []; if(id != '' && !this.isundefined(id) && id != 'pause') { arr.push(id); } else { if(id === 'pause') { arr = this.animatepausearray; } else { arr = this.animateelementarray; } } for(var i = 0; i < arr.length; i++) { var index = this.arrindexof(this.animateelementarray, arr[i]); if(index > -1) { this.animatearray[index].start(); } } }, /* �ӿں��� ��ͣ����animate */ animatepause: function(id) { if(this.playertype == 'flashplayer') { this.v.animatepause(this.isundefined(id) ? '' : id); return; } var arr = []; if(id != '' && !this.isundefined(id) && id != 'pause') { arr.push(id); } else { if(id === 'pause') { arr = this.animatepausearray; } else { arr = this.animateelementarray; } } for(var i = 0; i < arr.length; i++) { var index = this.arrindexof(this.animateelementarray, arr[i]); if(index > -1) { this.animatearray[index].stop(); } } }, /* ���ú��� ����idɾ���������ӧ������ */ deleteanimate: function(id) { var index = this.arrindexof(this.animateelementarray, id); if(index > -1) { this.animatearray.splice(index, 1); this.animateelementarray.splice(index, 1); } }, /* ���ú��� ɾ���ⲿ�½���Ԫ�� */ deleteelement: function(ele) { if(this.playertype == 'flashplayer' && this.v) { try{ this.v.deleteelement(ele); } catch(event){} return; } //�ƚ���Ԫ����Ԫ��������ɾ�������䲻�ٸ��沥�����ijߴ�ı���ı�λ�� var def = this.arrindexof(this.elementarr, ele.classname); if(def > -1) { this.elementarr.splice(def, 1); } this.deleteanimate(ele); this.deletechild(ele); }, /* -------------------------------------------------------------- ���ú������� ���º�������ֻ���ڱ�������ʹ�ã�ҳ������ҳ��������ŀ��ʹ�� ����id��ȡԪ�ض��� */ getbyelement: function(obj, parent) { if(this.isundefined(parent)) { parent = document; } var num = obj.substr(0, 1); var res = []; if(num != '#') { if(num == '.') { obj = obj.substr(1, obj.length); } if(parent.getelementsbyclassname) { res = parent.getelementsbyclassname(obj); } else { var reg = new regexp(' ' + obj + ' ', 'i'); var ele = parent.getelementsbytagname('*'); for(var i = 0; i < ele.length; i++) { if(reg.test(' ' + ele[i].classname + ' ')) { res.push(ele[i]); } } } if(res.length > 0) { return res[0]; } else { return res; } } else { if(num == '#') { obj = obj.substr(1, obj.length); } return document.getelementbyid(obj); } }, /* ���ú��� ���ܣ��޸���ʽ���ȡָ����ʽ��ֵ�� elem��id�����id��ӧ���ַ�������������һ�����ã������ʹ������ attribute����ʽ���ƻ��������ƕ�����ʡ�ե�valueֵ value��attributeϊ��ʽ����ʱ���������ʽֵ ʾ��һ�� this.css(id,'width','100px'); ʾ������ this.css('id','width','100px'); ʾ������ this.css([id1,id2,id3],'width','100px'); ʾ���ģ� this.css(id,{ width:'100px', height:'100px' }); ʾ����(��ȡ���)�� var width=this.css(id,'width'); */ css: function(elem, attribute, value) { var i = 0; var k = ''; if(typeof(elem) == 'object') { //��������� if(!this.isundefined(typeof(elem.length))) { //˵�������� for(i = 0; i < elem.length; i++) { var el; if(typeof(elem[i]) == 'string') { el = this.getbyelement(elem[i]) } else { el = elem[i]; } if(typeof(attribute) != 'object') { if(!this.isundefined(value)) { el.style[attribute] = value; } } else { for(k in attribute) { if(!this.isundefined(attribute[k])) { el.style[k] = attribute[k]; } } } } return; } } if(typeof(elem) == 'string') { elem = this.getbyelement(elem); } if(typeof(attribute) != 'object') { if(!this.isundefined(value)) { elem.style[attribute] = value; } else { if(!this.isundefined(elem.style[attribute])) { return elem.style[attribute]; } else { return false; } } } else { for(k in attribute) { if(!this.isundefined(attribute[k])) { elem.style[k] = attribute[k]; } } } }, /* ���ú��� �жϱ����ƿ���ڻ�ֵ�ƿ�ϊundefined */ isundefined: function(value) { try { if(value == 'undefined' || value == undefined) { return true; } } catch(event) {} return false; }, /* ���ú��� �������������÷�ʽ�� this.addlistener('click',function(event){},[id]); dֵϊ��ʱ�����ʾ������ǰ����ƶ������ */ addlistener: function(e, f, d, t) { if(this.playertype=='flashplayer' && this.isundefined(d)) { var ff = ''; //����������flashplayer���ݵĺ����ַ� if(typeof(f) == 'function') { ff = this.getparameternames(f); } this.v.addlistener(e, ff); return; } if(this.isundefined(t)) { t = false } if(e == 'full') { this.fullfunarr.push(f); return; } if(e == 'error' && this.isundefined(d)) { this.errorfunarr.push(f); return; } if(e == 'videochange') { this.videochangefunarr.push(f); return; } var o = this.v; if(!this.isundefined(d)) { o = d; } this.listenerarr.push([e, f, d, t]); if(o.addeventlistener) { try { o.addeventlistener(e, f, t); } catch(event) {} } else if(o.attachevent) { try { o.attachevent('on' + e, f); } catch(event) {} } else { o['on' + e] = f; } }, /* ���ú��� ɾ���������������÷�ʽ�� this.removelistener('click',function(event){}[,id]); dֵϊ��ʱ�����ʾ������ǰ����ƶ������ */ removelistener: function(e, f, d, t) { if(this.playertype=='flashplayer' && this.getparameternames(f) && this.isundefined(d)) { return; } if(this.isundefined(t)) { t = false } if(e == 'full') { this.delfullfunarr(f); return; } if(e == 'error') { this.delerrorfunarr(f); return; } if(e == 'videochange') { this.delvideochangefunarr(f); return; } var o = this.v; if(!this.isundefined(d)) { o = d; } for(var i = 0; i < this.listenerarr.length; i++) { if([e, f, d, t] == this.listenerarr[i]) { this.listenerarr.splice(i, 1); break; } } if(o.removeeventlistener) { try { this.addnum--; o.removeeventlistener(e, f, t); } catch(e) {} } else if(o.detachevent) { try { o.detachevent('on' + e, f); } catch(e) {} } else { o['on' + e] = null; } }, /* ���ú��� ��ȡ�������ƣ��� function chplayer(){} var fun=chplayer����getparameternames(fun)=chplayer */ getparameternames: function(fn) { if(typeof(fn) !== 'function') { return false; } var comments = /((\/\/.*$)|(\/\*[\s\s]*?\*\/))/mg; var code = fn.tostring().replace(comments, ''); var result = code.slice(code.indexof(' ') + 1, code.indexof('(')); return result === null ? false : result; }, /* ���ú��� ��ȡ��ǰ����ʱ�� */ getnowdate: function() { var nowdate = new date(); var month = nowdate.getmonth() + 1; var date = nowdate.getdate(); var hours = nowdate.gethours(); var minutes = nowdate.getminutes(); var seconds = nowdate.getseconds(); var tmonth = '', tdate = '', thours = '', tminutes = '', tseconds = '', tseconds = (seconds < 10) ? '0' + seconds : seconds + '', tminutes = (minutes < 10) ? '0' + minutes : minutes + '', thours = (hours < 10) ? '0' + hours : hours + '', tdate = (date < 10) ? '0' + date : date + '', tmonth = (month < 10) ? '0' + month : month + ''; return tmonth + '/' + tdate + ' ' + thours + ':' + tminutes + ':' + tseconds; }, /* ���ú��� ��ʽ��ʱ���� seconds:int������ ishours:boolean���ƿ���ʾсʱ��������ó�false�������ʾ��80:20����ʾ1сʱ20����20�� */ formattime: function(seconds, ishours) { var tseconds = '', tminutes = '', thours = ''; if(isnan(seconds)) { seconds = 0; } var s = math.floor(seconds % 60), m = 0, h = 0; if(ishours) { m = math.floor(seconds / 60) % 60; h = math.floor(seconds / 3600); } else { m = math.floor(seconds / 60); } tseconds = (s < 10) ? '0' + s : s + ''; tminutes = (m > 0) ? ((m < 10) ? '0' + m + ':' : m + ':') : '00:'; thours = (h > 0) ? ((h < 10) ? '0' + h + ':' : h + ':') : ''; if(ishours) { return thours + tminutes + tseconds; } else { return tminutes + tseconds; } }, /* ���ú��� ��ȡһ������ַ� len������ַ����� */ randomstring: function(len) { len = len || 16; var chars = 'abcdefghijklmnopqrstuvwxyz'; var maxpos = chars.length;���� var val = ''; for(i = 0; i < len; i++) { val += chars.charat(math.floor(math.random() * maxpos)); } return 'ch' + val; }, /* ���ú��� ��ȡ�ַ�������,��������,ӣ��������1 */ getstringlen: function(str) { var len = 0; for(var i = 0; i < str.length; i++) { if(str.charcodeat(i) > 127 || str.charcodeat(i) == 94) { len += 2; } else { len++; } } return len; }, /* �ڲ����� ����ϊajax�ṩ֧�� */ createxhr: function() { if(window.xmlhttprequest) { //ie7+��firefox��opera��chrome ��safari return new xmlhttprequest(); } else if(window.activexobject) { //ie6 ������ try { return new activexobject('microsoft.xmlhttp'); } catch(event) { try { return new activexobject('msxml2.xmlhttp'); } catch(event) { this.eject(this.errorlist[7]); } } } else { this.eject(this.errorlist[8]); } }, /* ���ú��� ajax���� */ ajax: function(cobj) { var thistemp = this; var callback = null; var obj = { method: 'get', //�������� datatype: 'json', //������������� charset: 'utf-8', async: false, //true��ʾ�첽��false��ʾͬ�� url: '', data: null, success: null }; if(typeof(cobj) != 'object') { this.eject(this.errorlist[9]); return; } obj = this.standardization(obj, cobj); if(obj.datatype === 'json' || obj.datatype === 'text' || obj.datatype === 'html') { var xhr = this.createxhr(); callback = function() { //�ж�http�ľ����ƿ�ɹ� if(xhr.status == 200) { if(obj.success == null) { return; } if(obj.datatype === 'json') { obj.success(eval('(' + xhr.responsetext + ')')); //�ص����ݲ��� } else { obj.success(xhr.responsetext); //�ص����ݲ��� } } else { thistemp.eject(thistemp.errorlist[10], 'ajax.status:' + xhr.status); } }; obj.url = obj.url + '?rand=' + this.randomstring(6); obj.data = this.formatparams(obj.data); //ͨ��params()����ֵ��ת�����ַ��� if(obj.method === 'get' && !this.isundefined(obj.data)) { obj.url += obj.url.indexof('?') == -1 ? '?' + obj.data : '&' + obj.data; } if(obj.async === true) { //true��ʾ�첽��false��ʾͬ�� xhr.onreadystatechange = function() { if(xhr.readystate == 4) { //�ж϶����״̬�ƿ񽻻���� callback(); //�ص� } }; } xhr.open(obj.method, obj.url, obj.async); if(obj.method === 'post') { xhr.setrequestheader('content-type', 'application/x-www-form-urlencoded'); xhr.setrequestheader('charset', obj['charset']); xhr.send(obj.data); } else { xhr.send(null); //get��ʽ����null } if(obj.async === false) { //ͬ�� callback(); } } else if(obj.datatype === 'jsonp') { var ohead = document.getelementsbytagname('head')[0]; var oscript = document.createelement('script'); var callbackname = 'callback' + new date().gettime(); var params = this.formatparams(obj.data) + '&callback=' + callbackname; //��ʱ���ƴ���ַ��� callback = obj.success; //ƴ�ӻ�src oscript.src = obj.url.split('?') + '?' + params; //����script��ǩ ohead.insertbefore(oscript, ohead.firstchild); //jsonp�ļص����� window[callbackname] = function(json) { callback(json); ohead.removechild(oscript); }; } }, /* ���ú��� ��̬����js */ loadjs: function(path, success) { var ohead = document.getelementsbytagname('head').item(0); var oscript = document.createelement('script'); oscript.type = 'text/javascript'; oscript.src = this.getnewurl(path); ohead.appendchild(oscript); oscript.onload = function() { success(); } }, /* ���ú��� ���������ƿ�֧��html5-video */ supportvideo: function() { if(!!document.createelement('video').canplaytype) { var vidtest = document.createelement("video"); oggtest = vidtest.canplaytype('video/ogg; codecs="theora, vorbis"'); if(!oggtest) { h264test = vidtest.canplaytype('video/mp4; codecs="avc1.42e01e, mp4a.40.2"'); if(!h264test) { return false; } else { if(h264test == "probably") { return true; } else { return false; } } } else { if(oggtest == "probably") { return true; } else { return false; } } } else { return false; } }, /* ���ú��� ����flashplayer�ķ��� */ getobjectbyid: function(id) { var x = null; var y = this.getbyelement('#'+id); var r = 'embed'; if(y && y.nodename == 'object') { if(typeof(y.setvariable) != 'undefined') { x = y; } else { var z = y.getelementsbytagname(r)[0]; if(z) { x = z; } } } return x; }, /* ���ú��� ����ת��ַ�ַ��� */ formatparams: function(data) { var arr = []; for(var i in data) { arr.push(encodeuricomponent(i) + '=' + encodeuricomponent(data[i])); } return arr.join('&'); }, /* ���ú��� �ե�ַ����ð������ */ arrsort: function(arr) { var temp = []; for(var i = 0; i < arr.length; i++) { for(var j = 0; j < arr.length - i; j++) { if(!this.isundefined(arr[j + 1]) && arr[j][3] < arr[j + 1][3]) { temp = arr[j + 1]; arr[j + 1] = arr[j]; arr[j] = temp; } } } return arr; }, /* ���ú��� �ж��ļ���׺ */ getfileext: function(filepath) { if(filepath != '') { if(filepath.indexof('?') > -1) { filepath = filepath.split('?')[0]; } var pos = '.' + filepath.replace(/.+\./, ''); return pos; } return ''; }, /* ���ú��� �����ַ���str�ƿ����key */ iscontains: function(str, key) { return str.indexof(key) > -1; }, /* ���ú��� ����ַ�������� */ getnewurl: function(url) { if(this.iscontains(url, '?')) { return url += '&' + this.randomstring(8) + '=' + this.randomstring(8); } else { return url += '?' + this.randomstring(8) + '=' + this.randomstring(8); } }, /* ���ú��� ��ȡclientx��clienty */ client: function(event) { var eve = event || window.event; if(this.isundefined(eve)){ eve={ clientx:0,clienty:0 }; } return { x: eve.clientx + (document.documentelement.scrollleft || document.body.scrollleft) - this.pdcoor['x'], y: eve.clienty + (document.documentelement.scrolltop || document.body.scrolltop) - this.pdcoor['y'] } }, /* ���ú��� ��ȡ�ڵ�ľ������� */ getcoor: function(obj) { var coor = this.getxy(obj); return { x: coor['x'] - this.pdcoor['x'], y: coor['y'] - this.pdcoor['y'] }; }, getxy: function(obj) { var parobj = obj; var left = obj.offsetleft; var top = obj.offsettop; while(parobj = parobj.offsetparent) { left += parobj.offsetleft; top += parobj.offsettop; } return { x: left, y: top }; }, /* ���ú��� ɾ����������������� */ removechild: function() { if(this.playertype == 'html5video') { //ɾ����ʱ�� var i = 0; var timerarr = [this.timererror, this.timerfull, this.timertime, this.timerbuffer, this.timerclick, this.timerloading, this.timercbar, this.timervcanvas]; for(i = 0; i < timerarr.length; i++) { if(timerarr[i] != null) { if(timerarr[i].runing) { timerarr[i].stop(); } timerarr[i] = null; } } //ɾ���¼����� var ltarr = this.listenerarr; for(i = 0; i < ltarr.length; i++) { this.removelistener(ltarr[i][0], ltarr[i][1], ltarr[i][2], ltarr[i][3]); } } this.playertype == ''; this.v = null; this.deletechild(this.cb['menu']); this.deletechild(this.pd); this.cd.innerhtml = ''; }, /* ���ú��� ����յ�ͼ�� */ canvasfill: function(name, path) { name.beginpath(); for(var i = 0; i < path.length; i++) { var d = path[i]; if(i > 0) { name.lineto(d[0], d[1]); } else { name.moveto(d[0], d[1]); } } name.closepath(); name.fill(); }, /* ���ú��� ������ */ canvasfillrect: function(name, path) { for(var i = 0; i < path.length; i++) { var d = path[i]; name.fillrect(d[0], d[1], d[2], d[3]); } }, /* ���ú��� ɾ�������ڵ� */ deletechild: function(f) { var def = this.arrindexof(this.elementarr, f.classname); if(def > -1) { this.elementarr.splice(def, 1); } var childs = f.childnodes; for(var i = childs.length - 1; i >= 0; i--) { f.removechild(childs[i]); } if(f && f != null && f.parentnode) { try { if(f.parentnode) { f.parentnode.removechild(f); } } catch(event) {} } }, /* ���ú��� ���������ŀ��,�ڲ��ڵ�ŀ�߼�����ڲ��ڵ�ŀ�߼����� */ getproportioncoor: function(stagew, stageh, vw, vh) { var w = 0, h = 0, x = 0, y = 0; if(stagew / stageh < vw / vh) { w = stagew; h = w * vh / vw; } else { h = stageh; w = h * vw / vh; } x = (stagew - w) * 0.5; y = (stageh - h) * 0.5; return { width: parseint(w), height: parseint(h), x: parseint(x), y: parseint(y) }; }, /* ���ú��� ����ļ�ļ�����ת�������� */ parsesrtsubtitles: function(srt) { var subtitles = []; var textsubtitles = []; var i = 0; var arrs = srt.split('\n'); var arr = []; var delhtmltag = function(str) { return str.replace(/<[^>]+>/g, ''); //ȥ�����е�html��� }; for(i = 0; i < arrs.length; i++) { if(arrs[i].replace(/\s/g, '').length > 0) { arr.push(arrs[i]); } else { if(arr.length > 0) { textsubtitles.push(arr); } arr = []; } } for(i = 0; i < textsubtitles.length; ++i) { var textsubtitle = textsubtitles[i]; if(textsubtitle.length >= 2) { var sn = textsubtitle[0]; // ��ļ����� var starttime = this.toseconds(this.trim(textsubtitle[1].split(' --> ')[0])); // ��ļ�ŀ�ʼʱ�� var endtime = this.toseconds(this.trim(textsubtitle[1].split(' --> ')[1])); // ��ļ�ľ���ʱ�� var content = [delhtmltag(textsubtitle[2])]; // ��ļ������ // ��ļ�����ж��� if(textsubtitle.length > 2) { for(var j = 3; j < textsubtitle.length; j++) { content.push(delhtmltag(textsubtitle[j])); } } // ��ļ���� var subtitle = { sn: sn, starttime: starttime, endtime: endtime, content: content }; subtitles.push(subtitle); } } return subtitles; }, /* ���ú��� ��ʱ��,�ú���ģ��as3�е�timerԭ�� time:��ʱʱ��,��λ:���� fun:���ܺ��� number:���д���,���������������� */ timer: function(time, fun, number) { var thistemp = this; this.time = 10; //���м�� this.fun = null; //�������� this.timeobj = null; //setinterval���� this.number = 0; //�����д��� this.numbertotal = null; //������ҫ���� this.runing = false; //��ǰ״̬ this.startfun = function() { thistemp.number++; thistemp.fun(); if(thistemp.numbertotal != null && thistemp.number >= thistemp.numbertotal) { thistemp.stop(); } }; this.start = function() { if(!thistemp.runing) { thistemp.runing = true; thistemp.timeobj = window.setinterval(thistemp.startfun, time); } }; this.stop = function() { if(thistemp.runing) { thistemp.runing = false; window.clearinterval(thistemp.timeobj); thistemp.timeobj = null; } }; if(time) { this.time = time; } if(fun) { this.fun = fun; } if(number) { this.numbertotal = number; } this.start(); }, /* ���ú��� ��ʱ����ת������ */ toseconds: function(t) { var s = 0.0; if(t) { var p = t.split(':'); for(i = 0; i < p.length; i++) { s = s * 60 + parsefloat(p[i].replace(',', '.')); } } return s; }, /* ���ú��� ������object��׼�� */ standardization: function(o, n) { //n�滻��o var h = {}; var k; for(k in o) { h[k] = o[k]; } for(k in n) { var type = typeof(h[k]); switch(type) { case 'number': h[k] = parsefloat(n[k]); break; case 'string': if(typeof(n[k]) != 'string' && typeof(n[k]) != 'undefined') { h[k] = n[k].tostring(); } else { h[k] = n[k]; } break; default: h[k] = n[k]; break; } } return h; }, /* ���ú��� �������� */ arrindexof: function(arr, key) { var re = new regexp(key, ['']); return(arr.tostring().replace(re, '��').replace(/[^,��]/g, '')).indexof('��'); }, /* ���ú��� ȥ��ո� */ trim: function(str) { return str.replace(/(^\s*)|(\s*$)/g, ''); }, /* ���ú��� ������ݵ�����̨ */ log: function(val) { try { console.log(val); } catch(e) {} }, /* ���ú��� ������ʾ */ eject: function(er, val) { if(!this.vars['debug']){ return; } var errorval = er[1]; if(!this.isundefined(val)) { errorval = errorval.replace('[error]', val); } var value = 'error ' + er[0] + ':' + errorval; try { alert(value); } catch(e) {} } }; window.chplayer = chplayer; })();