/* 软件名称: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'], ['下一集', 'javascript', 'nextfun', 'line'] ], //全局变量/变量类型: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/功能:是否加载了播放器 // 如果你不需要使用logo,可以设置如logo:'null', 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/功能:设置进度按钮及进度条是否跟着时间变化,该属性主要用来在按下进度按钮时暂停进度按钮移动和进度条的长度变化 istimebuttonmove: true, //全局变量/变量类型:boolean/功能:进度栏是否有效,如果是直播,则不需要监听时间让进度按钮和进度条变化 istimebuttondown: false, //全局变量/变量类型:boolean/功能:用来模拟双击功能的判断 isclick: false, //全局变量/变量类型:计时器/功能:用来模拟双击功能的计时器 timerclick: null, //全局变量/变量类型:计时器/功能:旋转loading timerloading: null, //全局变量/变量类型:计时器/功能:监听鼠标在视频上移动显示控制栏 timercbar: null, //全局变量/变量类型: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/功能:判断当前使用的播放器类型,html5video或flashplayer playertype: '', //全局变量/变量类型:int/功能:加载进度条的长度 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 { /* 对象格式则说明是标准的视频地址格式 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.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(); //设置静音/取消静音的按钮样式 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:调用的参考值类型 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:调用的参考值类型 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 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; } //先将该元件从元件数组里删除,让其不再跟随播放器的尺寸改变而改变位置 var def = this.arrindexof(this.elementarr, obj['element'].classname); if(def > -1) { this.elementarr.splice(def, 1); } //var run = true; var css = {}; //对传递的参数进行转化,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; } //先将该元件从元件数组里删除,让其不再跟随播放器的尺寸改变而改变位置 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; })();