ckplayer

ckplayer desc

此脚本不应直接安装,它是一个供其他脚本使用的外部库。如果您需要使用该库,请在脚本元属性加入:// @require https://update.cn-greasyfork.org/scripts/447800/1069741/ckplayer.js

  1. /*
  2. 软件名称:ckplayer
  3. 软件版本:X
  4. 软件作者:http://www.ckplayer.com
  5. ---------------------------------------------------------------------------------------------
  6. 开发说明:
  7. 使用的主要程序语言:javascript(js)及actionscript3.0(as3.0)(as3.0主要用于flashplayer部分的开发,不在该页面呈现)
  8. 功能:播放视频
  9. 特点:兼容HTML5-VIDEO(优先)以及FlashPlayer
  10. =====================================================================================================================
  11. */
  12. function ckplayerConfig() {
  13. return {
  14. flashvars: {}, //用来补充flashvars里的对象
  15. languagePath: '', //语言包文件地址
  16. stylePath: '', //风格包文件地址
  17. config: {
  18. fullInteractive: true, //是否开启交互功能
  19. delay: 30, //延迟加载视频,单位:毫秒
  20. timeFrequency: 100, //计算当前播放时间和加载量的时间频率,单位:毫秒
  21. autoLoad: true, //视频是否自动加载
  22. loadNext: 0, //多段视频预加载的段数,设置成0则全部加载
  23. definition: true, //是否使用清晰度组件
  24. smartRemove: true, //是否使用智能清理,使用该功能则在多段时当前播放段之前的段都会被清除出内存,减少对内存的使用
  25. bufferTime: 200, //缓存区的长度,单位:毫秒,不要小于10
  26. click: true, //是否支持屏幕单击暂停
  27. doubleClick: true, //是否支持屏幕双击全屏
  28. doubleClickInterval: 200, //判断双击的标准,即二次单击间隔的时间差之内判断为是双击,单位:毫秒
  29. keyDown: {
  30. space: true, //是否启用空格键切换播放/暂停
  31. left: true, //是否启用左方向键快退
  32. right: true, //是否启用右方向键快进
  33. up: true, //是否支持上方向键增加音量
  34. down: true //是否支持下方向键减少音量
  35. },
  36. timeJump: 10, //快进快退时的秒数
  37. volumeJump: 0.1, //音量调整的数量,大于0小于1的小数
  38. timeScheduleAdjust: 1, //是否可调节调节栏,0不启用,1是启用,2是只能前进(向右拖动),3是只能后退,4是只能前进但能回到第一次拖动时的位置,5是看过的地方可以随意拖动
  39. previewDefaultLoad: true, //预览图片是否默认加载,优点是鼠标第一次经过进度条即可显示预览图片
  40. promptSpotTime: false, //提示点文字是否在前面加上对应时间
  41. buttonMode: {
  42. player: false, //鼠标在播放器上是否显示可点击形态
  43. controlBar: false, //鼠标在控制栏上是否显示可点击形态
  44. timeSchedule: true, //鼠标在时间进度条上是否显示可点击形态
  45. volumeSchedule: true //鼠标在音量调节栏上是否显示可点击形态
  46. },
  47. liveAndVod: {//直播+点播=回播功能
  48. open: false, //是否开启,开启该功能需要设置flashvars里live=true
  49. vodTime: 2, //可以回看的整点数
  50. start: 'start' //回看请求参数
  51. },
  52. errorNum: 3, //错误重连次数
  53. playCorrect: false, //是否需要错误修正,这是针对rtmp的
  54. timeCorrect: true, //http视频播放时间错误纠正,有些因为视频格式的问题导致视频没有实际播放结束视频文件就返回了stop命令
  55. m3u8Definition: {//m3u8自动清晰度时按关键字来进行判断
  56. //tags:['200k','110k','400k','600k','1000k']
  57. },
  58. m3u8MaxBufferLength: 30, //m3u8每次缓冲时间,单位:秒数
  59. split: ',', //当视频地址采用字符形式并且需要使用逗号或其它符号来切割数组里定义
  60. timeStamp: '', //一个地址,用来请求当前时间戳,用于播放器内部时间效准
  61. addCallback: 'adPlay,adPause,playOrPause,videoPlay,videoPause,videoMute,videoEscMute,videoClear,changeVolume,fastBack,fastNext,videoSeek,newVideo,getMetaDate,videoRotation,videoBrightness,videoContrast,videoSaturation,videoHue,videoZoom,videoProportion,videoError,addListener,removeListener,addElement,getElement,deleteElement,animate,animateResume,animatePause,deleteAnimate,changeConfig,getConfig,openUrl,fullScreen,quitFullScreen,switchFull,screenshot,custom,changeControlBarShow,getCurrentSrc'
  62. //需要支持的事件
  63. },
  64. menu: {//版权名称支持
  65. ckkey: '',
  66. name: '',
  67. link: '',
  68. version: '',
  69. domain: '',
  70. more: []
  71. },
  72. style: {//风格部分内容配置,这里主要配置loading和logo以及广告的部分内容
  73. loading: {
  74. file: 'data:image/swf;base64,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',
  75. align: 'center',
  76. vAlign: 'middle',
  77. offsetX: -100,
  78. offsetY: -40
  79. },
  80. logo: {
  81. // file: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFcAAAAUCAYAAAD4BKGuAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAVTSURBVHja1Fl/aJVVGP4cw/mH5tUWi3I53cA0WbeIzMgaq6lQoVawm0S6glHhIKM/TELICotqCxMSGWQRdFfRLEhc9mMxqA0rbdS2wsV0GkZXuaKUWlHvgeeNh7f3u1du3Ft74eGcnXu+c873vD/Pt0nZbDZyZL2gWZAQTBH8IjggeEjgPZASPIB+g/P7EsGT6J/BfHfjHFIv2Jpjj/+dlDskvCm42Jk7X3C7YJOgw/z2oOBGwdEYRW0RVAjOCZ4ugNggqwU3CTLRBJFyQ+xuwVRY14igB78tE9QKpgmeEHwkGKRnq9AeMesHRWwEsYGUxwSdBZ51ecweE4Lct0DsOVjaZvptA8jfC4JfghWpXIJ2jMY+EDShf1pwh6DvX5x1GtpDE43cNFlfhyFWpQ9xd5FgFo3fRi++C+2nCBNBRgU3O6RsEyyEQv4QLMb4CcE9RlFBLqS1WZ6BZ83A35ofVhuvfE5QJrjWebdgCJOx51qM1QgewbMzsO57MDQrB9DeC8ObHd5Xyb2eiNiQQxmtgkZBr+OuZwV7BIcF1RgbF1wTE2MbEccX48VY9sMzBilhTke/m+b1Q9lefpgruI7OsYhIGzPJuAnn3+6EM7vu1YKl5vkrYRSfCGZivCxoMklk7M5j6eFlXyRNRSAvAoFf0Fo/CC7LkbwuQjsZsf0qwbuI9wlYgIqGl6NEzDYibJ/gbmAfxpKoMDRcaSK8xZzjZbK+NMhSYoNSngV5e+ksKXp+JdqZwDDmdpSbsqa9gNAyi5JalSGv3iQ+dtNK9HvI+sNBh2AhvNYVaH+msRtAdsa4ehoKCuQsoP2PY8+kCSkJ5IRWjD2FZ4/BOFSWYv9KhI40eUKQ31CqdnLM1c1OOnHufKSS+iEZvgHNhji8g1yT5VZKdCnHO+ajvrYK/I7GkuSWjwvq8Mzl5M79NF89aCHaBNXmWv0sQVUUZEDwsDnbr2i9s31lKyGuFs7kITEBC+snJaToRYIFrRN0CeYgoSUxJ23WUm85eB41b4IUuIvGtyIMVMY8lzHGMoYworF7J/onKYk10/wVQL6zXYr+Zq9aOEhuXZPDel8Q3If+HMzTeHPKlForEK+mws3SMfH2UMxNLIJbasKsoIQZwVLbKFkN4T1C3HxUMM+EkCAfgjwNV40Y304KriOP+jIHqa+jvYsqnH/kqzKaGCFZxWnoTqooxky8+dHUsOGwr6Jfi9jmlVVTHGLnot9L3qGWqCToWYYRF5fDa96mtb93yI2g8B0IWxlTHWmi/hOG00D4mEJfJ5WhQX7ySCsDUaNkJeud6+sgXCgs3OLEG2/xdZSh10JBeiB1zQU0HuQdSib60rOdm9kFToIL8hmFiRHzm1YM0ylet5k579OFpcUk4I0oD0/QuJ7tcBy5ERY6ixdrh5uNwN3bUV7pd4E+J958HmPxbRRydqK/in6vxj5aH9din/udEPKtuU1GqBL24xJwBInQWiHLcbQVKBXTzkVpHP0tWHsIpZUqPeWcrScXuX2ImRkqlufBhdQl15ig3WLKH0/SeAmtD+uprBqGx1ThhlWN5LKG4lcNKbDblFDjVDU0wWK7yLLqnPNk6cKzKsfXt1GQmQQXSuwymhd3tr9lkvPJMUV152kc2PsmUEMxtzdPRk2SNX2DQ3Vhr02Is18LXjHVAz/bG0NEK8johus3UBiwyfkYlDkQUyLaWrwZBrbHMaB8Z3PJLaYk8IIVKKPSJdxbv3ecynNzLNr33GKLV1YVW4IyfycXfq0UxP4X5HJdXCqX4Wv0AKqYkkipw4LG6WxMNi+GhAtH+M/K8wVe7wuWvwQYAFT+UsGCXmX3AAAAAElFTkSuQmCC',
  82. align: 'right',
  83. vAlign: 'top',
  84. offsetX: -100,
  85. offsetY: 10
  86. },
  87. advertisement: {//广告相关的配置
  88. time: 5, //广告默认播放时长以及多个广告时每个广告默认播放时间,单位:秒
  89. method: 'get', //广告监测地址默认请求方式,get/post
  90. videoForce: false, //频广告是否强制播放结束
  91. videoVolume: 0.8, //视频音量
  92. skipButtonShow: true, //是否显示跳过广告按钮
  93. linkButtonShow: true, //是否显示广告链接按钮,如果选择显示,只有在提供了广告链接地址时才会显示
  94. muteButtonShow: true, //是否显示跳过广告按钮
  95. closeButtonShow: true, //暂停时是否显示关闭广告按钮
  96. closeOtherButtonShow: true, //其它广告是否需要关闭广告按钮
  97. frontSkipButtonDelay: 0, //前置广告跳过广告按钮延时显示的时间,单位:秒
  98. insertSkipButtonDelay: 0, //插入广告跳过广告按钮延时显示的时间,单位:秒
  99. endSkipButtonDelay: 0, //后置广告跳过广告按钮延时显示的时间,单位:秒
  100. frontStretched: 2, //前置广告拉伸方式,0=原始大小,1=自动缩放,2=只有当广告的宽或高大于播放器宽高时才进行缩放,3=参考播放器宽高,4=宽度参考播放器宽、高度自动,5=高度参考播放器高、宽度自动
  101. insertStretched: 2, //插入广告拉伸方式,0=原始大小,1=自动缩放,2=只有当广告的宽或高大于播放器宽高时才进行缩放,3=参考播放器宽高,4=宽度参考播放器宽、高度自动,5=高度参考播放器高、宽度自动
  102. pauseStretched: 2, //暂停广告拉伸方式,0=原始大小,1=自动缩放,2=只有当广告的宽或高大于播放器宽高时才进行缩放,3=参考播放器宽高,4=宽度参考播放器宽、高度自动,5=高度参考播放器高、宽度自动
  103. endStretched: 2 //结束广告拉伸方式,0=原始大小,1=自动缩放,2=只有当广告的宽或高大于播放器宽高时才进行缩放,3=参考播放器宽高,4=宽度参考播放器宽、高度自动,5=高度参考播放器高、宽度自动
  104. },
  105. video: {//视频的默认比例
  106. defaultWidth: 4, //宽度
  107. defaultHeight: 3 //高度
  108. }
  109. }
  110. };
  111. }
  112. !(function () {
  113. var javascriptPath = '';
  114. !function () {
  115. var scriptList = document.scripts,
  116. thisPath = scriptList[scriptList.length - 1].src;
  117. javascriptPath = thisPath.substring(0, thisPath.lastIndexOf('/') + 1);
  118. }();
  119. var ckplayer = function (obj) {
  120. /*
  121. javascript部分开发所用的注释说明:
  122. 1:初始化-程序调用时即运行的代码部分
  123. 2:定义样式-定义容器(div,p,canvas等)的样式表,即css
  124. 3:监听动作-监听元素节点(单击-click,鼠标进入-mouseover,鼠标离开-mouseout,鼠标移动-mousemove等)事件
  125. 4:监听事件-监听视频的状态(播放,暂停,全屏,音量调节等)事件
  126. 5:共用函数-这类函数在外部也可以使用
  127. 6:全局变量-定义成全局使用的变量
  128. 7:其它相关注释
  129. 全局变量说明:
  130. 在本软件中所使用到的全局变量(变量(类型)包括Boolean,String,Int,Object(包含元素对象和变量对象),Array,Function等)
  131. 下面列出重要的全局变量:
  132. V:Object:视频对象
  133. VA:Array:视频列表(包括视频地址,类型,清晰度说明)
  134. ID:String:视频ID
  135. CB:Object:控制栏各元素的集合对象
  136. PD:Object:内部视频容器对象
  137. ---------------------------------------------------------------------------------------------
  138. 程序开始
  139. 下面为需要初始化配置的全局变量
  140. 初始化配置
  141. config:全局变量/变量类型:Object/功能:定义一些基本配置
  142. */
  143. this.config = {
  144. videoClick: true, //是否支持单击播放/暂停动作
  145. videoDbClick: true, //是否支持双击全屏/退出全屏动作
  146. errorTime: 100, //延迟判断失败的时间,单位:毫秒
  147. videoDrawImage: false //是否使用视频drawImage功能,注意,该功能在移动端表现不了
  148. };
  149. //全局变量/变量类型:Object/功能:播放器默认配置,在外部传递过来相应配置后,则进行相关替换
  150. this.varsConfig = {
  151. playerID: '', //播放器ID
  152. container: '', //视频容器的ID
  153. variable: 'ckplayer', //播放函数(变量)名称
  154. volume: 0.8, //默认音量,范围0-1
  155. poster: '', //封面图片地址
  156. autoplay: false, //是否自动播放
  157. loop: false, //是否需要循环播放
  158. live: false, //是否是直播
  159. duration: 0, //指定总时间
  160. seek: 0, //默认需要跳转的秒数
  161. drag: '', //拖动时支持的前置参数
  162. front: '', //前一集按钮动作
  163. next: '', //下一集按钮动作
  164. loaded: '', //加载播放器后调用的函数
  165. flashplayer: false, //设置成true则强制使用flashplayer
  166. html5m3u8: false, //PC平台上是否使用h5播放器播放m3u8
  167. track: null, //字幕轨道
  168. cktrack: null, //ck字幕
  169. preview: null, //预览图片对象
  170. prompt: null, //提示点功能
  171. video: null, //视频地址
  172. config: '', //调用配置函数名称
  173. type: '', //视频格式
  174. crossorigin: '', //设置html5视频的crossOrigin属性
  175. crossdomain: '', //安全策略文件地址
  176. unescape: false, //默认flashplayer里需要解码
  177. mobileCkControls: false, //移动端h5显示控制栏
  178. playbackrate: 1, //默认倍速
  179. debug: false //是否开启调试模式
  180. };
  181. this.vars = {};
  182. //全局变量/变量类型:Object/功能:语言配置
  183. this.language = {
  184. volume: '音量:',
  185. play: '点击播放',
  186. pause: '点击暂停',
  187. full: '点击全屏',
  188. escFull: '退出全屏',
  189. mute: '点击静音',
  190. escMute: '取消静音',
  191. front: '上一集',
  192. next: '下一集',
  193. definition: '点击选择清晰度',
  194. playbackRate: '点击选择速度',
  195. error: '加载出错'
  196. };
  197. //全局变量/变量类型:Array/功能:右键菜单:[菜单标题,类型(link:链接,default:灰色,function:调用函数,javascript:调用js函数),执行内容(包含链接地址,函数名称),[line(间隔线)]]
  198. this.contextMenu = [
  199. // ['ckplayer', 'link', 'http://www.ckplayer.com'],
  200. ['version:1.0', 'default', 'line']
  201. ];
  202. //全局变量/变量类型:Array/功能:错误列表
  203. this.errorList = [
  204. ['000', 'Object does not exist'],
  205. ['001', 'Variables type is not a object'],
  206. ['002', 'Video object does not exist'],
  207. ['003', 'Video object format error'],
  208. ['004', 'Video object format error'],
  209. ['005', 'Video object format error'],
  210. ['006', '[error] does not exist '],
  211. ['007', 'Ajax error'],
  212. ['008', 'Ajax error'],
  213. ['009', 'Ajax object format error'],
  214. ['010', 'Ajax.status:[error]']
  215. ];
  216. //全局变量/变量类型:Array/功能:HTML5变速播放的值数组/如果不需要可以设置成null
  217. this.playbackRateArr = [
  218. [1, '正常'],
  219. ];
  220. //全局变量/变量类型:Array/功能:HTML5默认变速播放的值
  221. this.playbackRateDefault = 0;
  222. //全局变量/变量类型:String/功能:定义logo
  223. this.logo = '';
  224. //全局变量/变量类型:Boolean/功能:是否加载了播放器
  225. this.loaded = false;
  226. //全局变量/变量类型:计时器/功能:监听视频加载出错的状态
  227. this.timerError = null;
  228. //全局变量/变量类型:Boolean/功能:是否出错
  229. this.error = false;
  230. //全局变量/变量类型:Array/功能:出错地址的数组
  231. this.errorUrl = [];
  232. //全局变量/变量类型:计时器/功能:监听全屏与非全屏状态
  233. this.timerFull = null;
  234. //全局变量/变量类型:Boolean/功能:是否全屏状态
  235. this.full = false;
  236. //全局变量/变量类型:计时器/功能:监听当前的月/日 时=分=秒
  237. this.timerTime = null;
  238. //全局变量/变量类型:计时器/功能:监听视频加载
  239. this.timerBuffer = null;
  240. //全局变量/变量类型:Boolean/功能:设置进度按钮及进度条是否跟着时间变化,该属性主要用来在按下进度按钮时暂停进度按钮移动和进度条的长度变化
  241. this.isTimeButtonMove = true;
  242. //全局变量/变量类型:Boolean/功能:进度栏是否有效,如果是直播,则不需要监听时间让进度按钮和进度条变化
  243. this.isTimeButtonDown = false;
  244. //全局变量/变量类型:Boolean/功能:用来模拟双击功能的判断
  245. this.isClick = false;
  246. //全局变量/变量类型:计时器/功能:用来模拟双击功能的计时器
  247. this.timerClick = null;
  248. //全局变量/变量类型:计时器/功能:旋转loading
  249. this.timerLoading = null;
  250. //全局变量/变量类型:计时器/功能:监听鼠标在视频上移动显示控制栏
  251. this.timerCBar = null;
  252. //全局变量/变量类型:Int/功能:播放视频时如果该变量的值大于0,则进行跳转后设置该值为0
  253. this.needSeek = 0;
  254. //全局变量/变量类型:Int/功能:当前音量
  255. this.volume = 0;
  256. //全局变量/变量类型:Int/功能:静音时保存临时音量
  257. this.volumeTemp = 0;
  258. //全局变量/变量类型:Number/功能:当前播放时间
  259. this.time = 0;
  260. //全局变量/变量类型:Boolean/功能:定义首次调用
  261. this.isFirst = true;
  262. //全局变量/变量类型:Boolean/功能:是否使用HTML5-VIDEO播放
  263. this.html5Video = true;
  264. //全局变量/变量类型:Object/功能:记录视频容器节点的x;y
  265. this.pdCoor = {
  266. x: 0,
  267. y: 0
  268. };
  269. //全局变量/变量类型:String/功能:判断当前使用的播放器类型,html5video或flashplayer
  270. this.playerType = '';
  271. //全局变量/变量类型:Int/功能:加载进度条的长度
  272. this.loadTime = 0;
  273. //全局变量/body对象
  274. this.body = document.body || document.documentElement;
  275. //全局变量/V/播放器
  276. this.V = null;
  277. //全局变量/保存外部js监听事件数组
  278. this.listenerJsArr = [];
  279. //全局变量/保存控制栏显示元素的总宽度
  280. this.buttonLen = 0;
  281. //全局变量/保存控制栏显示元素的数组
  282. this.buttonArr = [];
  283. //全局变量/保存按钮元素的宽
  284. this.buttonWidth = {};
  285. //全局变量/保存播放器上新增元件的数组
  286. this.elementArr = [];
  287. //全局变量/字幕内容
  288. this.track = [];
  289. //全局变量/字幕索引
  290. this.trackIndex = 0;
  291. //全局变量/当前显示的字幕内容
  292. this.nowTrackShow = {
  293. sn: ''
  294. };
  295. //全局变量/保存字幕元件数组
  296. this.trackElement = [];
  297. //全局变量/将视频转换为图片
  298. this.timerVCanvas = null;
  299. //全局变量/animate
  300. this.animateArray = [];
  301. //全局变量/保存animate的元件
  302. this.animateElementArray = [];
  303. //全局变量/保存需要在暂停时停止缓动的数组
  304. this.animatePauseArray = [];
  305. //全局变量/预览图片加载状态/0=没有加载,1=正在加载,2=加载完成
  306. this.previewStart = 0;
  307. //全局变量/预览图片容器
  308. this.previewDiv = null;
  309. //全局变量/预览框
  310. this.previewTop = null;
  311. //全局变量/预览框的宽
  312. this.previewWidth = 120;
  313. //全局变量/预览图片容器缓动函数
  314. this.previewTween = null;
  315. //全局变量/是否是m3u8格式,是的话则可以加载hls.js
  316. this.isM3u8 = false;
  317. //全局变量/保存提示点数组
  318. this.promptArr = [];
  319. //全局变量/显示提示点文件的容器
  320. this.promptElement = null;
  321. //配置文件函数
  322. this.ckplayerConfig = {};
  323. //控制栏是否显示
  324. this.showFace = true;
  325. //是否监听过h5的错误
  326. this.errorAdd = false;
  327. //是否发送了错误
  328. this.errorSend = false;
  329. //控制栏是否隐藏
  330. this.controlBarIsShow = true;
  331. //字体
  332. this.fontFamily = '"Microsoft YaHei"; YaHei; "\5FAE\8F6F\96C5\9ED1"; SimHei; "\9ED1\4F53";Arial';
  333. //记录第一次拖动进度按钮时的位置
  334. this.timeSliderLeftTemp = 0;
  335. if (obj) {
  336. this.embed(obj);
  337. }
  338. };
  339. ckplayer.prototype = {
  340. /*
  341. 主要函数部分开始
  342. 主接口函数:
  343. 调用播放器需初始化该函数
  344. */
  345. embed: function (c) {
  346. //c:Object:是调用接口传递的属性对象
  347. if (window.location.href.substr(0, 7) == 'file://') {
  348. alert('Please use the HTTP protocol to open the page');
  349. return;
  350. }
  351. if (c == undefined || !c) {
  352. this.eject(this.errorList[0]);
  353. return;
  354. }
  355. if (typeof (c) != 'object') {
  356. this.eject(this.errorList[1]);
  357. }
  358. this.vars = this.standardization(this.varsConfig, c);
  359. if (!this.vars['mobileCkControls'] && this.isMobile()) {
  360. this.vars['flashplayer'] = false;
  361. this.showFace = false;
  362. }
  363. var videoString = this.vars['video'];
  364. if (!videoString) {
  365. this.eject(this.errorList[2]);
  366. return;
  367. }
  368. if (typeof (videoString) == 'string') {
  369. if (videoString.substr(0, 3) == 'CK:' || videoString.substr(0, 3) == 'CE:' || videoString.substr(8, 3) == 'CK:' || videoString.substr(8, 3) == 'CE:') {
  370. this.vars['flashplayer'] = true;
  371. }
  372. }
  373. if (this.vars['config']) {
  374. this.ckplayerConfig = eval(this.vars['config'] + '()');
  375. } else {
  376. this.ckplayerConfig = ckplayerConfig();
  377. }
  378. if ((!this.supportVideo() && this.vars['flashplayer'] != '') || (this.vars['flashplayer'] && this.uploadFlash()) || !this.isMsie()) {
  379. this.html5Video = false;
  380. this.getVideo();
  381. } else if (videoString) {
  382. //判断视频数据类型
  383. this.analysedVideoUrl(videoString);
  384. return this;
  385. } else {
  386. this.eject(this.errorList[2]);
  387. }
  388. },
  389. /*
  390. 内部函数
  391. 根据外部传递过来的video开始分析视频地址
  392. */
  393. analysedVideoUrl: function (video) {
  394. var i = 0,
  395. y = 0;
  396. var thisTemp = this;
  397. //定义全局变量VA:Array:视频列表(包括视频地址,类型,清晰度说明)
  398. this.VA = [];
  399. if (typeof (video) == 'string') { //如果是字符形式的则判断后缀进行填充
  400. if (video.substr(0, 8) != 'website:') {
  401. this.VA = [
  402. [video, '', '', 0]
  403. ];
  404. var fileExt = this.getFileExt(video);
  405. switch (fileExt) {
  406. case '.mp4':
  407. this.VA[0][1] = 'video/mp4';
  408. break;
  409. case '.ogg':
  410. this.VA[0][1] = 'video/ogg';
  411. break;
  412. case '.webm':
  413. this.VA[0][1] = 'video/webm';
  414. break;
  415. default:
  416. break;
  417. }
  418. this.getVideo();
  419. } else {
  420. if (this.html5Video) {
  421. var ajaxObj = {
  422. url: video.substr(8),
  423. success: function (data) {
  424. if (data) {
  425. thisTemp.analysedUrl(data);
  426. } else {
  427. thisTemp.eject(thisTemp.errorList[5]);
  428. this.VA = video;
  429. thisTemp.getVideo();
  430. }
  431. }
  432. };
  433. this.ajax(ajaxObj);
  434. } else {
  435. this.VA = video;
  436. this.getVideo();
  437. }
  438.  
  439. }
  440. } else if (typeof (video) == 'object') { //对象或数组
  441. if (!this.isUndefined(typeof (video.length))) { //说明是数组
  442. if (!this.isUndefined(typeof (video[0].length))) { //说明是数组形式的数组
  443. this.VA = video;
  444. }
  445. this.getVideo();
  446. } else {
  447. /*
  448. 如果video格式是对象形式,则分二种
  449. 如果video对象里包含type,则直接播放
  450. */
  451. if (!this.isUndefined(video['type'])) {
  452. this.VA.push([video['file'], video['type'], '', 0]);
  453. this.getVideo();
  454. } else {
  455. this.eject(this.errorList[5]);
  456. }
  457. }
  458. } else {
  459. this.eject(this.errorList[4]);
  460. }
  461. },
  462. /*
  463. 对请求到的视频地址进行重新分析
  464. */
  465. analysedUrl: function (data) {
  466. this.vars = this.standardization(this.vars, data);
  467. if (!this.isUndefined(data['video'])) {
  468. this.vars['video'] = data['video'];
  469. }
  470. this.analysedVideoUrl(this.vars['video']);
  471. },
  472. /*
  473. 内部函数
  474. 检查浏览器支持的视频格式,如果是则将支持的视频格式重新分组给播放列表
  475. */
  476. getHtml5Video: function () {
  477. var va = this.VA;
  478. var nva = [];
  479. var mobile = false;
  480. var video = document.createElement('video');
  481. var codecs = function (type) {
  482. var cod = '';
  483. switch (type) {
  484. case 'video/mp4':
  485. cod = 'avc1.4D401E, mp4a.40.2';
  486. break;
  487. case 'video/ogg':
  488. cod = 'theora, vorbis';
  489. break;
  490. case 'video/webm':
  491. cod = 'vp8.0, vorbis';
  492. break;
  493. default:
  494. break;
  495. }
  496. return cod;
  497. };
  498. var supportType = function (vidType, codType) {
  499. if (!video.canPlayType) {
  500. this.html5Video = false;
  501. return;
  502. }
  503. var isSupp = video.canPlayType(vidType + ';codecs="' + codType + '"');
  504. if (isSupp == '') {
  505. return false
  506. }
  507. return true;
  508. };
  509. if (this.vars['flashplayer'] || !this.isMsie()) {
  510. this.html5Video = false;
  511. return;
  512. }
  513. if (this.isMobile()) {
  514. mobile = true;
  515. }
  516. for (var i = 0; i < va.length; i++) {
  517. var v = va[i];
  518. if (v) {
  519. if (v[1] != '' && !mobile && supportType(v[1], codecs(v[1])) && v[0].substr(0, 4) != 'rtmp') {
  520. nva.push(v);
  521. }
  522. if ((this.getFileExt(v[0]) == '.m3u8' || this.vars['type'] == 'video/m3u8' || this.vars['type'] == 'm3u8' || v[1] == 'video/m3u8' || v[1] == 'm3u8') && this.vars['html5m3u8']) {
  523. this.isM3u8 = true;
  524. nva.push(v);
  525. }
  526. }
  527. }
  528. if (nva.length > 0) {
  529. this.VA = nva;
  530. } else {
  531. if (!mobile) {
  532. this.html5Video = false;
  533. }
  534. }
  535. },
  536. /*
  537. 内部函数
  538. 根据视频地址开始构建播放器
  539. */
  540. getVideo: function () {
  541. //如果存在字幕则加载
  542. if (this.V) { //如果播放器已存在,则认为是从newVideo函数发送过来的请求
  543. this.changeVideo();
  544. return;
  545. }
  546. if (this.vars['cktrack']) {
  547. this.loadTrack();
  548. }
  549. if (this.supportVideo() && !this.vars['flashplayer']) {
  550. this.getHtml5Video(); //判断浏览器支持的视频格式
  551. }
  552. var thisTemp = this;
  553. var v = this.vars;
  554. var src = '',
  555. source = '',
  556. poster = '',
  557. loop = '',
  558. autoplay = '',
  559. track = '';
  560. var video = v['video'];
  561. var i = 0;
  562. this.CD = this.getByElement(v['container']);
  563. volume = v['volume'];
  564. if (!this.CD) {
  565. this.eject(this.errorList[6], v['container']);
  566. return false;
  567. }
  568. //开始构建播放容器
  569. var playerID = 'ckplayer' + this.randomString();
  570. var playerDiv = document.createElement('div');
  571. playerDiv.className = playerID;
  572. this.V = undefined;
  573. this.CD.innerHTML = '';
  574. this.CD.appendChild(playerDiv);
  575. this.PD = this.getByElement(playerID); //PD:定义播放器容器对象全局变量
  576. this.css(this.CD, {
  577. backgroundColor: '#000000',
  578. overflow: 'hidden',
  579. position: 'relative'
  580. });
  581. this.css(this.PD, {
  582. backgroundColor: '#000000',
  583. width: '100%',
  584. height: '100%',
  585. fontFamily: this.fontFamily
  586. });
  587. if (this.html5Video) { //如果支持HTML5-VIDEO则默认使用HTML5-VIDEO播放器
  588. //禁止播放器容器上鼠标选择文本
  589. this.PD.onselectstart = this.PD.ondrag = function () {
  590. return false;
  591. };
  592. //播放容器构建完成并且设置好样式
  593. //构建播放器
  594. if (this.VA.length == 1) {
  595. src = ' src="' + decodeURIComponent(this.VA[0][0]) + '"';
  596. } else {
  597. var videoArr = this.VA.slice(0);
  598. videoArr = this.arrSort(videoArr);
  599. for (i = 0; i < videoArr.length; i++) {
  600. var type = '';
  601. var va = videoArr[i];
  602. if (va[1]) {
  603. type = ' type="' + va[1] + '"';
  604. if (type == ' type="video/m3u8"' || type == ' type="m3u8"') {
  605. type = '';
  606. }
  607. }
  608. source += '<source src="' + decodeURIComponent(va[0]) + '"' + type + '>';
  609. }
  610. }
  611. //分析视频地址结束
  612. if (v['autoplay']) {
  613. autoplay = ' autoplay="autoplay"';
  614. }
  615. if (v['poster']) {
  616. poster = ' poster="' + v['poster'] + '"';
  617. }
  618. if (v['loop']) {
  619. loop = ' loop="loop"';
  620. }
  621. if (v['seek'] > 0) {
  622. this.needSeek = v['seek'];
  623. }
  624. if (v['track'] != null && v['cktrack'] == null) {
  625. var trackArr = v['track'];
  626. var trackDefault = '';
  627. var defaultHave = false;
  628. for (i = 0; i < trackArr.length; i++) {
  629. var trackObj = trackArr[i];
  630. if (trackObj['default'] && !defaultHave) {
  631. trackDefault = ' default';
  632. defaultHave = true;
  633. } else {
  634. trackDefault = '';
  635. }
  636. track += '<track kind="' + trackObj['kind'] + '" src="' + trackObj['src'] + '" srclang="' + trackObj['srclang'] + '" label="' + trackObj['label'] + '"' + trackDefault + '>';
  637. }
  638. }
  639. var autoLoad = this.ckplayerConfig['config']['autoLoad'];
  640. var preload = '';
  641. if (!autoLoad) {
  642. preload = ' preload="meta"';
  643. }
  644. var vid = this.randomString();
  645. var controls = '';
  646. if (!this.showFace) {
  647. controls = ' controls="controls"';
  648. }
  649. var html = '';
  650. if (!this.isM3u8) {
  651. html = '<video id="' + vid + '"' + src + ' width="100%" height="100%"' + autoplay + poster + loop + preload + controls + ' x5-playsinline="" playsinline="" webkit-playsinline="true">' + source + track + '</video>';
  652. } else {
  653. html = '<video id="' + vid + '" width="100%" height="100%"' + poster + loop + preload + controls + ' x5-playsinline="" playsinline="" webkit-playsinline="true">' + track + '</video>';
  654. }
  655. this.PD.innerHTML = html;
  656. this.V = this.getByElement('#' + vid); //V:定义播放器对象全局变量
  657. if (this.vars['crossorigin']) {
  658. this.V.crossOrigin = this.vars['crossorigin'];
  659. }
  660. try {
  661. this.V.volume = volume; //定义音量
  662. if (this.playbackRateArr && this.vars['playbackrate'] > -1) {
  663. if (this.vars['playbackrate'] < this.playbackRateArr.length) {
  664. this.playbackRateDefault = this.vars['playbackrate'];
  665. }
  666. this.V.playbackRate = this.playbackRateArr[this.playbackRateDefault][0]; //定义倍速
  667. }
  668. } catch (error) {
  669. }
  670. this.css(this.V, {
  671. width: '100%',
  672. height: '100%'
  673. });
  674. if (this.isM3u8) {
  675. var loadJsHandler = function () {
  676. thisTemp.embedHls(thisTemp.VA[0][0], v['autoplay']);
  677. };
  678. this.loadJs(javascriptPath + 'hls/hls.min.js', loadJsHandler);
  679. }
  680. this.css(this.V, 'backgroundColor', '#000000');
  681. //创建一个画布容器
  682. if (this.config['videoDrawImage']) {
  683. var canvasID = 'vcanvas' + this.randomString();
  684. var canvasDiv = document.createElement('div');
  685. canvasDiv.className = canvasID;
  686. this.PD.appendChild(canvasDiv);
  687. this.MD = this.getByElement(canvasID); //定义画布存储容器
  688. this.css(this.MD, {
  689. backgroundColor: '#000000',
  690. width: '100%',
  691. height: '100%',
  692. position: 'absolute',
  693. display: 'none',
  694. cursor: 'pointer',
  695. left: '0px',
  696. top: '0px',
  697. zIndex: '10'
  698. });
  699. var cvid = 'ccanvas' + this.randomString();
  700. this.MD.innerHTML = this.newCanvas(cvid, this.PD.offsetWidth, this.PD.offsetHeight);
  701. this.MDC = this.getByElement(cvid + '-canvas');
  702. this.MDCX = this.MDC.getContext('2d');
  703. }
  704. this.playerType = 'html5video';
  705. //播放器构建完成并且设置好样式
  706. //建立播放器的监听函数,包含操作监听及事件监听
  707. this.addVEvent();
  708. //根据清晰度的值构建清晰度切换按钮
  709. if (this.showFace) {
  710. this.definition();
  711. if (!this.vars['live'] && this.playbackRateArr && this.vars['playbackrate'] > -1) {
  712. this.playbackRate();
  713. }
  714. if (v['autoplay']) {
  715. this.loadingStart(true);
  716. }
  717. }
  718. this.playerLoad();
  719. } else { //如果不支持HTML5-VIDEO则调用flashplayer
  720. this.embedSWF();
  721. }
  722. },
  723. /*
  724. 内部函数
  725. 发送播放器加载成功的消息
  726. */
  727. playerLoad: function () {
  728. var thisTemp = this;
  729. if (this.isFirst) {
  730. this.isFirst = false;
  731. window.setTimeout(function () {
  732. thisTemp.loadedHandler();
  733. }, 1);
  734. }
  735. },
  736. /*
  737. 内部函数
  738. 建立播放器的监听函数,包含操作监听及事件监听
  739. */
  740. addVEvent: function () {
  741. var thisTemp = this;
  742. //监听视频单击事件
  743. var eventVideoClick = function (event) {
  744. thisTemp.videoClick();
  745. };
  746. this.addListenerInside('click', eventVideoClick);
  747. this.addListenerInside('click', eventVideoClick, this.MDC);
  748. //延迟计算加载失败事件
  749. this.timerErrorFun();
  750. //监听视频加载到元数据事件
  751. var eventJudgeIsLive = function (event) {
  752. thisTemp.sendJS('loadedmetadata');
  753. thisTemp.sendJS('duration', thisTemp.V.duration);
  754. thisTemp.judgeIsLive();
  755. };
  756. this.addListenerInside('loadedmetadata', eventJudgeIsLive);
  757. //监听视频播放事件
  758. var eventPlaying = function (event) {
  759. thisTemp.playingHandler();
  760. thisTemp.sendJS('play');
  761. thisTemp.sendJS('paused', false);
  762. };
  763. this.addListenerInside('playing', eventPlaying);
  764. //监听视频暂停事件
  765. var eventPause = function (event) {
  766. thisTemp.pauseHandler();
  767. thisTemp.sendJS('pause');
  768. thisTemp.sendJS('paused', true);
  769. };
  770. this.addListenerInside('pause', eventPause);
  771. //监听视频播放时间事件
  772. var eventTimeupdate = function (event) {
  773. if (thisTemp.timerLoading != null) {
  774. thisTemp.loadingStart(false);
  775. }
  776. if (thisTemp.time) {
  777. thisTemp.sendJS('time', thisTemp.time);
  778. }
  779. };
  780. this.addListenerInside('timeupdate', eventTimeupdate);
  781. //监听视频缓冲事件
  782. var eventWaiting = function (event) {
  783. thisTemp.loadingStart(true);
  784. };
  785. this.addListenerInside('waiting', eventWaiting);
  786. //监听视频seek开始事件
  787. var eventSeeking = function (event) {
  788. thisTemp.sendJS('seek', 'start');
  789. };
  790. this.addListenerInside('seeking', eventSeeking);
  791. //监听视频seek结束事件
  792. var eventSeeked = function (event) {
  793. thisTemp.seekedHandler();
  794. thisTemp.sendJS('seek', 'ended');
  795. };
  796. this.addListenerInside('seeked', eventSeeked);
  797. //监听视频播放结束事件
  798. var eventEnded = function (event) {
  799. thisTemp.endedHandler();
  800. thisTemp.sendJS('ended');
  801. };
  802. this.addListenerInside('ended', eventEnded);
  803. //监听视频音量
  804. var eventVolumeChange = function (event) {
  805. try {
  806. thisTemp.volumechangeHandler();
  807. thisTemp.sendJS('volume', thisTemp.volume || thisTemp.V.volume);
  808. } catch (event) {
  809. }
  810. };
  811. this.addListenerInside('volumechange', eventVolumeChange);
  812. //监听全屏事件
  813. var eventFullChange = function (event) {
  814. var fullState = document.fullScreen || document.mozFullScreen || document.webkitIsFullScreen;
  815. thisTemp.sendJS('full', fullState);
  816. };
  817. this.addListenerInside('fullscreenchange', eventFullChange);
  818. this.addListenerInside('webkitfullscreenchange', eventFullChange);
  819. this.addListenerInside('mozfullscreenchange', eventFullChange);
  820. //建立界面
  821. if (this.showFace) {
  822. this.interFace();
  823. }
  824. },
  825. /*
  826. 内部函数
  827. 重置界面元素
  828. */
  829. resetPlayer: function () {
  830. this.timeTextHandler();
  831. if (this.showFace) {
  832. this.timeProgress(0, 1); //改变时间进度条宽
  833. this.changeLoad(0);
  834. this.initPlayPause(); //判断显示播放或暂停按钮
  835. this.definition(); //构建清晰度按钮
  836. this.showFrontNext(); //构建上一集下一集按钮
  837. this.deletePrompt(); //删除提示点
  838. this.deletePreview(); //删除预览图
  839. this.trackHide(); //重置字幕
  840. this.resetTrack();
  841. this.trackElement = [];
  842. this.track = [];
  843. }
  844. },
  845. /*
  846. 内部函数
  847. 构建界面元素
  848. */
  849. interFace: function () {
  850. this.showFace = true;
  851. var thisTemp = this;
  852. var html = ''; //控制栏内容
  853. var i = 0;
  854. var bWidth = 38, //按钮的宽
  855. bHeight = 38; //按钮的高
  856. var bBgColor = '#FFFFFF', //按钮元素默认颜色
  857. bOverColor = '#0782F5'; //按钮元素鼠标经过时的颜色
  858. var timeInto = this.formatTime(0) + ' / ' + this.formatTime(this.vars['duration']); //时间显示框默认显示内容
  859. var randomS = this.randomString(10); //获取一个随机字符串
  860. /*
  861. 以下定义界面各元素的ID,统一以ID结束
  862. */
  863. var controlBarBgID = 'controlbgbar' + randomS, //控制栏背景
  864. controlBarID = 'controlbar' + randomS, //控制栏容器
  865. timeProgressBgID = 'timeprogressbg' + randomS, //播放进度条背景
  866. loadProgressID = 'loadprogress' + randomS, //加载进度条
  867. timeProgressID = 'timeprogress' + randomS, //播放进度条
  868. timeBOBGID = 'timebobg' + randomS, //播放进度按钮容器,该元素为一个透明覆盖在播放进度条上
  869. timeBOID = 'timebo' + randomS, //播放进度可拖动按钮外框
  870. timeBWID = 'timebw' + randomS, //播放进度可拖动按钮内框
  871. timeTextID = 'timetext' + randomS, //时间文本框
  872. playID = 'play' + randomS, //播放按钮
  873. pauseID = 'pause' + randomS, //暂停按钮
  874. frontID = 'front' + randomS, //前一集按钮
  875. nextID = 'next' + randomS, //下一集按钮
  876. fullID = 'full' + randomS, //全屏按钮
  877. escFullID = 'escfull' + randomS, //退出全屏按钮
  878. muteID = 'mute' + randomS, //静音按钮
  879. escMuteID = 'escmute' + randomS, //取消静音按钮
  880. volumeID = 'volume' + randomS, //音量调节框容器
  881. volumeDbgID = 'volumedbg' + randomS, //音量调节框容器背景
  882. volumeBgID = 'volumebg' + randomS, //音量调节框背景层
  883. volumeUpID = 'volumeup' + randomS, //音量调节框可变宽度层
  884. volumeBOID = 'volumebo' + randomS, //音量调节按钮外框
  885. volumeBWID = 'volumebw' + randomS, //音量调节按钮内框
  886. definitionID = 'definition' + randomS, //清晰度容器
  887. definitionPID = 'definitionp' + randomS, //清晰度列表容器
  888. playbackRateID = 'playbackrate' + randomS, //清晰度容器
  889. playbackRatePID = 'playbackratep' + randomS, //清晰度列表容器
  890. promptBgID = 'promptbg' + randomS, //提示框背景
  891. promptID = 'prompt' + randomS, //提示框
  892. dlineID = 'dline' + randomS, //分隔线共用前缀
  893. menuID = 'menu' + randomS, //右键容器
  894. pauseCenterID = 'pausecenter' + randomS, //中间暂停按钮
  895. loadingID = 'loading' + randomS, //缓冲
  896. errorTextID = 'errortext' + randomS, //错误文本框
  897. logoID = 'logo' + randomS; //logo
  898. //构建一些PD(播放器容器)里使用的元素
  899. var controlBarBg = document.createElement('div'),
  900. controlBar = document.createElement('div'),
  901. timeProgressBg = document.createElement('div'),
  902. timeBoBg = document.createElement('div'),
  903. pauseCenter = document.createElement('div'),
  904. errorText = document.createElement('div'),
  905. promptBg = document.createElement('div'),
  906. prompt = document.createElement('div'),
  907. menuDiv = document.createElement('div'),
  908. definitionP = document.createElement('div'),
  909. playbackrateP = document.createElement('div'),
  910. loading = document.createElement('div'),
  911. logo = document.createElement('div');
  912.  
  913. controlBarBg.className = controlBarBgID;
  914. controlBar.className = controlBarID;
  915. timeProgressBg.className = timeProgressBgID;
  916. timeBoBg.className = timeBOBGID;
  917. promptBg.className = promptBgID;
  918. prompt.className = promptID;
  919. menuDiv.className = menuID;
  920. definitionP.className = definitionPID;
  921. playbackrateP.className = playbackRatePID;
  922. pauseCenter.className = pauseCenterID;
  923. loading.className = loadingID;
  924. logo.className = logoID;
  925. errorText.className = errorTextID;
  926.  
  927. this.PD.appendChild(controlBarBg);
  928. this.PD.appendChild(controlBar);
  929. this.PD.appendChild(timeProgressBg);
  930. this.PD.appendChild(timeBoBg);
  931. this.PD.appendChild(promptBg);
  932. this.PD.appendChild(prompt);
  933. this.PD.appendChild(definitionP);
  934. this.PD.appendChild(playbackrateP);
  935. this.PD.appendChild(pauseCenter);
  936.  
  937. this.PD.appendChild(loading);
  938. this.PD.appendChild(errorText);
  939. this.PD.appendChild(logo);
  940. this.body.appendChild(menuDiv);
  941. //构建一些PD(播放器容器)里使用的元素结束
  942.  
  943. if (this.vars['live']) { //如果是直播,时间显示文本框里显示当前系统时间
  944. timeInto = this.getNowDate();
  945. }
  946. //构建控制栏的内容
  947. html += '<div class="' + playID + '" data-title="' + thisTemp.language['play'] + '">' + this.newCanvas(playID, bWidth, bHeight) + '</div>'; //播放按钮
  948. html += '<div class="' + pauseID + '" data-title="' + thisTemp.language['pause'] + '">' + this.newCanvas(pauseID, bWidth, bHeight) + '</div>'; //暂停按钮
  949. html += '<div class="' + dlineID + '-la"></div>'; //分隔线
  950. html += '<div class="' + frontID + '" data-title="' + thisTemp.language['front'] + '">' + this.newCanvas(frontID, bWidth, bHeight) + '</div>'; //前一集按钮
  951. html += '<div class="' + dlineID + '-lb"></div>'; //分隔线
  952. html += '<div class="' + nextID + '" data-title="' + thisTemp.language['next'] + '">' + this.newCanvas(nextID, bWidth, bHeight) + '</div>'; //下一集按钮
  953. html += '<div class="' + dlineID + '-lc"></div>'; //分隔线
  954.  
  955. html += '<div class="' + timeTextID + '">' + timeInto + '</div>'; //时间文本
  956. html += '<div class="' + fullID + '" data-title="' + thisTemp.language['full'] + '">' + this.newCanvas(fullID, bWidth, bHeight) + '</div>'; //全屏按钮
  957. html += '<div class="' + escFullID + '" data-title="' + thisTemp.language['escFull'] + '">' + this.newCanvas(escFullID, bWidth, bHeight) + '</div>'; //退出全屏按钮
  958. html += '<div class="' + dlineID + '-ra"></div>'; //分隔线
  959. html += '<div class="' + definitionID + '" data-title="' + thisTemp.language['definition'] + '"></div>'; //清晰度容器
  960. html += '<div class="' + dlineID + '-rb"></div>'; //分隔线
  961. html += '<div class="' + playbackRateID + '" data-title="' + thisTemp.language['playbackRate'] + '"></div>'; //倍速
  962. html += '<div class="' + dlineID + '-rc"></div>'; //分隔线
  963. html += '<div class="' + volumeID + '"><div class="' + volumeDbgID + '"><div class="' + volumeBgID + '"><div class="' + volumeUpID + '"></div></div><div class="' + volumeBOID + '"><div class="' + volumeBWID + '"></div></div></div></div>'; //音量调节框,音量调节按钮
  964. html += '<div class="' + muteID + '" data-title="' + thisTemp.language['mute'] + '">' + this.newCanvas(muteID, bWidth, bHeight) + '</div>'; //静音按钮
  965. html += '<div class="' + escMuteID + '" data-title="' + thisTemp.language['escMute'] + '">' + this.newCanvas(escMuteID, bWidth, bHeight) + '</div>'; //退出静音按钮
  966. html += '<div class="' + dlineID + '-rd"></div>'; //分隔线
  967. this.getByElement(controlBarID).innerHTML = html;
  968. //构建控制栏内容结束
  969. //构建进度条内容
  970. this.getByElement(timeProgressBgID).innerHTML = '<div class="' + loadProgressID + '"></div><div class="' + timeProgressID + '"></div>';
  971. this.getByElement(timeBOBGID).innerHTML = '<div class="' + timeBOID + '"><div class="' + timeBWID + '"></div></div>';
  972. //构建进度条内容结束
  973. this.getByElement(pauseCenterID).innerHTML = this.newCanvas(pauseCenterID, 80, 80); //构建中间暂停按钮
  974. this.getByElement(loadingID).innerHTML = this.newCanvas(loadingID, 60, 60); //构建中间缓冲时显示的图标
  975. this.getByElement(errorTextID).innerHTML = this.language['error']; //构建错误时显示的文本框
  976. if (this.ckplayerConfig['style']['logo']) {
  977. if (this.ckplayerConfig['style']['logo']['file']) {
  978. var logoFile = this.ckplayerConfig['style']['logo']['file'];
  979. if (logoFile.substr(0, 15) == 'data:image/png;' || logoFile.substr(0, 15) == 'data:image/jpg;' || logoFile.substr(0, 15) == 'data:image/jpeg;') {
  980. this.getByElement(logoID).innerHTML = '<img src="' + logoFile + '" border="0">'; //构建logo
  981. }
  982. }
  983. } else {
  984. this.getByElement(logoID).innerHTML = this.vars['logo'] || this.logo || ''; //构建logo
  985. }
  986. //CB:Object:全局变量,将一些全局需要用到的元素统一放在CB对象里
  987. var pd = this.PD;
  988. this.CB = {
  989. controlBarBg: this.getByElement(controlBarBgID, pd),
  990. controlBar: this.getByElement(controlBarID, pd),
  991. promptBg: this.getByElement(promptBgID, pd),
  992. prompt: this.getByElement(promptID, pd),
  993. timeProgressBg: this.getByElement(timeProgressBgID, pd),
  994. loadProgress: this.getByElement(loadProgressID, pd),
  995. timeProgress: this.getByElement(timeProgressID, pd),
  996. timeBoBg: this.getByElement(timeBOBGID, pd),
  997. timeButton: this.getByElement(timeBOID, pd),
  998. timeText: this.getByElement(timeTextID, pd),
  999. play: this.getByElement(playID, pd),
  1000. front: this.getByElement(frontID, pd),
  1001. next: this.getByElement(nextID, pd),
  1002. pause: this.getByElement(pauseID, pd),
  1003. definition: this.getByElement(definitionID, pd),
  1004. definitionP: this.getByElement(definitionPID, pd),
  1005. definitionLine: this.getByElement(dlineID + '-rb', pd),
  1006. playbackrate: this.getByElement(playbackRateID, pd),
  1007. playbackrateP: this.getByElement(playbackRatePID, pd),
  1008. playbackrateLine: this.getByElement(dlineID + '-rc', pd),
  1009. full: this.getByElement(fullID, pd),
  1010. escFull: this.getByElement(escFullID, pd),
  1011. mute: this.getByElement(muteID, pd),
  1012. escMute: this.getByElement(escMuteID, pd),
  1013. volume: this.getByElement(volumeID, pd),
  1014. volumeBg: this.getByElement(volumeBgID, pd),
  1015. volumeUp: this.getByElement(volumeUpID, pd),
  1016. volumeBO: this.getByElement(volumeBOID, pd),
  1017. pauseCenter: this.getByElement(pauseCenterID, pd),
  1018. menu: this.getByElement(menuID),
  1019. loading: this.getByElement(loadingID, pd),
  1020. loadingCanvas: this.getByElement(loadingID + '-canvas', pd),
  1021. errorText: this.getByElement(errorTextID, pd),
  1022. logo: this.getByElement(logoID, pd),
  1023. playLine: this.getByElement(dlineID + '-la', pd),
  1024. frontLine: this.getByElement(dlineID + '-lb', pd),
  1025. nextLine: this.getByElement(dlineID + '-lc', pd),
  1026. fullLine: this.getByElement(dlineID + '-ra'),
  1027. definitionLine: this.getByElement(dlineID + '-rb', pd),
  1028. muteLine: this.getByElement(dlineID + '-rd', pd)
  1029. };
  1030. this.buttonWidth = {
  1031. play: bWidth,
  1032. full: bWidth,
  1033. front: bWidth,
  1034. next: bWidth,
  1035. mute: bWidth
  1036. };
  1037. //定义界面元素的样式
  1038. //控制栏背景
  1039. this.css(controlBarBgID, {
  1040. width: '100%',
  1041. height: bHeight + 'px',
  1042. backgroundColor: '#000000',
  1043. position: 'absolute',
  1044. bottom: '0px',
  1045. filter: 'alpha(opacity:0.8)',
  1046. opacity: '0.8',
  1047. zIndex: '90'
  1048. });
  1049. //控制栏容器
  1050. this.css(controlBarID, {
  1051. width: '100%',
  1052. height: bHeight + 'px',
  1053. position: 'absolute',
  1054. bottom: '0px',
  1055. zIndex: '90'
  1056. });
  1057. //中间暂停按钮
  1058. this.css(pauseCenterID, {
  1059. width: '80px',
  1060. height: '80px',
  1061. borderRadius: '50%',
  1062. position: 'absolute',
  1063. display: 'none',
  1064. cursor: 'pointer',
  1065. zIndex: '100'
  1066. });
  1067. //loading
  1068. this.css(loadingID, {
  1069. width: '60px',
  1070. height: '60px',
  1071. position: 'absolute',
  1072. display: 'none',
  1073. zIndex: '100'
  1074. });
  1075. //出错文本框
  1076. this.css(errorTextID, {
  1077. width: '120px',
  1078. height: '30px',
  1079. lineHeight: '30px',
  1080. color: '#FFFFFF',
  1081. fontSize: '14px',
  1082. textAlign: 'center',
  1083. position: 'absolute',
  1084. display: 'none',
  1085. zIndex: '101',
  1086. cursor: 'default',
  1087. zIndex: '100'
  1088. });
  1089. //定义logo文字的样式
  1090. this.css(logoID, {
  1091. height: '30px',
  1092. lineHeight: '30px',
  1093. color: '#FFFFFF',
  1094. fontFamily: 'Arial',
  1095. fontSize: '28px',
  1096. textAlign: 'center',
  1097. position: 'absolute',
  1098. float: 'left',
  1099. left: '-1000px',
  1100. top: '20px',
  1101. zIndex: '100',
  1102. filter: 'alpha(opacity:0.8)',
  1103. opacity: '0.8',
  1104. cursor: 'default'
  1105. });
  1106.  
  1107. this.css(this.CB['loadingCanvas'], {
  1108. transform: 'rotate(0deg)',
  1109. msTransform: 'rotate(0deg)',
  1110. mozTransform: 'rotate(0deg)',
  1111. webkitTransform: 'rotate(0deg)',
  1112. oTransform: 'rotate(0deg)'
  1113. });
  1114. //定义提示语的样式
  1115. this.css([promptBgID, promptID], {
  1116. height: '30px',
  1117. lineHeight: '30px',
  1118. color: '#FFFFFF',
  1119. fontSize: '14px',
  1120. textAlign: 'center',
  1121. position: 'absolute',
  1122. borderRadius: '5px',
  1123. paddingLeft: '5px',
  1124. paddingRight: '5px',
  1125. bottom: '0px',
  1126. display: 'none',
  1127. zIndex: '95'
  1128. });
  1129. this.css(promptBgID, {
  1130. backgroundColor: '#000000',
  1131. filter: 'alpha(opacity:0.5)',
  1132. opacity: '0.5'
  1133. });
  1134. //时间进度条背景容器
  1135. this.css(timeProgressBgID, {
  1136. width: '100%',
  1137. height: '6px',
  1138. backgroundColor: '#3F3F3F',
  1139. overflow: 'hidden',
  1140. position: 'absolute',
  1141. bottom: '38px',
  1142. zIndex: '88'
  1143. });
  1144. //加载进度和时间进度
  1145. this.css([loadProgressID, timeProgressID], {
  1146. width: '1px',
  1147. height: '6px',
  1148. position: 'absolute',
  1149. bottom: '38px',
  1150. top: '0px',
  1151. zIndex: '91'
  1152. });
  1153. this.css(loadProgressID, 'backgroundColor', '#6F6F6F');
  1154. this.css(timeProgressID, 'backgroundColor', bOverColor);
  1155. //时间进度按钮
  1156. this.css(timeBOBGID, {
  1157. width: '100%',
  1158. height: '14px',
  1159. overflow: 'hidden',
  1160. position: 'absolute',
  1161. bottom: '34px',
  1162. cursor: 'pointer',
  1163. zIndex: '92'
  1164. });
  1165. this.css(timeBOID, {
  1166. width: '14px',
  1167. height: '14px',
  1168. overflow: 'hidden',
  1169. borderRadius: '50%',
  1170. backgroundColor: bBgColor,
  1171. cursor: 'pointer',
  1172. position: 'absolute',
  1173. top: '0px',
  1174. zIndex: '20'
  1175. });
  1176. this.css(timeBWID, {
  1177. width: '8px',
  1178. height: '8px',
  1179. overflow: 'hidden',
  1180. borderRadius: '50%',
  1181. position: 'absolute',
  1182. backgroundColor: bOverColor,
  1183. left: '3px',
  1184. top: '3px'
  1185. });
  1186. this.css(timeTextID, {
  1187. lineHeight: bHeight + 'px',
  1188. color: '#FFFFFF',
  1189. fontFamily: 'arial',
  1190. fontSize: '16px',
  1191. paddingLeft: '10px',
  1192. float: 'left',
  1193. overflow: 'hidden',
  1194. cursor: 'default'
  1195. });
  1196. //分隔线
  1197. this.css([dlineID + '-la', dlineID + '-lb', dlineID + '-lc', dlineID + '-ra', dlineID + '-rb', dlineID + '-rc', dlineID + '-rd'], {
  1198. width: '0px',
  1199. height: bHeight + 'px',
  1200. overflow: 'hidden',
  1201. borderLeft: '1px solid #303030',
  1202. borderRight: '1px solid #151515',
  1203. filter: 'alpha(opacity:0.9)',
  1204. opacity: '0.9'
  1205. });
  1206. this.css([dlineID + '-la', dlineID + '-lb', dlineID + '-lc'], 'float', 'left');
  1207. this.css([dlineID + '-ra', dlineID + '-rb', dlineID + '-rc', dlineID + '-rd'], 'float', 'right');
  1208. this.css([dlineID + '-lb', dlineID + '-lc', dlineID + '-rb', dlineID + '-rc'], 'display', 'none');
  1209. //播放/暂停/上一集/下一集按钮
  1210. this.css([playID, pauseID, frontID, nextID], {
  1211. width: bWidth + 'px',
  1212. height: bHeight + 'px',
  1213. float: 'left',
  1214. overflow: 'hidden',
  1215. cursor: 'pointer'
  1216. });
  1217. this.css([frontID, nextID], 'display', 'none');
  1218. //初始化判断播放/暂停按钮隐藏项
  1219. this.initPlayPause();
  1220.  
  1221. //设置静音/取消静音的按钮样式
  1222. this.css([muteID, escMuteID], {
  1223. width: bWidth + 'px',
  1224. height: bHeight + 'px',
  1225. float: 'right',
  1226. overflow: 'hidden',
  1227. cursor: 'pointer'
  1228. });
  1229. if (this.vars['volume'] > 0) {
  1230. this.css(escMuteID, 'display', 'none');
  1231. } else {
  1232. this.css(muteID, 'display', 'none');
  1233. }
  1234. //音量调节框
  1235. this.css([volumeID, volumeDbgID], {
  1236. width: '110px',
  1237. height: bHeight + 'px',
  1238. overflow: 'hidden',
  1239. float: 'right'
  1240. });
  1241. this.css(volumeDbgID, {
  1242. position: 'absolute'
  1243. });
  1244. this.css([volumeBgID, volumeUpID], {
  1245. width: '100px',
  1246. height: '6px',
  1247. overflow: 'hidden',
  1248. borderRadius: '5px',
  1249. cursor: 'pointer'
  1250. });
  1251. this.css(volumeBgID, {
  1252. position: 'absolute',
  1253. top: '16px'
  1254. });
  1255. this.css(volumeBgID, 'backgroundColor', '#666666');
  1256. this.css(volumeUpID, 'backgroundColor', bOverColor);
  1257. this.buttonWidth['volume'] = 100;
  1258. //音量调节按钮
  1259. this.css(volumeBOID, {
  1260. width: '12px',
  1261. height: '12px',
  1262. overflow: 'hidden',
  1263. borderRadius: '50%',
  1264. position: 'absolute',
  1265. backgroundColor: bBgColor,
  1266. top: '13px',
  1267. left: '0px',
  1268. cursor: 'pointer'
  1269. });
  1270. this.css(volumeBWID, {
  1271. width: '6px',
  1272. height: '6px',
  1273. overflow: 'hidden',
  1274. borderRadius: '50%',
  1275. position: 'absolute',
  1276. backgroundColor: bOverColor,
  1277. left: '3px',
  1278. top: '3px'
  1279. });
  1280. //清晰度容器
  1281. this.css(definitionID, {
  1282. lineHeight: bHeight + 'px',
  1283. color: '#FFFFFF',
  1284. float: 'right',
  1285. fontSize: '14px',
  1286. textAlign: 'center',
  1287. overflow: 'hidden',
  1288. display: 'none',
  1289. cursor: 'pointer'
  1290. });
  1291. this.css(definitionPID, {
  1292. lineHeight: (bHeight - 8) + 'px',
  1293. color: '#FFFFFF',
  1294. overflow: 'hidden',
  1295. position: 'absolute',
  1296. bottom: '4px',
  1297. backgroundColor: '#000000',
  1298. textAlign: 'center',
  1299. zIndex: '95',
  1300. cursor: 'pointer',
  1301. display: 'none'
  1302. });
  1303. //倍速容器
  1304. this.css(playbackRateID, {
  1305. lineHeight: bHeight + 'px',
  1306. color: '#FFFFFF',
  1307. float: 'right',
  1308. fontSize: '14px',
  1309. textAlign: 'center',
  1310. overflow: 'hidden',
  1311. display: 'none',
  1312. cursor: 'pointer'
  1313. });
  1314. this.css(playbackRatePID, {
  1315. lineHeight: (bHeight - 8) + 'px',
  1316. color: '#FFFFFF',
  1317. overflow: 'hidden',
  1318. position: 'absolute',
  1319. bottom: '4px',
  1320. backgroundColor: '#000000',
  1321. textAlign: 'center',
  1322. zIndex: '95',
  1323. cursor: 'pointer',
  1324. display: 'none'
  1325. });
  1326. //设置全屏/退出全屏按钮样式
  1327. this.css([fullID, escFullID], {
  1328. width: bWidth + 'px',
  1329. height: bHeight + 'px',
  1330. float: 'right',
  1331. overflow: 'hidden',
  1332. cursor: 'pointer'
  1333. });
  1334. this.css(escFullID, 'display', 'none');
  1335. //构建各按钮的形状
  1336. //播放按钮
  1337. var cPlay = this.getByElement(playID + '-canvas').getContext('2d');
  1338. var cPlayFillRect = function () {
  1339. thisTemp.canvasFill(cPlay, [
  1340. [12, 10],
  1341. [29, 19],
  1342. [12, 28]
  1343. ]);
  1344. };
  1345. cPlay.fillStyle = bBgColor;
  1346. cPlayFillRect();
  1347. var cPlayOver = function (event) {
  1348. cPlay.clearRect(0, 0, bWidth, bHeight);
  1349. cPlay.fillStyle = bOverColor;
  1350. cPlayFillRect();
  1351. };
  1352. var cPlayOut = function (event) {
  1353. cPlay.clearRect(0, 0, bWidth, bHeight);
  1354. cPlay.fillStyle = bBgColor;
  1355. cPlayFillRect();
  1356. };
  1357.  
  1358. this.addListenerInside('mouseover', cPlayOver, this.getByElement(playID + '-canvas'));
  1359. this.addListenerInside('mouseout', cPlayOut, this.getByElement(playID + '-canvas'));
  1360. //暂停按钮
  1361. var cPause = this.getByElement(pauseID + '-canvas').getContext('2d');
  1362. var cPauseFillRect = function () {
  1363. thisTemp.canvasFillRect(cPause, [
  1364. [10, 10, 5, 18],
  1365. [22, 10, 5, 18]
  1366. ]);
  1367. };
  1368. cPause.fillStyle = bBgColor;
  1369. cPauseFillRect();
  1370. var cPauseOver = function (event) {
  1371. cPause.clearRect(0, 0, bWidth, bHeight);
  1372. cPause.fillStyle = bOverColor;
  1373. cPauseFillRect();
  1374. };
  1375. var cPauseOut = function (event) {
  1376. cPause.clearRect(0, 0, bWidth, bHeight);
  1377. cPause.fillStyle = bBgColor;
  1378. cPauseFillRect();
  1379. };
  1380. this.addListenerInside('mouseover', cPauseOver, this.getByElement(pauseID + '-canvas'));
  1381. this.addListenerInside('mouseout', cPauseOut, this.getByElement(pauseID + '-canvas'));
  1382. //前一集按钮
  1383. var cFront = this.getByElement(frontID + '-canvas').getContext('2d');
  1384. var cFrontFillRect = function () {
  1385. thisTemp.canvasFill(cFront, [
  1386. [16, 19],
  1387. [30, 10],
  1388. [30, 28]
  1389. ]);
  1390. thisTemp.canvasFillRect(cFront, [
  1391. [8, 10, 5, 18]
  1392. ]);
  1393. };
  1394. cFront.fillStyle = bBgColor;
  1395. cFrontFillRect();
  1396. var cFrontOver = function (event) {
  1397. cFront.clearRect(0, 0, bWidth, bHeight);
  1398. cFront.fillStyle = bOverColor;
  1399. cFrontFillRect();
  1400. };
  1401. var cFrontOut = function (event) {
  1402. cFront.clearRect(0, 0, bWidth, bHeight);
  1403. cFront.fillStyle = bBgColor;
  1404. cFrontFillRect();
  1405. };
  1406.  
  1407. this.addListenerInside('mouseover', cFrontOver, this.getByElement(frontID + '-canvas'));
  1408. this.addListenerInside('mouseout', cFrontOut, this.getByElement(frontID + '-canvas'));
  1409. //下一集按钮
  1410. var cNext = this.getByElement(nextID + '-canvas').getContext('2d');
  1411. var cNextFillRect = function () {
  1412. thisTemp.canvasFill(cNext, [
  1413. [8, 10],
  1414. [22, 19],
  1415. [8, 28]
  1416. ]);
  1417. thisTemp.canvasFillRect(cNext, [
  1418. [25, 10, 5, 18]
  1419. ]);
  1420. };
  1421. cNext.fillStyle = bBgColor;
  1422. cNextFillRect();
  1423. var cNextOver = function (event) {
  1424. cNext.clearRect(0, 0, bWidth, bHeight);
  1425. cNext.fillStyle = bOverColor;
  1426. cNextFillRect();
  1427. };
  1428. var cNextOut = function (event) {
  1429. cNext.clearRect(0, 0, bWidth, bHeight);
  1430. cNext.fillStyle = bBgColor;
  1431. cNextFillRect();
  1432. };
  1433. this.addListenerInside('mouseover', cNextOver, this.getByElement(nextID + '-canvas'));
  1434. this.addListenerInside('mouseout', cNextOut, this.getByElement(nextID + '-canvas'));
  1435. //全屏按钮
  1436. var cFull = this.getByElement(fullID + '-canvas').getContext('2d');
  1437. var cFullFillRect = function () {
  1438. thisTemp.canvasFillRect(cFull, [
  1439. [19, 10, 9, 3],
  1440. [25, 13, 3, 6],
  1441. [10, 19, 3, 9],
  1442. [13, 25, 6, 3]
  1443. ]);
  1444. };
  1445. cFull.fillStyle = bBgColor;
  1446. cFullFillRect();
  1447. var cFullOver = function () {
  1448. cFull.clearRect(0, 0, bWidth, bHeight);
  1449. cFull.fillStyle = bOverColor;
  1450. cFullFillRect();
  1451. };
  1452. var cFullOut = function () {
  1453. cFull.clearRect(0, 0, bWidth, bHeight);
  1454. cFull.fillStyle = bBgColor;
  1455. cFullFillRect();
  1456. };
  1457. this.addListenerInside('mouseover', cFullOver, this.getByElement(fullID + '-canvas'));
  1458. this.addListenerInside('mouseout', cFullOut, this.getByElement(fullID + '-canvas'));
  1459. //定义退出全屏按钮样式
  1460. var cEscFull = this.getByElement(escFullID + '-canvas').getContext('2d');
  1461. var cEscFullFillRect = function () {
  1462. thisTemp.canvasFillRect(cEscFull, [
  1463. [20, 9, 3, 9],
  1464. [23, 15, 6, 3],
  1465. [9, 20, 9, 3],
  1466. [15, 23, 3, 6]
  1467. ]);
  1468. };
  1469. cEscFull.fillStyle = bBgColor;
  1470. cEscFullFillRect();
  1471.  
  1472. var cEscFullOver = function () {
  1473. cEscFull.clearRect(0, 0, bWidth, bHeight);
  1474. cEscFull.fillStyle = bOverColor;
  1475. cEscFullFillRect();
  1476. };
  1477. var cEscFullOut = function () {
  1478. cEscFull.clearRect(0, 0, bWidth, bHeight);
  1479. cEscFull.fillStyle = bBgColor;
  1480. cEscFullFillRect();
  1481. };
  1482. this.addListenerInside('mouseover', cEscFullOver, this.getByElement(escFullID + '-canvas'));
  1483. this.addListenerInside('mouseout', cEscFullOut, this.getByElement(escFullID + '-canvas'));
  1484. //定义全屏按钮的样式
  1485. var cMute = this.getByElement(muteID + '-canvas').getContext('2d');
  1486. var cMuteFillRect = function () {
  1487. thisTemp.canvasFill(cMute, [
  1488. [10, 15],
  1489. [15, 15],
  1490. [21, 10],
  1491. [21, 28],
  1492. [15, 23],
  1493. [10, 23]
  1494. ]);
  1495. thisTemp.canvasFillRect(cMute, [
  1496. [23, 15, 2, 8],
  1497. [27, 10, 2, 18]
  1498. ]);
  1499. };
  1500. cMute.fillStyle = bBgColor;
  1501. cMuteFillRect();
  1502. var cMuteOver = function () {
  1503. cMute.clearRect(0, 0, bWidth, bHeight);
  1504. cMute.fillStyle = bOverColor;
  1505. cMuteFillRect();
  1506. };
  1507. var cMuteOut = function () {
  1508. cMute.clearRect(0, 0, bWidth, bHeight);
  1509. cMute.fillStyle = bBgColor;
  1510. cMuteFillRect();
  1511. };
  1512. this.addListenerInside('mouseover', cMuteOver, this.getByElement(muteID + '-canvas'));
  1513. this.addListenerInside('mouseout', cMuteOut, this.getByElement(muteID + '-canvas'));
  1514. //定义退出全屏按钮样式
  1515. var cEscMute = this.getByElement(escMuteID + '-canvas').getContext('2d');
  1516. var cEscMuteFillRect = function () {
  1517. thisTemp.canvasFill(cEscMute, [
  1518. [10, 15],
  1519. [15, 15],
  1520. [21, 10],
  1521. [21, 28],
  1522. [15, 23],
  1523. [10, 23]
  1524. ]);
  1525. thisTemp.canvasFill(cEscMute, [
  1526. [23, 13],
  1527. [24, 13],
  1528. [33, 25],
  1529. [32, 25]
  1530. ]);
  1531. thisTemp.canvasFill(cEscMute, [
  1532. [32, 13],
  1533. [33, 13],
  1534. [24, 25],
  1535. [23, 25]
  1536. ]);
  1537. };
  1538. cEscMute.fillStyle = bBgColor;
  1539. cEscMuteFillRect();
  1540. var cEscMuteOver = function () {
  1541. cEscMute.clearRect(0, 0, bWidth, bHeight);
  1542. cEscMute.fillStyle = bOverColor;
  1543. cEscMuteFillRect();
  1544. };
  1545. var cEscMuteOut = function () {
  1546. cEscMute.clearRect(0, 0, bWidth, bHeight);
  1547. cEscMute.fillStyle = bBgColor;
  1548. cEscMuteFillRect();
  1549. };
  1550. this.addListenerInside('mouseover', cEscMuteOver, this.getByElement(escMuteID + '-canvas'));
  1551. this.addListenerInside('mouseout', cEscMuteOut, this.getByElement(escMuteID + '-canvas'));
  1552. //定义loading样式
  1553. var cLoading = this.getByElement(loadingID + '-canvas').getContext('2d');
  1554. var cLoadingFillRect = function () {
  1555. cLoading.save();
  1556. var grad = cLoading.createLinearGradient(0, 0, 60, 60);
  1557. grad.addColorStop(0, bBgColor);
  1558. var grad2 = cLoading.createLinearGradient(0, 0, 80, 60);
  1559. grad2.addColorStop(1, bOverColor);
  1560. var grad3 = cLoading.createLinearGradient(0, 0, 80, 60);
  1561. grad3.addColorStop(1, '#FF9900');
  1562. var grad4 = cLoading.createLinearGradient(0, 0, 80, 60);
  1563. grad4.addColorStop(1, '#CC3300');
  1564. cLoading.strokeStyle = grad; //设置描边样式
  1565. cLoading.lineWidth = 8; //设置线宽
  1566. cLoading.beginPath(); //路径开始
  1567. cLoading.arc(30, 30, 25, 0, 0.4 * Math.PI, false); //用于绘制圆弧context.arc(x坐标,y坐标,半径,起始角度,终止角度,顺时针/逆时针)
  1568. cLoading.stroke(); //绘制
  1569. cLoading.closePath(); //路径结束
  1570. cLoading.beginPath(); //路径开始
  1571. cLoading.strokeStyle = grad2; //设置描边样式
  1572. cLoading.arc(30, 30, 25, 0.5 * Math.PI, 0.9 * Math.PI, false); //用于绘制圆弧context.arc(x坐标,y坐标,半径,起始角度,终止角度,顺时针/逆时针)
  1573. cLoading.stroke(); //绘制
  1574. cLoading.beginPath(); //路径开始
  1575. cLoading.strokeStyle = grad3; //设置描边样式
  1576. cLoading.arc(30, 30, 25, Math.PI, 1.4 * Math.PI, false); //用于绘制圆弧context.arc(x坐标,y坐标,半径,起始角度,终止角度,顺时针/逆时针)
  1577. cLoading.stroke(); //绘制
  1578. cLoading.beginPath(); //路径开始
  1579. cLoading.strokeStyle = grad4; //设置描边样式
  1580. cLoading.arc(30, 30, 25, 1.5 * Math.PI, 1.9 * Math.PI, false); //用于绘制圆弧context.arc(x坐标,y坐标,半径,起始角度,终止角度,顺时针/逆时针)
  1581. cLoading.stroke(); //绘制
  1582. cLoading.closePath(); //路径结束
  1583. cLoading.restore();
  1584. };
  1585. cLoading.fillStyle = bBgColor;
  1586. cLoadingFillRect();
  1587. //定义中间暂停按钮的样式
  1588. var cPauseCenter = this.getByElement(pauseCenterID + '-canvas').getContext('2d');
  1589. var cPauseCenterFillRect = function () {
  1590. thisTemp.canvasFill(cPauseCenter, [
  1591. [28, 22],
  1592. [59, 38],
  1593. [28, 58]
  1594. ]);
  1595. /* 指定几个颜色 */
  1596. cPauseCenter.save();
  1597. cPauseCenter.lineWidth = 5; //设置线宽
  1598. cPauseCenter.beginPath(); //路径开始
  1599. cPauseCenter.arc(40, 40, 35, 0, 2 * Math.PI, false); //用于绘制圆弧context.arc(x坐标,y坐标,半径,起始角度,终止角度,顺时针/逆时针)
  1600. cPauseCenter.stroke(); //绘制
  1601. cPauseCenter.closePath(); //路径结束
  1602. cPauseCenter.restore();
  1603. };
  1604. cPauseCenter.fillStyle = bBgColor;
  1605. cPauseCenter.strokeStyle = bBgColor;
  1606. cPauseCenterFillRect();
  1607. var cPauseCenterOver = function () {
  1608. cPauseCenter.clearRect(0, 0, 80, 80);
  1609. cPauseCenter.fillStyle = bOverColor;
  1610. cPauseCenter.strokeStyle = bOverColor;
  1611. cPauseCenterFillRect();
  1612. };
  1613. var cPauseCenterOut = function () {
  1614. cPauseCenter.clearRect(0, 0, 80, 80);
  1615. cPauseCenter.fillStyle = bBgColor;
  1616. cPauseCenter.strokeStyle = bBgColor;
  1617. cPauseCenterFillRect();
  1618. };
  1619. this.addListenerInside('mouseover', cPauseCenterOver, this.getByElement(pauseCenterID + '-canvas'));
  1620. this.addListenerInside('mouseout', cPauseCenterOut, this.getByElement(pauseCenterID + '-canvas'));
  1621.  
  1622. //鼠标经过/离开音量调节按钮
  1623. var volumeBOOver = function () {
  1624. thisTemp.css(volumeBOID, 'backgroundColor', bOverColor);
  1625. thisTemp.css(volumeBWID, 'backgroundColor', bBgColor);
  1626. };
  1627. var volumeBOOut = function () {
  1628. thisTemp.css(volumeBOID, 'backgroundColor', bBgColor);
  1629. thisTemp.css(volumeBWID, 'backgroundColor', bOverColor);
  1630. };
  1631. this.addListenerInside('mouseover', volumeBOOver, this.getByElement(volumeBOID));
  1632. this.addListenerInside('mouseout', volumeBOOut, this.getByElement(volumeBOID));
  1633. //鼠标经过/离开进度按钮
  1634. var timeBOOver = function () {
  1635. thisTemp.css(timeBOID, 'backgroundColor', bOverColor);
  1636. thisTemp.css(timeBWID, 'backgroundColor', bBgColor);
  1637. };
  1638. var timeBOOut = function () {
  1639. thisTemp.css(timeBOID, 'backgroundColor', bBgColor);
  1640. thisTemp.css(timeBWID, 'backgroundColor', bOverColor);
  1641. };
  1642. this.addListenerInside('mouseover', timeBOOver, this.getByElement(timeBOID));
  1643. this.addListenerInside('mouseout', timeBOOut, this.getByElement(timeBOID));
  1644.  
  1645. this.addButtonEvent(); //注册按钮及音量调节,进度操作事件
  1646. this.newMenu(); //单独设置右键的样式和事件
  1647. this.controlBarHide(); //单独注册控制栏隐藏事件
  1648. this.keypress(); //单独注册键盘事件
  1649. //初始化音量调节框
  1650. this.changeVolume(this.vars['volume']);
  1651. //初始化判断是否需要显示上一集和下一集按钮
  1652. this.showFrontNext();
  1653. window.setTimeout(function () {
  1654. thisTemp.elementCoordinate(); //调整中间暂停按钮/loading的位置/error的位置
  1655. }, 100);
  1656. this.checkBarWidth();
  1657. var resize = function () {
  1658. thisTemp.elementCoordinate();
  1659. thisTemp.timeUpdateHandler();
  1660. thisTemp.changeLoad();
  1661. thisTemp.checkBarWidth();
  1662. thisTemp.changeElementCoor(); //修改新加元件的坐标
  1663. thisTemp.changePrompt();
  1664. };
  1665. this.addListenerInside('resize', resize, window);
  1666. },
  1667. /*
  1668. 内部函数
  1669. 创建按钮,使用canvas画布
  1670. */
  1671. newCanvas: function (id, width, height) {
  1672. return '<canvas class="' + id + '-canvas" width="' + width + '" height="' + height + '"></canvas>';
  1673. },
  1674. /*
  1675. 内部函数
  1676. 注册按钮,音量调节框,进度操作框事件
  1677. */
  1678. addButtonEvent: function () {
  1679. var thisTemp = this;
  1680. //定义按钮的单击事件
  1681. var playClick = function (event) {
  1682. thisTemp.videoPlay();
  1683. thisTemp.sendJS('clickEvent', 'actionScript->videoPlay');
  1684. };
  1685. this.addListenerInside('click', playClick, this.CB['play']);
  1686. this.addListenerInside('click', playClick, this.CB['pauseCenter']);
  1687. var pauseClick = function (event) {
  1688. thisTemp.videoPause();
  1689. thisTemp.sendJS('clickEvent', 'actionScript->videoPause');
  1690. };
  1691. this.addListenerInside('click', pauseClick, this.CB['pause']);
  1692. var frontClick = function (event) {
  1693. if (thisTemp.vars['front']) {
  1694. eval(thisTemp.vars['front'] + '()');
  1695. thisTemp.sendJS('clickEvent', 'actionScript->' + thisTemp.vars['front']);
  1696. }
  1697. };
  1698. this.addListenerInside('click', frontClick, this.CB['front']);
  1699. var nextClick = function (event) {
  1700. if (thisTemp.vars['next']) {
  1701. eval(thisTemp.vars['next'] + '()');
  1702. thisTemp.sendJS('clickEvent', 'actionScript->' + thisTemp.vars['next']);
  1703. }
  1704. };
  1705. this.addListenerInside('click', nextClick, this.CB['next']);
  1706. var muteClick = function (event) {
  1707. thisTemp.videoMute();
  1708. thisTemp.sendJS('clickEvent', 'actionScript->videoMute');
  1709. };
  1710. this.addListenerInside('click', muteClick, this.CB['mute']);
  1711. var escMuteClick = function (event) {
  1712. thisTemp.videoEscMute();
  1713. thisTemp.sendJS('clickEvent', 'actionScript->videoEscMute');
  1714. };
  1715. this.addListenerInside('click', escMuteClick, this.CB['escMute']);
  1716. var fullClick = function (event) {
  1717. thisTemp.fullScreen();
  1718. thisTemp.sendJS('clickEvent', 'actionScript->fullScreen');
  1719. };
  1720. this.addListenerInside('click', fullClick, this.CB['full']);
  1721. var escFullClick = function (event) {
  1722. thisTemp.quitFullScreen();
  1723. thisTemp.sendJS('clickEvent', 'actionScript->quitFullScreen');
  1724. };
  1725. this.addListenerInside('click', escFullClick, this.CB['escFull']);
  1726. //定义各个按钮的鼠标经过/离开事件
  1727. var promptHide = function (event) {
  1728. thisTemp.promptShow(false);
  1729. };
  1730. var playOver = function (event) {
  1731. thisTemp.promptShow(thisTemp.CB['play']);
  1732. };
  1733. this.addListenerInside('mouseover', playOver, this.CB['play']);
  1734. this.addListenerInside('mouseout', promptHide, this.CB['play']);
  1735. var pauseOver = function (event) {
  1736. thisTemp.promptShow(thisTemp.CB['pause']);
  1737. };
  1738. this.addListenerInside('mouseover', pauseOver, this.CB['pause']);
  1739. this.addListenerInside('mouseout', promptHide, this.CB['pause']);
  1740. var frontOver = function (event) {
  1741. thisTemp.promptShow(thisTemp.CB['front']);
  1742. };
  1743. this.addListenerInside('mouseover', frontOver, this.CB['front']);
  1744. this.addListenerInside('mouseout', promptHide, this.CB['front']);
  1745. var nextOver = function (event) {
  1746. thisTemp.promptShow(thisTemp.CB['next']);
  1747. };
  1748. this.addListenerInside('mouseover', nextOver, this.CB['next']);
  1749. this.addListenerInside('mouseout', promptHide, this.CB['next']);
  1750. var muteOver = function (event) {
  1751. thisTemp.promptShow(thisTemp.CB['mute']);
  1752. };
  1753. this.addListenerInside('mouseover', muteOver, this.CB['mute']);
  1754. this.addListenerInside('mouseout', promptHide, this.CB['mute']);
  1755. var escMuteOver = function (event) {
  1756. thisTemp.promptShow(thisTemp.CB['escMute']);
  1757. };
  1758. this.addListenerInside('mouseover', escMuteOver, this.CB['escMute']);
  1759. this.addListenerInside('mouseout', promptHide, this.CB['escMute']);
  1760. var fullOver = function (event) {
  1761. thisTemp.promptShow(thisTemp.CB['full']);
  1762. };
  1763. this.addListenerInside('mouseover', fullOver, this.CB['full']);
  1764. this.addListenerInside('mouseout', promptHide, this.CB['full']);
  1765. var escFullOver = function (event) {
  1766. thisTemp.promptShow(thisTemp.CB['escFull']);
  1767. };
  1768. this.addListenerInside('mouseover', escFullOver, this.CB['escFull']);
  1769. this.addListenerInside('mouseout', promptHide, this.CB['escFull']);
  1770. var definitionOver = function (event) {
  1771. thisTemp.promptShow(thisTemp.CB['definition']);
  1772. };
  1773. this.addListenerInside('mouseover', definitionOver, this.CB['definition']);
  1774. this.addListenerInside('mouseout', promptHide, this.CB['definition']);
  1775. var playbackrateOver = function (event) {
  1776. thisTemp.promptShow(thisTemp.CB['playbackrate']);
  1777. };
  1778. this.addListenerInside('mouseover', playbackrateOver, this.CB['playbackrate']);
  1779. this.addListenerInside('mouseout', promptHide, this.CB['playbackrate']);
  1780. //定义音量和进度按钮的滑块事件
  1781.  
  1782. var volumePrompt = function (vol) {
  1783. var volumeBOXY = thisTemp.getCoor(thisTemp.CB['volumeBO']);
  1784. var promptObj = {
  1785. title: thisTemp.language['volume'] + vol + '%',
  1786. x: volumeBOXY['x'] + thisTemp.CB['volumeBO'].offsetWidth * 0.5,
  1787. y: volumeBOXY['y']
  1788. };
  1789. thisTemp.promptShow(false, promptObj);
  1790. };
  1791. var volumeObj = {
  1792. slider: this.CB['volumeBO'],
  1793. follow: this.CB['volumeUp'],
  1794. refer: this.CB['volumeBg'],
  1795. grossValue: 'volume',
  1796. pd: true,
  1797. startFun: function (vol) {},
  1798. monitorFun: function (vol) {
  1799. thisTemp.changeVolume(vol * 0.01, false, false);
  1800. volumePrompt(vol);
  1801. },
  1802. endFun: function (vol) {},
  1803. overFun: function (vol) {
  1804. volumePrompt(vol);
  1805. }
  1806. };
  1807. this.slider(volumeObj);
  1808. var volumeClickObj = {
  1809. refer: this.CB['volumeBg'],
  1810. grossValue: 'volume',
  1811. fun: function (vol) {
  1812. thisTemp.changeVolume(vol * 0.01, true, true);
  1813. }
  1814. };
  1815. this.progressClick(volumeClickObj);
  1816. this.timeButtonMouseDown(); //用单击的函数来判断是否需要建立控制栏监听
  1817. //鼠标经过/离开音量调节框时的
  1818. var volumeBgMove = function (event) {
  1819. var volumeBgXY = thisTemp.getCoor(thisTemp.CB['volumeBg']);
  1820. var eventX = thisTemp.client(event)['x'];
  1821. var eventVolume = parseInt((eventX - volumeBgXY['x']) * 100 / thisTemp.CB['volumeBg'].offsetWidth);
  1822. var buttonPromptObj = {
  1823. title: thisTemp.language['volume'] + eventVolume + '%',
  1824. x: eventX,
  1825. y: volumeBgXY['y']
  1826. };
  1827. thisTemp.promptShow(false, buttonPromptObj);
  1828. };
  1829. this.addListenerInside('mousemove', volumeBgMove, this.CB['volumeBg']);
  1830. this.addListenerInside('mouseout', promptHide, this.CB['volumeBg']);
  1831. this.addListenerInside('mouseout', promptHide, this.CB['volumeBO']);
  1832. //注册清晰度相关事件
  1833. this.addDefListener();
  1834. //注册倍速相关事件
  1835. this.addPlaybackrate();
  1836. },
  1837. /*
  1838. 内部函数
  1839. 注册单击视频动作
  1840. */
  1841. videoClick: function () {
  1842. var thisTemp = this;
  1843. var clearTimerClick = function () {
  1844. if (thisTemp.timerClick != null) {
  1845. if (thisTemp.timerClick.runing) {
  1846. thisTemp.timerClick.stop();
  1847. }
  1848. thisTemp.timerClick = null;
  1849. }
  1850. };
  1851. var timerClickFun = function () {
  1852. clearTimerClick();
  1853. thisTemp.isClick = false;
  1854. thisTemp.playOrPause();
  1855.  
  1856. };
  1857. clearTimerClick();
  1858. if (this.isClick) {
  1859. this.isClick = false;
  1860. if (thisTemp.config['videoDbClick']) {
  1861. if (!this.full) {
  1862. thisTemp.fullScreen();
  1863. } else {
  1864. thisTemp.quitFullScreen();
  1865. }
  1866. }
  1867.  
  1868. } else {
  1869. this.isClick = true;
  1870. this.timerClick = new this.timer(300, timerClickFun, 1)
  1871. //this.timerClick.start();
  1872. }
  1873.  
  1874. },
  1875. /*
  1876. 内部函数
  1877. 注册鼠标经过进度滑块的事件
  1878. */
  1879. timeButtonMouseDown: function () {
  1880. var thisTemp = this;
  1881. var timePrompt = function (time) {
  1882. if (isNaN(time)) {
  1883. time = 0;
  1884. }
  1885. var timeButtonXY = thisTemp.getCoor(thisTemp.CB['timeButton']);
  1886. var promptObj = {
  1887. title: thisTemp.formatTime(time),
  1888. x: timeButtonXY['x'] - thisTemp.pdCoor['x'] + thisTemp.CB['timeButton'].offsetWidth * 0.5,
  1889. y: timeButtonXY['y'] - thisTemp.pdCoor['y']
  1890. };
  1891. thisTemp.promptShow(false, promptObj);
  1892. };
  1893. var timeObj = {
  1894. slider: this.CB['timeButton'],
  1895. follow: this.CB['timeProgress'],
  1896. refer: this.CB['timeBoBg'],
  1897. grossValue: 'time',
  1898. pd: false,
  1899. startFun: function (time) {
  1900. thisTemp.isTimeButtonMove = false;
  1901. },
  1902. monitorFun: function (time) {},
  1903. endFun: function (time) {
  1904. if (thisTemp.V) {
  1905. if (thisTemp.V.duration > 0) {
  1906. thisTemp.needSeek = 0;
  1907. thisTemp.videoSeek(parseInt(time));
  1908. }
  1909. }
  1910. },
  1911. overFun: function (time) {
  1912. timePrompt(time);
  1913. }
  1914. };
  1915. var timeClickObj = {
  1916. refer: this.CB['timeBoBg'],
  1917. grossValue: 'time',
  1918. fun: function (time) {
  1919. if (thisTemp.V) {
  1920. if (thisTemp.V.duration > 0) {
  1921. thisTemp.needSeek = 0;
  1922. thisTemp.videoSeek(parseInt(time));
  1923. }
  1924. }
  1925. }
  1926. };
  1927. var timeBoBgmousemove = function (event) {
  1928. var timeBoBgXY = thisTemp.getCoor(thisTemp.CB['timeBoBg']);
  1929. var eventX = thisTemp.client(event)['x'];
  1930. var eventTime = parseInt((eventX - timeBoBgXY['x']) * thisTemp.V.duration / thisTemp.CB['timeBoBg'].offsetWidth);
  1931. var buttonPromptObj = {
  1932. title: thisTemp.formatTime(eventTime),
  1933. x: eventX,
  1934. y: timeBoBgXY['y']
  1935. };
  1936. thisTemp.promptShow(false, buttonPromptObj);
  1937. var def = false;
  1938. if (!thisTemp.isUndefined(thisTemp.CB['definitionP'])) {
  1939. if (thisTemp.css(thisTemp.CB['definitionP'], 'display') != 'block') {
  1940. def = true;
  1941. }
  1942. }
  1943. if (thisTemp.vars['preview'] != null && def) {
  1944. buttonPromptObj['time'] = eventTime;
  1945. thisTemp.preview(buttonPromptObj);
  1946. }
  1947. };
  1948. var promptHide = function (event) {
  1949. thisTemp.promptShow(false);
  1950. if (thisTemp.previewDiv != null) {
  1951. thisTemp.css([thisTemp.previewDiv, thisTemp.previewTop], 'display', 'none');
  1952. }
  1953. };
  1954. if (!this.vars['live']) { //如果不是直播
  1955. this.isTimeButtonDown = true;
  1956. this.addListenerInside('mousemove', timeBoBgmousemove, this.CB['timeBoBg']);
  1957. this.addListenerInside('mouseout', promptHide, this.CB['timeBoBg']);
  1958. } else {
  1959. this.isTimeButtonDown = false;
  1960. timeObj['removeListenerInside'] = true;
  1961. timeClickObj['removeListenerInside'] = true;
  1962. }
  1963. this.slider(timeObj);
  1964. this.progressClick(timeClickObj);
  1965.  
  1966. },
  1967. /*
  1968. 内部函数
  1969. 注册调节框上单击事件,包含音量调节框和播放时度调节框
  1970. */
  1971. progressClick: function (obj) {
  1972. /*
  1973. refer:参考对象
  1974. fun:返回函数
  1975. refer:参考元素,即背景
  1976. grossValue:调用的参考值类型
  1977. pd:
  1978. */
  1979. //建立参考元素的mouseClick事件,用来做为鼠标在其上按下时触发的状态
  1980. var thisTemp = this;
  1981. var referMouseClick = function (event) {
  1982. var referX = thisTemp.client(event)['x'] - thisTemp.getCoor(obj['refer'])['x'];
  1983. var rWidth = obj['refer'].offsetWidth;
  1984. var grossValue = 0;
  1985. if (obj['grossValue'] == 'volume') {
  1986. grossValue = 100;
  1987. } else {
  1988. if (thisTemp.V) {
  1989. grossValue = thisTemp.V.duration;
  1990. }
  1991. }
  1992. var nowZ = parseInt(referX * grossValue / rWidth);
  1993. if (obj['fun']) {
  1994. if (obj['grossValue'] === 'time') {
  1995. var sliderXY = thisTemp.getCoor(thisTemp.CB['timeButton']);
  1996. sliderLeft = sliderXY['x'];
  1997. if (!thisTemp.checkSlideLeft(referX, sliderLeft, rWidth)) {
  1998. return;
  1999. }
  2000. var bimeButtonWB = thisTemp.CB['timeButton'].offsetWidth * 0.5;
  2001. thisTemp.css(thisTemp.CB['timeButton'], 'left', (referX - bimeButtonWB) + 'px');
  2002. thisTemp.css(thisTemp.CB['timeProgress'], 'width', (referX) + 'px');
  2003. }
  2004. obj['fun'](nowZ);
  2005. }
  2006. };
  2007. if (this.isUndefined(obj['removeListenerInside'])) {
  2008. this.addListenerInside('click', referMouseClick, obj['refer']);
  2009. } else {
  2010. this.removeListenerInside('click', referMouseClick, obj['refer']);
  2011. }
  2012.  
  2013. },
  2014.  
  2015. /*
  2016. 内部函数
  2017. 共用的注册滑块事件
  2018. */
  2019. slider: function (obj) {
  2020. /*
  2021. obj={
  2022. slider:滑块元素
  2023. follow:跟随滑块的元素
  2024. refer:参考元素,即背景
  2025. grossValue:调用的参考值类型
  2026. startFun:开始调用的元素
  2027. monitorFun:监听函数
  2028. endFun:结束调用的函数
  2029. overFun:鼠标放上去后调用的函数
  2030. pd:是否需要修正
  2031. }
  2032. */
  2033. var thisTemp = this;
  2034. var clientX = 0,
  2035. criterionWidth = 0,
  2036. sliderLeft = 0,
  2037. referLeft = 0;
  2038. var value = 0;
  2039. var calculation = function () { //根据滑块的left计算百分比
  2040. var sLeft = parseInt(thisTemp.css(obj['slider'], 'left'));
  2041. var rWidth = obj['refer'].offsetWidth - obj['slider'].offsetWidth;
  2042. var grossValue = 0;
  2043. if (thisTemp.isUndefined(sLeft) || isNaN(sLeft)) {
  2044. sLeft = 0;
  2045. }
  2046. if (obj['grossValue'] == 'volume') {
  2047. grossValue = 100;
  2048. } else {
  2049. if (thisTemp.V) {
  2050. grossValue = thisTemp.V.duration;
  2051. }
  2052. }
  2053. return parseInt(sLeft * grossValue / rWidth);
  2054. };
  2055. var mDown = function (event) {
  2056. thisTemp.addListenerInside('mousemove', mMove, document);
  2057. thisTemp.addListenerInside('mouseup', mUp, document);
  2058. var referXY = thisTemp.getCoor(obj['refer']);
  2059. var sliderXY = thisTemp.getCoor(obj['slider']);
  2060. clientX = thisTemp.client(event)['x'];
  2061. referLeft = referXY['x'];
  2062. sliderLeft = sliderXY['x'];
  2063. criterionWidth = clientX - sliderLeft;
  2064. if (obj['startFun']) {
  2065. obj['startFun'](calculation());
  2066. }
  2067. };
  2068. var mMove = function (event) {
  2069. clientX = thisTemp.client(event)['x'];
  2070. var newX = clientX - criterionWidth - referLeft;
  2071. if (newX < 0) {
  2072. newX = 0;
  2073. }
  2074. if (newX > obj['refer'].offsetWidth - obj['slider'].offsetWidth) {
  2075. newX = obj['refer'].offsetWidth - obj['slider'].offsetWidth;
  2076. }
  2077. if (obj['slider'] === thisTemp.CB['timeButton']) {
  2078. if (!thisTemp.checkSlideLeft(newX, sliderLeft, obj['refer'].offsetWidth)) {
  2079. return;
  2080. }
  2081. }
  2082. thisTemp.css(obj['slider'], 'left', newX + 'px');
  2083. thisTemp.css(obj['follow'], 'width', (newX + obj['slider'].offsetWidth * 0.5) + 'px');
  2084. var nowZ = calculation();
  2085. if (obj['monitorFun']) {
  2086. obj['monitorFun'](nowZ);
  2087. }
  2088. };
  2089. var mUp = function (event) {
  2090. thisTemp.removeListenerInside('mousemove', mMove, document);
  2091. thisTemp.removeListenerInside('mouseup', mUp, document);
  2092. if (obj['endFun']) {
  2093. obj['endFun'](calculation());
  2094. }
  2095. };
  2096. var mOver = function (event) {
  2097. if (obj['overFun']) {
  2098. obj['overFun'](calculation());
  2099. }
  2100.  
  2101. };
  2102. if (this.isUndefined(obj['removeListenerInside'])) {
  2103. this.addListenerInside('mousedown', mDown, obj['slider']);
  2104. this.addListenerInside('mouseover', mOver, obj['slider']);
  2105. } else {
  2106. this.removeListenerInside('mousedown', mDown, obj['slider']);
  2107. this.removeListenerInside('mouseover', mOver, obj['slider']);
  2108. }
  2109. },
  2110. /*
  2111. 内部函数
  2112. 判断是否可以拖动进度按钮或点击进度栏
  2113. */
  2114. checkSlideLeft: function (newX, sliderLeft, refer) {
  2115. var timeSA = this.ckplayerConfig['config']['timeScheduleAdjust'];
  2116. switch (timeSA) {
  2117. case 0:
  2118. return false;
  2119. break;
  2120. case 2:
  2121. if (newX < sliderLeft) {
  2122. return false;
  2123. }
  2124. break;
  2125. case 3:
  2126. if (newX > sliderLeft) {
  2127. return false;
  2128. }
  2129. break;
  2130. case 4:
  2131. if (!this.timeSliderLeftTemp) {
  2132. this.timeSliderLeftTemp = sliderLeft / refer;
  2133. }
  2134. if (newX < this.timeSliderLeftTemp * refer) {
  2135. return false;
  2136. }
  2137. break;
  2138. case 5:
  2139. if (!this.timeSliderLeftTemp) {
  2140. this.timeSliderLeftTemp = sliderLeft / refer;
  2141. } else {
  2142. var timeSliderMax = sliderLeft / refer;
  2143. if (timeSliderMax > this.timeSliderLeftTemp) {
  2144. this.timeSliderLeftTemp = timeSliderMax;
  2145. }
  2146. }
  2147. if (newX > this.timeSliderLeftTemp * refer) {
  2148. return false;
  2149. }
  2150. break;
  2151. default:
  2152. return true;
  2153. break;
  2154. }
  2155. return true;
  2156. },
  2157. /*
  2158. 内部函数
  2159. 显示loading
  2160. */
  2161. loadingStart: function (rot) {
  2162. var thisTemp = this;
  2163. if (this.isUndefined(rot)) {
  2164. rot = true;
  2165. }
  2166. if (this.showFace) {
  2167. this.css(thisTemp.CB['loading'], 'display', 'none');
  2168. }
  2169. if (this.timerLoading != null) {
  2170. if (this.timerLoading.runing) {
  2171. this.timerLoading.stop();
  2172. }
  2173. this.timerLoading = null;
  2174. }
  2175. var buffer = 0;
  2176. var loadingFun = function () {
  2177. var nowRotate = '0';
  2178. try {
  2179. 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';
  2180. } catch (event) {
  2181. }
  2182. nowRotate = parseInt(nowRotate.replace('rotate(', '').replace('deg);', ''));
  2183. nowRotate += 4;
  2184. if (nowRotate > 360) {
  2185. nowRotate = 0;
  2186. }
  2187. if (thisTemp.showFace) {
  2188. thisTemp.css(thisTemp.CB['loadingCanvas'], {
  2189. transform: 'rotate(' + nowRotate + 'deg)',
  2190. msTransform: 'rotate(' + nowRotate + 'deg)',
  2191. mozTransform: 'rotate(' + nowRotate + 'deg)',
  2192. webkitTransform: 'rotate(' + nowRotate + 'deg)',
  2193. oTransform: 'rotate(' + nowRotate + 'deg)'
  2194. });
  2195. }
  2196. buffer++;
  2197. if (buffer >= 99) {
  2198. buffer = 99;
  2199. }
  2200. thisTemp.sendJS('buffer', buffer);
  2201. };
  2202. if (rot) {
  2203. this.timerLoading = new this.timer(10, loadingFun);
  2204. //this.timerLoading.start();
  2205. if (this.showFace) {
  2206. this.css(thisTemp.CB['loading'], 'display', 'block');
  2207. }
  2208. } else {
  2209. thisTemp.sendJS('buffer', 100);
  2210. }
  2211. },
  2212. /*
  2213. 内部函数
  2214. 判断是否需要显示上一集和下一集
  2215. */
  2216. showFrontNext: function () {
  2217. if (!this.showFace) {
  2218. return;
  2219. }
  2220. if (this.vars['front']) {
  2221. this.css([this.CB['front'], this.CB['frontLine']], 'display', 'block');
  2222. } else {
  2223. this.css([this.CB['front'], this.CB['frontLine']], 'display', 'none');
  2224. }
  2225. if (this.vars['next']) {
  2226. this.css([this.CB['next'], this.CB['nextLine']], 'display', 'block');
  2227. } else {
  2228. this.css([this.CB['next'], this.CB['nextLine']], 'display', 'none');
  2229. }
  2230. },
  2231. /*
  2232. 内部函数
  2233. 显示提示语
  2234. */
  2235. promptShow: function (ele, data) {
  2236. if (!this.showFace) {
  2237. return;
  2238. }
  2239. var obj = {};
  2240. if (ele || data) {
  2241. if (!this.isUndefined(data)) {
  2242. obj = data;
  2243. } else {
  2244. var offsetCoor = this.getCoor(ele);
  2245. obj = {
  2246. title: this.getDataset(ele, 'title'),
  2247. x: offsetCoor['x'] + ele.offsetWidth * 0.5,
  2248. y: offsetCoor['y']
  2249. };
  2250. }
  2251. this.CB['prompt'].innerHTML = obj['title'];
  2252. this.css(this.CB['prompt'], 'display', 'block');
  2253. var promoptWidth = this.getStringLen(obj['title']) * 10;
  2254. this.css(this.CB['promptBg'], 'width', promoptWidth + 'px');
  2255. this.css(this.CB['prompt'], 'width', promoptWidth + 'px');
  2256. promoptWidth += 10;
  2257. var x = obj['x'] - (promoptWidth * 0.5);
  2258. var y = this.PD.offsetHeight - obj['y'] + 8;
  2259. if (x < 0) {
  2260. x = 0;
  2261. }
  2262. if (x > this.PD.offsetWidth - promoptWidth) {
  2263. x = this.PD.offsetWidth - promoptWidth;
  2264. }
  2265. this.css([this.CB['promptBg'], this.CB['prompt']], {
  2266. display: 'block',
  2267. left: x + 'px',
  2268. bottom: y + 'px'
  2269. });
  2270. } else {
  2271. this.css([this.CB['promptBg'], this.CB['prompt']], {
  2272. display: 'none'
  2273. });
  2274. }
  2275. },
  2276. /*
  2277. 内部函数
  2278. 监听错误
  2279. */
  2280. timerErrorFun: function () {
  2281. var thisTemp = this;
  2282. this.errorSend = false;
  2283. var clearIntervalError = function (event) {
  2284. if (thisTemp.timerError != null) {
  2285. if (thisTemp.timerError.runing) {
  2286. thisTemp.timerError.stop();
  2287. }
  2288. thisTemp.timerError = null;
  2289. }
  2290. };
  2291. var errorFun = function (event) {
  2292. clearIntervalError();
  2293. thisTemp.error = true;
  2294. //提取错误播放地址
  2295. thisTemp.errorUrl = thisTemp.getVideoUrl();
  2296. //提取错误播放地址结束
  2297. if (!thisTemp.errorSend) {
  2298. thisTemp.errorSend = true;
  2299. thisTemp.sendJS('error');
  2300. }
  2301. if (thisTemp.showFace) {
  2302. thisTemp.css(thisTemp.CB['errorText'], 'display', 'block');
  2303. thisTemp.css(thisTemp.CB['pauseCenter'], 'display', 'none');
  2304. thisTemp.css(thisTemp.CB['loading'], 'display', 'none');
  2305. }
  2306. thisTemp.V.removeAttribute('poster');
  2307. thisTemp.resetPlayer();
  2308. };
  2309. var errorListenerFun = function (event) {
  2310. window.setTimeout(function () {
  2311. if (isNaN(thisTemp.V.duration)) {
  2312. errorFun(event);
  2313. }
  2314. }, 500);
  2315.  
  2316. };
  2317. if (!this.errorAdd) {
  2318. this.errorAdd = true;
  2319. this.addListenerInside('error', errorListenerFun, this.V);
  2320. }
  2321. clearIntervalError();
  2322. var timerErrorFun = function () {
  2323. if (thisTemp.V && parseInt(thisTemp.V.networkState) == 3) {
  2324. errorFun();
  2325. }
  2326. };
  2327. this.timerError = new this.timer(this.config['errorTime'], timerErrorFun);
  2328. //this.timerError.start();
  2329. },
  2330. /*
  2331. 内部函数
  2332. 构建判断全屏还是非全屏的判断
  2333. */
  2334. judgeFullScreen: function () {
  2335. var thisTemp = this;
  2336. if (this.timerFull != null) {
  2337. if (this.timerFull.runing) {
  2338. this.timerFull.stop();
  2339. }
  2340. this.timerFull = null;
  2341. }
  2342. var fullFun = function () {
  2343. thisTemp.isFullScreen();
  2344. };
  2345. this.timerFull = new this.timer(20, fullFun);
  2346. },
  2347. /*
  2348. 内部函数
  2349. 判断是否是全屏
  2350. */
  2351. isFullScreen: function () {
  2352. if (!this.showFace) {
  2353. return;
  2354. }
  2355. var fullState = document.fullScreen || document.mozFullScreen || document.webkitIsFullScreen || document.msFullscreenElement;
  2356. if (fullState && !this.full) {
  2357. this.full = true;
  2358. this.sendJS('full', true);
  2359. this.elementCoordinate();
  2360. this.css(this.CB['full'], 'display', 'none');
  2361. this.css(this.CB['escFull'], 'display', 'block');
  2362. if (this.vars['live'] == 0) {
  2363. this.timeUpdateHandler();
  2364. }
  2365. this.PD.appendChild(this.CB['menu']);
  2366. }
  2367. if (!fullState && this.full) {
  2368. this.full = false;
  2369. this.sendJS('full', false);
  2370. this.elementCoordinate();
  2371. this.css(this.CB['full'], 'display', 'block');
  2372. this.css(this.CB['escFull'], 'display', 'none');
  2373. if (this.timerFull != null) {
  2374. if (this.timerFull.runing) {
  2375. this.timerFull.stop();
  2376. }
  2377. this.timerFull = null;
  2378. }
  2379. if (this.vars['live'] == 0) {
  2380. this.timeUpdateHandler();
  2381. }
  2382. this.body.appendChild(this.CB['menu']);
  2383. }
  2384. },
  2385. /*
  2386. 内部函数
  2387. 构建右键内容及注册相关动作事件
  2388. */
  2389. newMenu: function () {
  2390. var thisTemp = this;
  2391. var i = 0;
  2392. this.css(this.CB['menu'], {
  2393. backgroundColor: '#FFFFFF',
  2394. padding: '5px',
  2395. position: 'absolute',
  2396. left: '10px',
  2397. top: '20px',
  2398. display: 'none',
  2399. zIndex: '999',
  2400. color: '#A1A9BE',
  2401. boxShadow: '2px 2px 3px #AAAAAA'
  2402. });
  2403. var mArr = this.contextMenu;
  2404. var cMenu = this.ckplayerConfig['menu'];
  2405. if (cMenu['name']) {
  2406. if (cMenu['link']) {
  2407. mArr[0] = [cMenu['name'], 'link', cMenu['link']];
  2408. } else {
  2409. mArr[0] = [cMenu['name'], 'default'];
  2410. }
  2411. }
  2412. if (cMenu['version']) {
  2413. mArr[1] = [cMenu['version'], 'default', 'line'];
  2414. }
  2415. if (cMenu['more']) {
  2416. if (typeof (cMenu['more']) == 'object') {
  2417. if (cMenu['more'].length > 0) {
  2418. var moreArr = cMenu['more'];
  2419. for (i = 0; i < moreArr.length; i++) {
  2420. var mTemp = moreArr[i];
  2421. var arrTemp = [];
  2422. if (mTemp['name']) {
  2423. arrTemp.push(mTemp['name']);
  2424. }
  2425. if (mTemp['clickEvent'] && mTemp['clickEvent'] != 'none') {
  2426. var eveObj = this.clickEvent(mTemp['clickEvent']);
  2427. arrTemp.push(eveObj['type']);
  2428. if (eveObj['fun']) {
  2429. arrTemp.push(eveObj['fun']);
  2430. }
  2431. if (eveObj['link']) {
  2432. arrTemp.push(eveObj['link']);
  2433. }
  2434. if (eveObj['target']) {
  2435. arrTemp.push(' target="' + eveObj['target'] + '"');
  2436. }
  2437. }
  2438. if (mTemp['separatorBefore']) {
  2439. arrTemp.push('line');
  2440. }
  2441. mArr.push(arrTemp);
  2442. }
  2443. }
  2444. }
  2445. }
  2446. var html = '';
  2447. for (i = 0; i < mArr.length; i++) {
  2448. var me = mArr[i];
  2449. switch (me[1]) {
  2450. case 'default':
  2451. html += '<p>' + me[0] + '</p>';
  2452. break;
  2453. case 'link':
  2454. html += '<p><a href="' + me[2] + '"' + me[3] + '>' + me[0] + '</a></p>';
  2455. break;
  2456. case 'javaScript':
  2457. html += '<p><a href="javascript:' + me[2] + '">' + me[0] + '</a></p>';
  2458. break;
  2459. case 'actionScript':
  2460. html += '<p><a href="javascript:' + this.vars['variable'] + me[2].replace('thisTemp', '') + '">' + me[0] + '</a></p>';
  2461. break;
  2462. default:
  2463. break;
  2464. }
  2465. }
  2466. this.CB['menu'].innerHTML = html;
  2467. var pArr = this.CB['menu'].childNodes;
  2468. for (i = 0; i < pArr.length; i++) {
  2469. this.css(pArr[i], {
  2470. height: '30px',
  2471. lineHeight: '30px',
  2472. margin: '0px',
  2473. fontFamily: this.fontFamily,
  2474. fontSize: '12px',
  2475. paddingLeft: '10px',
  2476. paddingRight: '30px'
  2477. });
  2478. if (mArr[i][mArr[i].length - 1] == 'line') {
  2479. this.css(pArr[i], 'borderBottom', '1px solid #e9e9e9');
  2480. }
  2481. var aArr = pArr[i].childNodes;
  2482. for (var n = 0; n < aArr.length; n++) {
  2483. if (aArr[n].localName == 'a') {
  2484. this.css(aArr[n], {
  2485. color: '#000000',
  2486. textDecoration: 'none'
  2487. });
  2488. }
  2489. }
  2490. }
  2491. this.PD.oncontextmenu = function (event) {
  2492. var eve = event || window.event;
  2493. var client = thisTemp.client(event);
  2494. if (eve.button == 2) {
  2495. eve.returnvalue = false;
  2496. var x = client['x'] + thisTemp.pdCoor['x'] - 2;
  2497. var y = client['y'] + thisTemp.pdCoor['y'] - 2;
  2498. thisTemp.css(thisTemp.CB['menu'], {
  2499. display: 'block',
  2500. left: x + 'px',
  2501. top: y + 'px'
  2502. });
  2503. return false;
  2504. }
  2505. return true;
  2506. };
  2507. var setTimeOutPClose = function () {
  2508. if (setTimeOutP) {
  2509. window.clearTimeout(setTimeOutP);
  2510. setTimeOutP = null;
  2511. }
  2512. };
  2513. var setTimeOutP = null;
  2514. var mouseOut = function (event) {
  2515. setTimeOutPClose();
  2516. setTimeOutP = window.setTimeout(function (event) {
  2517. thisTemp.css(thisTemp.CB['menu'], 'display', 'none');
  2518. }, 500);
  2519. };
  2520. this.addListenerInside('mouseout', mouseOut, thisTemp.CB['menu']);
  2521. var mouseOver = function (event) {
  2522. setTimeOutPClose();
  2523. };
  2524. this.addListenerInside('mouseover', mouseOver, thisTemp.CB['menu']);
  2525.  
  2526. },
  2527. /*
  2528. 内部函数
  2529. 构建控制栏隐藏事件
  2530. */
  2531. controlBarHide: function (hide) {
  2532. var thisTemp = this;
  2533. var client = {
  2534. x: 0,
  2535. y: 0
  2536. },
  2537. oldClient = {
  2538. x: 0,
  2539. y: 0
  2540. };
  2541. var cShow = true,
  2542. force = false;
  2543. var oldCoor = [0, 0];
  2544. var controlBarShow = function (show) {
  2545. if (show && !cShow && thisTemp.controlBarIsShow) {
  2546. cShow = true;
  2547. thisTemp.sendJS('controlBar', true);
  2548. thisTemp.css(thisTemp.CB['controlBarBg'], 'display', 'block');
  2549. thisTemp.css(thisTemp.CB['controlBar'], 'display', 'block');
  2550. thisTemp.css(thisTemp.CB['timeProgressBg'], 'display', 'block');
  2551. thisTemp.css(thisTemp.CB['timeBoBg'], 'display', 'block');
  2552. thisTemp.changeVolume(thisTemp.volume);
  2553. thisTemp.changeLoad();
  2554. if (!thisTemp.timerBuffer) {
  2555. thisTemp.bufferEdHandler();
  2556. }
  2557. } else {
  2558. if (cShow) {
  2559. cShow = false;
  2560. var paused = thisTemp.getMetaDate()['paused'];
  2561. if (force) {
  2562. paused = false;
  2563. }
  2564. if (!paused) {
  2565. thisTemp.sendJS('controlBar', false);
  2566. thisTemp.css(thisTemp.CB['controlBarBg'], 'display', 'none');
  2567. thisTemp.css(thisTemp.CB['controlBar'], 'display', 'none');
  2568. thisTemp.css(thisTemp.CB['timeProgressBg'], 'display', 'none');
  2569. thisTemp.css(thisTemp.CB['timeBoBg'], 'display', 'none');
  2570. thisTemp.promptShow(false);
  2571.  
  2572. }
  2573. }
  2574. }
  2575. };
  2576. var cbarFun = function (event) {
  2577. if (client['x'] == oldClient['x'] && client['y'] == oldClient['y']) {
  2578. var cdH = parseInt(thisTemp.CD.offsetHeight);
  2579. if ((client['y'] < cdH - 50 || client['y'] > cdH - 2) && cShow) {
  2580. controlBarShow(false);
  2581. }
  2582. } else {
  2583. if (!cShow) {
  2584. controlBarShow(true);
  2585. }
  2586. }
  2587. oldClient = {
  2588. x: client['x'],
  2589. y: client['y']
  2590. }
  2591. };
  2592. this.timerCBar = new this.timer(2000, cbarFun);
  2593. var cdMove = function (event) {
  2594. var getClient = thisTemp.client(event);
  2595. client['x'] = getClient['x'];
  2596. client['y'] = getClient['y'];
  2597. if (!cShow) {
  2598. controlBarShow(true);
  2599. }
  2600. };
  2601. this.addListenerInside('mousemove', cdMove, thisTemp.CD);
  2602. this.addListenerInside('ended', cdMove);
  2603. this.addListenerInside('resize', cdMove, window);
  2604. if (hide === true) {
  2605. cShow = true;
  2606. force = true;
  2607. controlBarShow(false);
  2608. }
  2609. if (hide === false) {
  2610. cShow = false;
  2611. force = true;
  2612. controlBarShow(true);
  2613. }
  2614. },
  2615.  
  2616. /*
  2617. 内部函数
  2618. 注册键盘按键事件
  2619. */
  2620. keypress: function () {
  2621. var thisTemp = this;
  2622. var keyDown = function (eve) {
  2623. var keycode = eve.keyCode || eve.which;
  2624. switch (keycode) {
  2625. case 32:
  2626. thisTemp.playOrPause();
  2627. break;
  2628. case 37:
  2629. thisTemp.fastBack();
  2630. break;
  2631. case 39:
  2632. thisTemp.fastNext();
  2633. break;
  2634. case 38:
  2635. now = thisTemp.volume + thisTemp.ckplayerConfig['config']['volumeJump'];
  2636. thisTemp.changeVolume(now > 1 ? 1 : now);
  2637. break;
  2638. case 40:
  2639. now = thisTemp.volume - thisTemp.ckplayerConfig['config']['volumeJump'];
  2640. thisTemp.changeVolume(now < 0 ? 0 : now);
  2641. break;
  2642. default:
  2643. break;
  2644. }
  2645. };
  2646. this.addListenerInside('keydown', keyDown, window || document);
  2647. },
  2648. /*
  2649. 内部函数
  2650. 注册倍速相关
  2651. */
  2652. playbackRate: function () {
  2653. if (!this.showFace) {
  2654. return;
  2655. }
  2656. var thisTemp = this;
  2657. var vArr = this.playbackRateArr;
  2658. var html = '';
  2659. var nowD = ''; //当前的清晰度
  2660. var i = 0;
  2661. if (!nowD) {
  2662. nowD = vArr[this.playbackRateDefault][1];
  2663. }
  2664. if (vArr.length > 1) {
  2665. var zlen = 0;
  2666. for (i = 0; i < vArr.length; i++) {
  2667. html = '<p>' + vArr[i][1] + '</p>' + html;
  2668. var dlen = this.getStringLen(vArr[i][1]);
  2669. if (dlen > zlen) {
  2670. zlen = dlen;
  2671. }
  2672. }
  2673. if (html) {
  2674. html += '<p>' + nowD + '</p>';
  2675. }
  2676. this.CB['playbackrate'].innerHTML = nowD;
  2677. this.CB['playbackrateP'].innerHTML = html;
  2678. this.css([this.CB['playbackrate'], this.CB['playbackrateLine']], 'display', 'block');
  2679. var pArr = this.CB['playbackrateP'].childNodes;
  2680. for (var i = 0; i < pArr.length; i++) {
  2681. var fontColor = '#FFFFFF';
  2682. if (pArr[i].innerHTML == nowD) {
  2683. fontColor = '#0782F5';
  2684. }
  2685. this.css(pArr[i], {
  2686. color: fontColor,
  2687. margin: '0px',
  2688. padding: '0px',
  2689. fontSize: '14px'
  2690. });
  2691. if (i < pArr.length - 1) {
  2692. this.css(pArr[i], 'borderBottom', '1px solid #282828')
  2693. }
  2694. var defClick = function (event) {
  2695. if (nowD != this.innerHTML) {
  2696. thisTemp.css(thisTemp.CB['playbackrateP'], 'display', 'none');
  2697. thisTemp.newPlaybackrate(this.innerHTML);
  2698. thisTemp.sendJS('clickEvent', 'actionScript->newPlaybackrate');
  2699. }
  2700. };
  2701. this.addListenerInside('click', defClick, pArr[i]);
  2702.  
  2703. }
  2704. var pW = (zlen * 10) + 20;
  2705. this.css(this.CB['playbackrateP'], {
  2706. width: pW + 'px'
  2707. });
  2708. this.css(this.CB['playbackrate'], {
  2709. width: pW + 'px'
  2710. });
  2711. this.buttonWidth['playbackrate'] = this.CB['playbackrate'].offsetWidth;
  2712. } else {
  2713. this.CB['playbackrate'].innerHTML = '';
  2714. this.CB['playbackrateP'].innerHTML = '';
  2715. this.css([this.CB['playbackrate'], this.CB['playbackrateLine']], 'display', 'none');
  2716. }
  2717. },
  2718. /*
  2719. 内部函数
  2720. 注册切换倍速播放相关事件
  2721. */
  2722. addPlaybackrate: function () {
  2723. var thisTemp = this;
  2724. var setTimeOutP = null;
  2725. var defClick = function (event) {
  2726. thisTemp.css(thisTemp.CB['playbackrateP'], {
  2727. left: thisTemp.getCoor(thisTemp.CB['playbackrate'])['x'] + 'px',
  2728. display: 'block'
  2729. });
  2730. };
  2731. this.addListenerInside('click', defClick, this.CB['playbackrate']);
  2732. var defMouseOut = function (event) {
  2733. if (setTimeOutP) {
  2734. window.clearTimeout(setTimeOutP);
  2735. setTimeOutP = null;
  2736. }
  2737. setTimeOutP = window.setTimeout(function (event) {
  2738. thisTemp.css(thisTemp.CB['playbackrateP'], 'display', 'none');
  2739. }, 500);
  2740. };
  2741. this.addListenerInside('mouseout', defMouseOut, thisTemp.CB['playbackrateP']);
  2742. var defMouseOver = function (event) {
  2743. if (setTimeOutP) {
  2744. window.clearTimeout(setTimeOutP);
  2745. setTimeOutP = null;
  2746. }
  2747. };
  2748. this.addListenerInside('mouseover', defMouseOver, thisTemp.CB['playbackrateP']);
  2749. },
  2750. /*
  2751. 内部函数
  2752. 切换倍速后发生的动作
  2753. */
  2754. newPlaybackrate: function (title) {
  2755. var vArr = this.playbackRateArr;
  2756. var nVArr = [];
  2757. var i = 0;
  2758. for (i = 0; i < vArr.length; i++) {
  2759. var v = vArr[i];
  2760. if (v[1] == title) {
  2761. this.playbackRateDefault = i;
  2762. this.V.playbackRate = v[0];
  2763. if (this.showFace) {
  2764. this.CB['playbackrate'].innerHTML = v[1];
  2765. this.playbackRate();
  2766. }
  2767. this.sendJS('playbackRate', v);
  2768. }
  2769. }
  2770. },
  2771.  
  2772. /*
  2773. 内部函数
  2774. 构建清晰度按钮及切换事件(Click事件)
  2775. */
  2776. definition: function () {
  2777. if (!this.showFace) {
  2778. return;
  2779. }
  2780. var thisTemp = this;
  2781. var vArr = this.VA;
  2782. var dArr = [];
  2783. var html = '';
  2784. var nowD = ''; //当前的清晰度
  2785. var i = 0;
  2786. for (i = 0; i < vArr.length; i++) {
  2787. var d = vArr[i][2];
  2788. if (dArr.indexOf(d) == -1) {
  2789. dArr.push(d);
  2790. }
  2791. if (this.V) {
  2792. if (vArr[i][0] == this.V.currentSrc) {
  2793. nowD = d;
  2794. }
  2795. }
  2796. }
  2797. if (!nowD) {
  2798. nowD = dArr[0];
  2799. }
  2800. if (dArr.length > 1) {
  2801. var zlen = 0;
  2802. for (i = dArr.length - 1; i > -1; i--) {
  2803. html = '<p>' + dArr[i] + '</p>' + html;
  2804. var dlen = this.getStringLen(dArr[i]);
  2805. if (dlen > zlen) {
  2806. zlen = dlen;
  2807. }
  2808. }
  2809. if (html) {
  2810. html += '<p>' + nowD + '</p>';
  2811. }
  2812. this.CB['definition'].innerHTML = nowD;
  2813. this.CB['definitionP'].innerHTML = html;
  2814. this.css([this.CB['definition'], this.CB['definitionLine']], 'display', 'block');
  2815. var pArr = this.CB['definitionP'].childNodes;
  2816. for (var i = 0; i < pArr.length; i++) {
  2817. var fontColor = '#FFFFFF';
  2818. if (pArr[i].innerHTML == nowD) {
  2819. fontColor = '#0782F5';
  2820. }
  2821. this.css(pArr[i], {
  2822. color: fontColor,
  2823. margin: '0px',
  2824. padding: '0px',
  2825. fontSize: '14px'
  2826. });
  2827. if (i < pArr.length - 1) {
  2828. this.css(pArr[i], 'borderBottom', '1px solid #282828')
  2829. }
  2830. var defClick = function () {
  2831. if (nowD != this.innerHTML) {
  2832. thisTemp.css(thisTemp.CB['definitionP'], 'display', 'none');
  2833. thisTemp.newDefinition(this.innerHTML);
  2834. }
  2835. };
  2836. this.addListenerInside('click', defClick, pArr[i]);
  2837.  
  2838. }
  2839. var pW = (zlen * 10) + 20;
  2840. this.css(this.CB['definitionP'], {
  2841. width: pW + 'px'
  2842. });
  2843. this.css(this.CB['definition'], {
  2844. width: pW + 'px'
  2845. });
  2846. this.buttonWidth['definition'] = this.CB['definition'].offsetWidth;
  2847. } else {
  2848. this.CB['definition'].innerHTML = '';
  2849. this.CB['definitionP'].innerHTML = '';
  2850. this.css([this.CB['definition'], this.CB['definitionLine']], 'display', 'none');
  2851. }
  2852. },
  2853. /*
  2854. 内部函数
  2855. 注册清晰度相关事件
  2856. */
  2857. addDefListener: function () {
  2858. var thisTemp = this;
  2859. var setTimeOutP = null;
  2860. var defClick = function (event) {
  2861. thisTemp.css(thisTemp.CB['definitionP'], {
  2862. left: thisTemp.getCoor(thisTemp.CB['definition'])['x'] + 'px',
  2863. display: 'block'
  2864. });
  2865. };
  2866. this.addListenerInside('click', defClick, this.CB['definition']);
  2867. var defMouseOut = function (event) {
  2868. if (setTimeOutP) {
  2869. window.clearTimeout(setTimeOutP);
  2870. setTimeOutP = null;
  2871. }
  2872. setTimeOutP = window.setTimeout(function (event) {
  2873. thisTemp.css(thisTemp.CB['definitionP'], 'display', 'none');
  2874. }, 500);
  2875. };
  2876. this.addListenerInside('mouseout', defMouseOut, thisTemp.CB['definitionP']);
  2877. var defMouseOver = function (event) {
  2878. if (setTimeOutP) {
  2879. window.clearTimeout(setTimeOutP);
  2880. setTimeOutP = null;
  2881. }
  2882. };
  2883. this.addListenerInside('mouseover', defMouseOver, thisTemp.CB['definitionP']);
  2884. },
  2885. /*
  2886. 内部函数
  2887. 切换清晰度后发生的动作
  2888. */
  2889. newDefinition: function (title) {
  2890. var vArr = this.VA;
  2891. var nVArr = [];
  2892. var i = 0;
  2893. for (i = 0; i < vArr.length; i++) {
  2894. var v = vArr[i];
  2895. if (v[2] == title) {
  2896. nVArr.push(v);
  2897. this.sendJS('definitionChange', i + '');
  2898. }
  2899. }
  2900. if (nVArr.length < 1) {
  2901. return;
  2902. }
  2903. if (this.V != null && this.needSeek == 0) {
  2904. this.needSeek = this.V.currentTime;
  2905. }
  2906. if (this.getFileExt(nVArr[0][0]) != '.m3u8') {
  2907. this.isM3u8 = false;
  2908. }
  2909. if (!this.isM3u8) {
  2910. if (nVArr.length == 1) {
  2911. this.V.innerHTML = '';
  2912. this.V.src = nVArr[0][0];
  2913. } else {
  2914. var source = '';
  2915. nVArr = this.arrSort(nVArr);
  2916. for (i = 0; i < nVArr.length; i++) {
  2917. var type = '';
  2918. var va = nVArr[i];
  2919. if (va[1]) {
  2920. type = ' type="' + va[1] + '"';
  2921. }
  2922. source += '<source src="' + va[0] + '"' + type + '>';
  2923. }
  2924. this.V.removeAttribute('src');
  2925. this.V.innerHTML = source;
  2926. }
  2927. } else {
  2928. this.embedHls(vArr[0][0], this.vars['autoplay']);
  2929. }
  2930. this.V.autoplay = 'autoplay';
  2931. this.V.load();
  2932. this.timerErrorFun();
  2933. },
  2934. /*
  2935. 内置函数
  2936. 播放hls
  2937. */
  2938. embedHls: function (url, autoplay) {
  2939. var thisTemp = this;
  2940. if (Hls.isSupported()) {
  2941. var hls = new Hls();
  2942. hls.loadSource(url);
  2943. hls.attachMedia(this.V);
  2944. hls.on(Hls.Events.MANIFEST_PARSED, function () {
  2945. thisTemp.playerLoad();
  2946. if (autoplay) {
  2947. thisTemp.videoPlay();
  2948. }
  2949. });
  2950. }
  2951. },
  2952. /*
  2953. 内部函数
  2954. 构建提示点
  2955. */
  2956. prompt: function () {
  2957. if (!this.showFace) {
  2958. return;
  2959. }
  2960. var thisTemp = this;
  2961. var prompt = this.vars['promptSpot'];
  2962. if (prompt == null || this.promptArr.length > 0) {
  2963. return;
  2964. }
  2965. var showPrompt = function (event) {
  2966. if (thisTemp.promptElement == null) {
  2967. var random2 = 'prompte' + thisTemp.randomString(5);
  2968. var ele2 = document.createElement('div');
  2969. ele2.className = random2;
  2970. thisTemp.PD.appendChild(ele2);
  2971. thisTemp.promptElement = thisTemp.getByElement(random2);
  2972. thisTemp.css(thisTemp.promptElement, {
  2973. overflowX: 'hidden',
  2974. lineHeight: '22px',
  2975. fontSize: '14px',
  2976. color: '#FFFFFF',
  2977. position: 'absolute',
  2978. display: 'block',
  2979. zIndex: '90'
  2980. });
  2981. }
  2982. var pcon = thisTemp.getPromptTest();
  2983. var pW = pcon['pW'],
  2984. pT = pcon['pT'],
  2985. pL = parseInt(thisTemp.css(this, 'left')) - parseInt(pW * 0.5);
  2986. if (pcon['pL'] > 10) {
  2987. pL = pcon['pL'];
  2988. }
  2989. if (pL < 0) {
  2990. pL = 0;
  2991. }
  2992. thisTemp.css(thisTemp.promptElement, {
  2993. width: pW + 'px',
  2994. left: (-pW - 10) + 'px',
  2995. display: 'block'
  2996. });
  2997. thisTemp.promptElement.innerHTML = thisTemp.getDataset(this, 'words');
  2998. thisTemp.css(thisTemp.promptElement, {
  2999. left: pL + 'px',
  3000. top: (pT - thisTemp.promptElement.offsetHeight - 10) + 'px'
  3001. });
  3002. };
  3003. var hidePrompt = function (event) {
  3004. if (thisTemp.promptElement != null) {
  3005. thisTemp.css(thisTemp.promptElement, {
  3006. display: 'none'
  3007. });
  3008. }
  3009. };
  3010. var i = 0;
  3011. for (i = 0; i < prompt.length; i++) {
  3012. var pr = prompt[i];
  3013. var words = pr['words'];
  3014. var time = pr['time'];
  3015. var random = 'prompt' + this.randomString(5);
  3016. var ele = document.createElement('div');
  3017. ele.className = random;
  3018. this.CB['timeBoBg'].appendChild(ele);
  3019. var div = this.getByElement(random);
  3020. div.setAttribute('data-time', time);
  3021. div.setAttribute('data-words', words);
  3022. this.css(div, {
  3023. width: '6px',
  3024. height: '6px',
  3025. backgroundColor: '#FFFFFF',
  3026. position: 'absolute',
  3027. top: '4px',
  3028. left: '-100px',
  3029. display: 'none',
  3030. zIndex: '1',
  3031. borderRadius: '6px'
  3032. });
  3033.  
  3034. this.addListenerInside('mouseover', showPrompt, div);
  3035. this.addListenerInside('mouseout', hidePrompt, div);
  3036. this.promptArr.push(div);
  3037. }
  3038. this.changePrompt();
  3039. },
  3040. /*
  3041. 内部函数
  3042. 计算提示文本的位置
  3043. */
  3044. getPromptTest: function () {
  3045. var pW = this.previewWidth,
  3046. pT = this.getCoor(this.CB['timeButton'])['y'],
  3047. pL = 0;
  3048. if (this.previewTop != null) {
  3049. pT -= parseInt(this.css(this.previewTop, 'height'));
  3050. pL = parseInt(this.css(this.previewTop, 'left'));
  3051. } else {
  3052. pT -= 35;
  3053. }
  3054. pL += 2;
  3055. if (pL < 0) {
  3056. pL = 0;
  3057. }
  3058. if (pL > this.PD.offsetWidth - pW) {
  3059. pL = this.PD.offsetWidth - pW;
  3060. }
  3061. return {
  3062. pW: pW,
  3063. pT: pT,
  3064. pL: pL
  3065. };
  3066. },
  3067. /*
  3068. 内部函数
  3069. 删除提示点
  3070. */
  3071. deletePrompt: function () {
  3072. var arr = this.promptArr;
  3073. if (arr.length > 0) {
  3074. for (var i = 0; i < arr.length; i++) {
  3075. if (arr[i]) {
  3076. this.deleteChild(arr[i]);
  3077. }
  3078. }
  3079. }
  3080. this.promptArr = [];
  3081. },
  3082. /*
  3083. 内部函数
  3084. 计算提示点坐标
  3085. */
  3086. changePrompt: function () {
  3087. if (this.promptArr.length == 0) {
  3088. return;
  3089. }
  3090. var arr = this.promptArr;
  3091. var duration = this.getMetaDate()['duration'];
  3092. var bw = this.CB['timeBoBg'].offsetWidth;
  3093. for (var i = 0; i < arr.length; i++) {
  3094. var time = parseInt(this.getDataset(arr[i], 'time'));
  3095. var left = parseInt(time * bw / duration) - parseInt(arr[i].offsetWidth * 0.5);
  3096. if (left < 0) {
  3097. left = 0;
  3098. }
  3099. if (left > bw - parseInt(arr[i].offsetWidth * 0.5)) {
  3100. left = bw - parseInt(arr[i].offsetWidth * 0.5);
  3101. }
  3102. this.css(arr[i], {
  3103. left: left + 'px',
  3104. display: 'block'
  3105. });
  3106. }
  3107. },
  3108. /*
  3109. 内部函数
  3110. 构建预览图片效果
  3111. */
  3112. preview: function (obj) {
  3113. var thisTemp = this;
  3114. var preview = {
  3115. file: null,
  3116. scale: 0
  3117. };
  3118. preview = this.standardization(preview, this.vars['preview']);
  3119. if (preview['file'] == null || preview['scale'] <= 0) {
  3120. return;
  3121. }
  3122. var srcArr = preview['file'];
  3123. if (this.previewStart == 0) { //如果还没有构建,则先进行构建
  3124. this.previewStart = 1;
  3125. if (srcArr.length > 0) {
  3126. var i = 0;
  3127. var imgW = 0,
  3128. imgH = 0;
  3129. var random = thisTemp.randomString(10);
  3130. var loadNum = 0;
  3131. var loadImg = function (i) {
  3132. srcArr[i] = thisTemp.getNewUrl(srcArr[i]);
  3133. var n = 0;
  3134. var img = new Image();
  3135. img.src = srcArr[i];
  3136. img.className = random + i;
  3137. img.onload = function (event) {
  3138. loadNum++;
  3139. if (thisTemp.previewDiv == null) { //如果没有建立DIV,则建
  3140. imgW = img.width;
  3141. imgH = img.height;
  3142. thisTemp.previewWidth = parseInt(imgW * 0.1);
  3143. var ele = document.createElement('div');
  3144. ele.className = random;
  3145. thisTemp.PD.appendChild(ele);
  3146. thisTemp.previewDiv = thisTemp.getByElement(random);
  3147. var eleTop = (obj['y'] - parseInt(imgH * 0.1) + 2);
  3148. thisTemp.css(thisTemp.previewDiv, {
  3149. width: srcArr.length * imgW * 10 + 'px',
  3150. height: parseInt(imgH * 0.1) + 'px',
  3151. backgroundColor: '#000000',
  3152. position: 'absolute',
  3153. left: '0px',
  3154. top: eleTop + 'px',
  3155. display: 'none',
  3156. zIndex: '80'
  3157. });
  3158. ele.setAttribute('data-x', '0');
  3159. ele.setAttribute('data-y', eleTop);
  3160. var ele2 = document.createElement('div');
  3161. ele2.className = random + 'd2';
  3162. thisTemp.PD.appendChild(ele2);
  3163. thisTemp.previewTop = thisTemp.getByElement(ele2.className);
  3164. thisTemp.css(thisTemp.previewTop, {
  3165. width: parseInt(imgW * 0.1) + 'px',
  3166. height: parseInt(imgH * 0.1) + 'px',
  3167. position: 'absolute',
  3168. border: '5px solid ' + thisTemp.css(thisTemp.CB['timeProgress'], 'backgroundColor'),
  3169. left: '0px',
  3170. top: (obj['y'] - parseInt(imgH * 0.1) + 2) + 'px',
  3171. display: 'none',
  3172. zIndex: '81'
  3173. });
  3174. var html = '';
  3175. for (n = 0; n < srcArr.length; n++) {
  3176. html += thisTemp.newCanvas(random + n, imgW * 10, parseInt(imgH * 0.1))
  3177. }
  3178. thisTemp.previewDiv.innerHTML = html;
  3179. }
  3180. thisTemp.previewDiv.appendChild(img);
  3181. var cimg = thisTemp.getByElement(img.className);
  3182. var canvas = thisTemp.getByElement(img.className + '-canvas');
  3183. var context = canvas.getContext('2d');
  3184. var sx = 0,
  3185. sy = 0,
  3186. x = 0,
  3187. h = parseInt(imgH * 0.1);
  3188. for (n = 0; n < 100; n++) {
  3189. x = parseInt(n * imgW * 0.1);
  3190. context.drawImage(cimg, sx, sy, parseInt(imgW * 0.1), h, x, 0, parseInt(imgW * 0.1), h);
  3191. sx += parseInt(imgW * 0.1);
  3192. if (sx >= imgW) {
  3193. sx = 0;
  3194. sy += h;
  3195. }
  3196. thisTemp.css(cimg, 'display', 'none');
  3197. }
  3198. if (loadNum == srcArr.length) {
  3199. thisTemp.previewStart = 2;
  3200. } else {
  3201. i++;
  3202. loadImg(i);
  3203. }
  3204. };
  3205. };
  3206. }
  3207. loadImg(i);
  3208. return;
  3209. }
  3210. if (this.previewStart == 2) {
  3211. var isTween = true;
  3212. var nowNum = parseInt(obj['time'] / this.vars['preview']['scale']);
  3213. var numTotal = parseInt(thisTemp.getMetaDate()['duration'] / this.vars['preview']['scale']);
  3214. if (thisTemp.css(thisTemp.previewDiv, 'display') == 'none') {
  3215. isTween = false;
  3216. }
  3217. thisTemp.css(thisTemp.previewDiv, 'display', 'block');
  3218. var imgWidth = thisTemp.previewDiv.offsetWidth * 0.01 / srcArr.length;
  3219. var left = (imgWidth * nowNum) - obj['x'] + parseInt(imgWidth * 0.5),
  3220. top = obj['y'] - thisTemp.previewDiv.offsetHeight;
  3221. thisTemp.css(thisTemp.previewDiv, 'top', top + 2 + 'px');
  3222. var topLeft = obj['x'] - parseInt(imgWidth * 0.5);
  3223. var timepieces = 0;
  3224. if (topLeft < 0) {
  3225. topLeft = 0;
  3226. timepieces = obj['x'] - topLeft - imgWidth * 0.5;
  3227. }
  3228. if (topLeft > thisTemp.PD.offsetWidth - imgWidth) {
  3229. topLeft = thisTemp.PD.offsetWidth - imgWidth;
  3230. timepieces = obj['x'] - topLeft - imgWidth * 0.5;
  3231. }
  3232. if (left < 0) {
  3233. left = 0;
  3234. }
  3235. if (left > numTotal * imgWidth - thisTemp.PD.offsetWidth) {
  3236. left = numTotal * imgWidth - thisTemp.PD.offsetWidth;
  3237. }
  3238. thisTemp.css(thisTemp.previewTop, {
  3239. left: topLeft + 'px',
  3240. top: top + 2 + 'px',
  3241. display: 'block'
  3242. });
  3243. if (thisTemp.previewTop.offsetHeight > thisTemp.previewDiv.offsetHeight) {
  3244. thisTemp.css(thisTemp.previewTop, {
  3245. height: thisTemp.previewDiv.offsetHeight - (thisTemp.previewTop.offsetHeight - thisTemp.previewDiv.offsetHeight) + 'px'
  3246. });
  3247. }
  3248. if (this.previewTween != null) {
  3249. this.animatePause(this.previewTween);
  3250. this.previewTween = null
  3251. }
  3252. var nowLeft = parseInt(thisTemp.css(thisTemp.previewDiv, 'left'));
  3253. var leftC = nowLeft + left;
  3254. if (nowLeft == -(left + timepieces)) {
  3255. return;
  3256. }
  3257. if (isTween) {
  3258. var obj = {
  3259. element: thisTemp.previewDiv,
  3260. start: null,
  3261. end: -(left + timepieces),
  3262. speed: 0.3
  3263. };
  3264. this.previewTween = this.animate(obj);
  3265. } else {
  3266. thisTemp.css(thisTemp.previewDiv, 'left', -(left + timepieces) + 'px')
  3267. }
  3268. }
  3269. },
  3270. /*
  3271. 内部函数
  3272. 删除预览图节点
  3273. */
  3274. deletePreview: function () {
  3275. if (this.previewDiv != null) {
  3276. this.deleteChild(this.previewDiv);
  3277. this.previewDiv = null;
  3278. this.previewStart = 0;
  3279. }
  3280. },
  3281. /*
  3282. 内部函数
  3283. 修改视频地址,属性
  3284. */
  3285. changeVideo: function () {
  3286. if (!this.html5Video) {
  3287. this.getVarsObject();
  3288. this.V.newVideo(this.vars);
  3289. return;
  3290. }
  3291. var vArr = this.VA;
  3292. var v = this.vars;
  3293. var i = 0;
  3294. if (vArr.length < 1) {
  3295. return;
  3296. }
  3297. if (this.V != null && this.needSeek == 0) {
  3298. this.needSeek = this.V.currentTime;
  3299. }
  3300. if (v['poster']) {
  3301. this.V.poster = v['poster'];
  3302. } else {
  3303. this.V.removeAttribute('poster');
  3304. }
  3305. if (v['loop']) {
  3306. this.V.loop = 'loop';
  3307. } else {
  3308. this.V.removeAttribute('loop');
  3309. }
  3310. if (v['seek'] > 0) {
  3311. this.needSeek = v['seek'];
  3312. } else {
  3313. this.needSeek = 0;
  3314. }
  3315. if (this.getFileExt(vArr[0][0]) != '.m3u8') {
  3316. this.isM3u8 = false;
  3317. }
  3318. if (!this.isM3u8) {
  3319. if (vArr.length == 1) {
  3320. this.V.innerHTML = '';
  3321. this.V.src = vArr[0][0];
  3322. } else {
  3323. var source = '';
  3324. vArr = this.arrSort(vArr);
  3325. for (i = 0; i < vArr.length; i++) {
  3326. var type = '';
  3327. var va = vArr[i];
  3328. if (va[1]) {
  3329. type = ' type="' + va[1] + '"';
  3330. }
  3331. source += '<source src="' + va[0] + '"' + type + '>';
  3332. }
  3333. this.V.removeAttribute('src');
  3334. this.V.innerHTML = source;
  3335. }
  3336. //分析视频地址结束
  3337. if (v['autoplay']) {
  3338. this.V.autoplay = 'autoplay';
  3339. } else {
  3340. this.V.removeAttribute('autoplay');
  3341. }
  3342. this.V.load();
  3343. } else {
  3344. this.embedHls(vArr[0][0], v['autoplay']);
  3345. }
  3346. if (!this.isUndefined(v['volume'])) {
  3347. this.changeVolume(v['volume']);
  3348. }
  3349. this.resetPlayer(); //重置界面元素
  3350. this.timerErrorFun();
  3351. //如果存在字幕则加载
  3352. if (this.vars['cktrack']) {
  3353. this.loadTrack();
  3354. }
  3355. },
  3356. /*
  3357. 内部函数
  3358. 调整中间暂停按钮,缓冲loading,错误提示文本框的位置
  3359. */
  3360. elementCoordinate: function () {
  3361. this.pdCoor = this.getXY(this.PD);
  3362. this.css(this.CB['pauseCenter'], {
  3363. left: parseInt((this.PD.offsetWidth - 80) * 0.5) + 'px',
  3364. top: parseInt((this.PD.offsetHeight - 80) * 0.5) + 'px'
  3365. });
  3366. this.css(this.CB['loading'], {
  3367. left: parseInt((this.PD.offsetWidth - 60) * 0.5) + 'px',
  3368. top: parseInt((this.PD.offsetHeight - 60) * 0.5) + 'px'
  3369. });
  3370. this.css(this.CB['errorText'], {
  3371. left: parseInt((this.PD.offsetWidth - 120) * 0.5) + 'px',
  3372. top: parseInt((this.PD.offsetHeight - 30) * 0.5) + 'px'
  3373. });
  3374. this.css(this.CB['logo'], {
  3375. left: parseInt(this.PD.offsetWidth - this.CB['logo'].offsetWidth - 20) + 'px',
  3376. top: '20px'
  3377. });
  3378. this.checkBarWidth();
  3379. },
  3380. /*
  3381. 内部函数
  3382. 当播放器尺寸变化时,显示和隐藏相关节点
  3383. */
  3384. checkBarWidth: function () {
  3385. if (!this.showFace) {
  3386. return;
  3387. }
  3388. var controlBarW = this.CB['controlBar'].offsetWidth;
  3389. var ele = [];
  3390. ele.push([
  3391. [this.CB['full'], this.CB['escFull'], this.CB['fullLine']], this.buttonWidth['full'] + 2, 'full'
  3392. ]);
  3393. if (this.vars['front'] != '') {
  3394. ele.push([
  3395. [this.CB['front'], this.CB['frontLine']], this.buttonWidth['front'] + 2
  3396. ]);
  3397. }
  3398. if (this.vars['next'] != '') {
  3399. ele.push([
  3400. [this.CB['next'], this.CB['nextLine']], this.buttonWidth['next'] + 2
  3401. ]);
  3402. }
  3403. if (this.CB['definition'].innerHTML != '') {
  3404. ele.push([
  3405. [this.CB['definition'], this.CB['definitionLine']], this.buttonWidth['definition'] + 2
  3406. ]);
  3407. }
  3408. ele.push([
  3409. [this.CB['volume']], this.buttonWidth['volume']
  3410. ]);
  3411. ele.push([
  3412. [this.CB['mute'], this.CB['escMute'], this.CB['muteLine']], this.buttonWidth['mute'] + 2, 'mute'
  3413. ]);
  3414. ele.push([
  3415. [this.CB['timeText']], this.buttonWidth['timeText']
  3416. ]);
  3417. ele.push([
  3418. [this.CB['play'], this.CB['pause'], this.CB['playLine']], this.buttonWidth['play'] + 2, 'play'
  3419. ]);
  3420.  
  3421. var i = 0;
  3422. var len = 0;
  3423. var isc = true;
  3424. //计算所有要显示的节点的总宽度
  3425. for (var i = 0; i < ele.length; i++) {
  3426. var nlen = ele[i][1];
  3427. if (nlen > 2) {
  3428. len += nlen;
  3429. } else {
  3430. isc = false;
  3431. }
  3432. }
  3433. if (isc) {
  3434. this.buttonLen = len;
  3435. this.buttonArr = ele;
  3436. }
  3437. len = this.buttonLen;
  3438. ele = this.buttonArr;
  3439. for (var i = 0; i < ele.length; i++) {
  3440. if (len > controlBarW) {
  3441. len -= ele[i][1];
  3442. this.css(ele[i][0], 'display', 'none');
  3443. } else {
  3444. this.css(ele[i][0], 'display', 'block');
  3445. if (ele[i].length == 3) {
  3446. var name = ele[i][2];
  3447. switch (name) {
  3448. case 'mute':
  3449. if (this.volume == 0) {
  3450. this.css(this.CB['mute'], 'display', 'none');
  3451. } else {
  3452. this.css(this.CB['escMute'], 'display', 'none');
  3453. }
  3454. break;
  3455. case 'play':
  3456. this.playShow(this.V.paused ? false : true);
  3457. break;
  3458. case 'full':
  3459. if (this.full) {
  3460. this.css(this.CB['full'], 'display', 'none');
  3461. } else {
  3462. this.css(this.CB['escFull'], 'display', 'none');
  3463. }
  3464. break;
  3465. }
  3466. }
  3467. }
  3468. }
  3469. },
  3470. /*
  3471. 内部函数
  3472. 初始化暂停或播放按钮
  3473. */
  3474. initPlayPause: function () {
  3475. if (!this.showFace) {
  3476. return;
  3477. }
  3478. if (this.vars['autoplay']) {
  3479. this.css([this.CB['play'], this.CB['pauseCenter']], 'display', 'none');
  3480. this.css(this.CB['pause'], 'display', 'block');
  3481. } else {
  3482. this.css(this.CB['play'], 'display', 'block');
  3483. if (this.css(this.CB['errorText'], 'display') == 'none') {
  3484. this.css(this.CB['pauseCenter'], 'display', 'block');
  3485. }
  3486. this.css(this.CB['pause'], 'display', 'none');
  3487. }
  3488. },
  3489.  
  3490. /*
  3491. 下面为监听事件
  3492. 内部函数
  3493. 监听元数据已加载
  3494. */
  3495. loadedHandler: function () {
  3496. this.loaded = true;
  3497. if (this.vars['loaded'] != '') {
  3498. try {
  3499. eval(this.vars['loaded'] + '()');
  3500. } catch (event) {
  3501. this.log(event);
  3502. }
  3503. }
  3504. },
  3505. /*
  3506. 内部函数
  3507. 监听播放
  3508. */
  3509. playingHandler: function () {
  3510. this.playShow(true);
  3511. if (this.needSeek > 0) {
  3512. this.videoSeek(this.needSeek);
  3513. this.needSeek = 0;
  3514. }
  3515. if (this.animatePauseArray.length > 0) {
  3516. this.animateResume('pause');
  3517. }
  3518. if (this.playerType == 'html5video' && this.V != null && this.config['videoDrawImage']) {
  3519. this.sendVCanvas();
  3520. }
  3521. },
  3522. /*
  3523. 内部函数
  3524. 使用画布附加视频
  3525. */
  3526. sendVCanvas: function () {
  3527. if (this.timerVCanvas == null) {
  3528. this.css(this.V, 'display', 'none');
  3529. this.css(this.MD, 'display', 'block');
  3530. var thisTemp = this;
  3531. var videoCanvas = function () {
  3532. if (thisTemp.MDCX.width != thisTemp.PD.offsetWidth) {
  3533. thisTemp.MDC.width = thisTemp.PD.offsetWidth;
  3534. }
  3535. if (thisTemp.MDCX.height != thisTemp.PD.offsetHeight) {
  3536. thisTemp.MDC.height = thisTemp.PD.offsetHeight;
  3537. }
  3538. thisTemp.MDCX.clearRect(0, 0, thisTemp.MDCX.width, thisTemp.MDCX.height);
  3539. var coor = thisTemp.getProportionCoor(thisTemp.PD.offsetWidth, thisTemp.PD.offsetHeight, thisTemp.V.videoWidth, thisTemp.V.videoHeight);
  3540. thisTemp.MDCX.drawImage(thisTemp.V, 0, 0, thisTemp.V.videoWidth, thisTemp.V.videoHeight, coor['x'], coor['y'], coor['width'], coor['height']);
  3541. };
  3542. this.timerVCanvas = new this.timer(0, videoCanvas);
  3543. }
  3544. },
  3545. /*
  3546. 内部函数
  3547. 监听暂停
  3548. */
  3549. pauseHandler: function () {
  3550. this.playShow(false);
  3551. if (this.animatePauseArray.length > 0) {
  3552. this.animatePause('pause');
  3553. }
  3554. if (this.playerType == 'html5video' && this.V != null && this.config['videoDrawImage']) {
  3555. this.stopVCanvas();
  3556. }
  3557. },
  3558. /*
  3559. 内部函数
  3560. 停止画布
  3561. */
  3562. stopVCanvas: function () {
  3563. if (this.timerVCanvas != null) {
  3564. this.css(this.V, 'display', 'block');
  3565. this.css(this.MD, 'display', 'none');
  3566. if (this.timerVCanvas.runing) {
  3567. this.timerVCanvas.stop();
  3568. }
  3569. this.timerVCanvas = null;
  3570. }
  3571. },
  3572. /*
  3573. 内部函数
  3574. 根据当前播放还是暂停确认图标显示
  3575. */
  3576. playShow: function (b) {
  3577. if (!this.showFace) {
  3578. return;
  3579. }
  3580. if (b) {
  3581. this.css(this.CB['play'], 'display', 'none');
  3582. this.css(this.CB['pauseCenter'], 'display', 'none');
  3583. this.css(this.CB['pause'], 'display', 'block');
  3584. } else {
  3585. this.css(this.CB['play'], 'display', 'block');
  3586. if (this.css(this.CB['errorText'], 'display') == 'none') {
  3587. this.css(this.CB['pauseCenter'], 'display', 'block');
  3588. } else {
  3589. this.css(this.CB['pauseCenter'], 'display', 'none');
  3590. }
  3591. this.css(this.CB['pause'], 'display', 'none');
  3592. }
  3593. },
  3594. /*
  3595. 内部函数
  3596. 监听seek结束
  3597. */
  3598. seekedHandler: function () {
  3599. this.resetTrack();
  3600. this.isTimeButtonMove = true;
  3601. if (this.V.paused) {
  3602. this.videoPlay();
  3603. }
  3604. },
  3605. /*
  3606. 内部函数
  3607. 监听播放结束
  3608. */
  3609. endedHandler: function () {
  3610. if (!this.vars['loop']) {
  3611. this.videoPause();
  3612. }
  3613. },
  3614. /*
  3615. 内部函数
  3616. 监听音量改变
  3617. */
  3618. volumechangeHandler: function () {
  3619. if (!this.showFace) {
  3620. return;
  3621. }
  3622. try {
  3623. if (this.V.volume > 0) {
  3624. this.css(this.CB['mute'], 'display', 'block');
  3625. this.css(this.CB['escMute'], 'display', 'none');
  3626. } else {
  3627. this.css(this.CB['mute'], 'display', 'none');
  3628. this.css(this.CB['escMute'], 'display', 'block');
  3629. }
  3630. } catch (event) {
  3631. }
  3632. },
  3633.  
  3634. /*
  3635. 内部函数
  3636. 监听播放时间调节进度条
  3637. */
  3638. timeUpdateHandler: function () {
  3639. var duration = 0;
  3640. if (this.playerType == 'html5video') {
  3641. try {
  3642. duration = this.V.duration;
  3643. } catch (event) {
  3644. }
  3645. }
  3646. if (duration > 0) {
  3647. this.time = this.V.currentTime;
  3648. this.timeTextHandler();
  3649. this.trackShowHandler();
  3650. if (this.isTimeButtonMove) {
  3651. this.timeProgress(this.time, duration);
  3652. }
  3653. }
  3654. },
  3655. /*
  3656. 内部函数
  3657. 按时间改变进度条
  3658. */
  3659. timeProgress: function (time, duration) {
  3660. if (!this.showFace) {
  3661. return;
  3662. }
  3663. var timeProgressBgW = this.CB['timeProgressBg'].offsetWidth;
  3664. var timeBOW = parseInt((time * timeProgressBgW / duration) - (this.CB['timeButton'].offsetWidth * 0.5));
  3665. if (timeBOW > timeProgressBgW - this.CB['timeButton'].offsetWidth) {
  3666. timeBOW = timeProgressBgW - this.CB['timeButton'].offsetWidth;
  3667. }
  3668. if (timeBOW < 0) {
  3669. timeBOW = 0;
  3670. }
  3671. this.css(this.CB['timeProgress'], 'width', timeBOW + 'px');
  3672. this.css(this.CB['timeButton'], 'left', parseInt(timeBOW) + 'px');
  3673. },
  3674. /*
  3675. 内部函数
  3676. 监听播放时间改变时间显示文本框
  3677. */
  3678. timeTextHandler: function () { //显示时间/总时间
  3679. if (!this.showFace) {
  3680. return;
  3681. }
  3682. var duration = this.V.duration;
  3683. var time = this.V.currentTime;
  3684. if (isNaN(duration) || parseInt(duration) < 0.2) {
  3685. duration = this.vars['duration'];
  3686. }
  3687. this.CB['timeText'].innerHTML = this.formatTime(time) + ' / ' + this.formatTime(duration);
  3688. if (this.CB['timeText'].offsetWidth > 0) {
  3689. this.buttonWidth['timeText'] = this.CB['timeText'].offsetWidth;
  3690. }
  3691. },
  3692. /*
  3693. 内部函数
  3694. 监听是否是缓冲状态
  3695. */
  3696. bufferEdHandler: function () {
  3697. if (!this.showFace || this.playerType == 'flashplayer') {
  3698. return;
  3699. }
  3700. var thisTemp = this;
  3701. var clearTimerBuffer = function () {
  3702. if (thisTemp.timerBuffer != null) {
  3703. if (thisTemp.timerBuffer.runing) {
  3704. thisTemp.sendJS('buffer', 100);
  3705. thisTemp.timerBuffer.stop();
  3706. }
  3707. thisTemp.timerBuffer = null;
  3708. }
  3709. };
  3710. clearTimerBuffer();
  3711. var bufferFun = function () {
  3712. if (thisTemp.V.buffered.length > 0) {
  3713. var duration = thisTemp.V.duration;
  3714. var len = thisTemp.V.buffered.length;
  3715. var bufferStart = thisTemp.V.buffered.start(len - 1);
  3716. var bufferEnd = thisTemp.V.buffered.end(len - 1);
  3717. var loadTime = bufferStart + bufferEnd;
  3718. var loadProgressBgW = thisTemp.CB['timeProgressBg'].offsetWidth;
  3719. var timeButtonW = thisTemp.CB['timeButton'].offsetWidth;
  3720. var loadW = parseInt((loadTime * loadProgressBgW / duration) + timeButtonW);
  3721. if (loadW >= loadProgressBgW) {
  3722. loadW = loadProgressBgW;
  3723. clearTimerBuffer();
  3724. }
  3725. thisTemp.changeLoad(loadTime);
  3726. }
  3727. };
  3728. this.timerBuffer = new this.timer(200, bufferFun);
  3729. },
  3730. /*
  3731. 内部函数
  3732. 单独计算加载进度
  3733. */
  3734. changeLoad: function (loadTime) {
  3735. if (this.V == null) {
  3736. return;
  3737. }
  3738. if (!this.showFace) {
  3739. return;
  3740. }
  3741. var loadProgressBgW = this.CB['timeProgressBg'].offsetWidth;
  3742. var timeButtonW = this.CB['timeButton'].offsetWidth;
  3743. var duration = this.V.duration;
  3744. if (this.isUndefined(loadTime)) {
  3745. loadTime = this.loadTime;
  3746. } else {
  3747. this.loadTime = loadTime;
  3748. }
  3749. var loadW = parseInt((loadTime * loadProgressBgW / duration) + timeButtonW);
  3750. this.css(this.CB['loadProgress'], 'width', loadW + 'px');
  3751. },
  3752. /*
  3753. 内部函数
  3754. 判断是否是直播
  3755. */
  3756. judgeIsLive: function () {
  3757. var thisTemp = this;
  3758. if (this.timerError != null) {
  3759. if (this.timerError.runing) {
  3760. this.timerError.stop();
  3761. }
  3762. this.timerError = null;
  3763. }
  3764. this.error = false;
  3765. if (this.showFace) {
  3766. this.css(this.CB['errorText'], 'display', 'none');
  3767. }
  3768. var timeupdate = function (event) {
  3769. thisTemp.timeUpdateHandler();
  3770. };
  3771. if (!this.vars['live']) {
  3772. if (this.V != null && this.playerType == 'html5video') {
  3773. this.addListenerInside('timeupdate', timeupdate);
  3774. thisTemp.timeTextHandler();
  3775. thisTemp.prompt(); //添加提示点
  3776. window.setTimeout(function () {
  3777. thisTemp.bufferEdHandler();
  3778. }, 200);
  3779. }
  3780. } else {
  3781. this.removeListenerInside('timeupdate', timeupdate);
  3782. if (this.timerTime != null) {
  3783. window.clearInterval(this.timerTime);
  3784. timerTime = null;
  3785. }
  3786. if (this.timerTime != null) {
  3787. if (this.timerTime.runing) {
  3788. this.timerTime.stop();
  3789. }
  3790. this.timerTime = null;
  3791. }
  3792. var timeFun = function () {
  3793. if (thisTemp.V != null && !thisTemp.V.paused && thisTemp.showFace) {
  3794. thisTemp.CB['timeText'].innerHTML = thisTemp.getNowDate();
  3795. }
  3796. };
  3797. this.timerTime = new this.timer(1000, timeFun);
  3798. //timerTime.start();
  3799. }
  3800. this.definition();
  3801. },
  3802. /*
  3803. 内部函数
  3804. 加载字幕
  3805. */
  3806. loadTrack: function () {
  3807. if (this.playerType == 'flashplayer' || this.vars['flashplayer'] == true) {
  3808. return;
  3809. }
  3810. var thisTemp = this;
  3811. var track = this.vars['cktrack'];
  3812. var obj = {
  3813. method: 'get',
  3814. dataType: 'text',
  3815. url: track,
  3816. charset: 'utf-8',
  3817. success: function (data) {
  3818. thisTemp.track = thisTemp.parseSrtSubtitles(data);
  3819. thisTemp.trackIndex = 0;
  3820. thisTemp.nowTrackShow = {
  3821. sn: ''
  3822. };
  3823. }
  3824. };
  3825. this.ajax(obj);
  3826. },
  3827. /*
  3828. 内部函数
  3829. 重置字幕
  3830. */
  3831. resetTrack: function () {
  3832. this.trackIndex = 0;
  3833. this.nowTrackShow = {
  3834. sn: ''
  3835. };
  3836. },
  3837. /*
  3838. 内部函数
  3839. 根据时间改变读取显示字幕
  3840. */
  3841. trackShowHandler: function () {
  3842. if (!this.showFace) {
  3843. return;
  3844. }
  3845. if (this.track.length < 1) {
  3846. return;
  3847. }
  3848. if (this.trackIndex >= this.track.length) {
  3849. this.trackIndex = 0;
  3850. }
  3851. var nowTrack = this.track[this.trackIndex]; //当前编号对应的字幕内容
  3852. /*
  3853. this.nowTrackShow=当前显示在界面上的内容
  3854. 如果当前时间正好在nowTrack时间内,则需要判断
  3855. */
  3856. if (this.time >= nowTrack['startTime'] && this.time <= nowTrack['endTime']) {
  3857. /*
  3858. 如果当前显示的内容不等于当前需要显示的内容时,则需要显示正确的内容
  3859. */
  3860. var nowShow = this.nowTrackShow;
  3861. if (nowShow['sn'] != nowTrack['sn']) {
  3862. this.trackHide();
  3863. this.trackShow(nowTrack);
  3864. }
  3865. } else {
  3866. /*
  3867. * 如果当前播放时间不在当前编号字幕内,则需要先清空当前的字幕内容,再显示新的字幕内容
  3868. */
  3869. this.trackHide();
  3870. this.checkTrack();
  3871. }
  3872. },
  3873. /*
  3874. 内部函数
  3875. 显示字幕内容
  3876. */
  3877. trackShow: function (track) {
  3878. this.nowTrackShow = track;
  3879. var arr = track['content'];
  3880. for (var i = 0; i < arr.length; i++) {
  3881. var obj = {
  3882. list: [{
  3883. type: 'text',
  3884. text: arr[i],
  3885. color: '#FFFFFF',
  3886. size: 16,
  3887. font: this.fontFamily,
  3888. lineHeight: 30
  3889. }],
  3890. position: [1, 2, null, -(arr.length - i) * 30 - 50]
  3891. };
  3892. var ele = this.addElement(obj);
  3893. this.trackElement.push(ele);
  3894. }
  3895. },
  3896. /*
  3897. 内部函数
  3898. 隐藏字字幕内容
  3899. */
  3900. trackHide: function () {
  3901. for (var i = 0; i < this.trackElement.length; i++) {
  3902. this.deleteElement(this.trackElement[i]);
  3903. }
  3904. this.trackElement = [];
  3905. },
  3906. /*
  3907. 内部函数
  3908. 重新计算字幕的编号
  3909. */
  3910. checkTrack: function () {
  3911. var num = this.trackIndex;
  3912. var arr = this.track;
  3913. var i = 0;
  3914. for (i = num; i < arr.length; i++) {
  3915. if (this.time >= arr[i]['startTime'] && this.time <= arr[i]['endTime']) {
  3916. this.trackIndex = i;
  3917. break;
  3918. }
  3919. }
  3920. },
  3921. /*
  3922. -----------------------------------------------------------------------------接口函数开始
  3923. 接口函数
  3924. 在播放和暂停之间切换
  3925. */
  3926. playOrPause: function () {
  3927. if (!this.loaded) {
  3928. return;
  3929. }
  3930. if (this.config['videoClick']) {
  3931. if (this.V == null) {
  3932. return;
  3933. }
  3934. if (this.playerType == 'flashplayer') {
  3935. this.V.playOrPause();
  3936. return;
  3937. }
  3938. if (this.V.paused) {
  3939. this.videoPlay();
  3940. } else {
  3941. this.videoPause();
  3942. }
  3943. }
  3944. },
  3945. /*
  3946. 接口函数
  3947. 播放动作
  3948. */
  3949. videoPlay: function () {
  3950. if (!this.loaded) {
  3951. return;
  3952. }
  3953. if (this.playerType == 'flashplayer') {
  3954. this.V.videoPlay();
  3955. return;
  3956. }
  3957. this.V.play();
  3958. },
  3959. /*
  3960. 接口函数
  3961. 暂停动作
  3962. */
  3963. videoPause: function () {
  3964. if (!this.loaded) {
  3965. return;
  3966. }
  3967. if (this.playerType == 'flashplayer') {
  3968. this.V.videoPause();
  3969. return;
  3970. }
  3971. this.V.pause();
  3972. },
  3973. /*
  3974. 接口函数
  3975. 跳转时间动作
  3976. */
  3977. videoSeek: function (time) {
  3978. if (!this.loaded) {
  3979. return;
  3980. }
  3981. if (this.playerType == 'flashplayer') {
  3982. this.V.videoSeek(time);
  3983. return;
  3984. }
  3985. var meta = this.getMetaDate();
  3986. var duration = meta['duration'];
  3987. if (duration > 0 && time > duration) {
  3988. time = duration;
  3989. }
  3990. if (time >= 0) {
  3991. this.V.currentTime = time;
  3992. this.sendJS('seekTime', time);
  3993. }
  3994. },
  3995. /*
  3996. 接口函数
  3997. 调节音量/获取音量
  3998. */
  3999. changeVolume: function (vol, bg, button) {
  4000. if (this.loaded) {
  4001. if (this.playerType == 'flashplayer') {
  4002. this.V.changeVolume(time);
  4003. return;
  4004. }
  4005. }
  4006. if (isNaN(vol) || this.isUndefined(vol)) {
  4007. vol = 0;
  4008. }
  4009. if (!this.loaded) {
  4010. this.vars['volume'] = vol;
  4011. }
  4012. if (!this.html5Video) {
  4013. this.V.changeVolume(vol);
  4014. return;
  4015. }
  4016. try {
  4017. if (this.isUndefined(bg)) {
  4018. bg = true;
  4019. }
  4020. } catch (e) {
  4021. }
  4022. try {
  4023. if (this.isUndefined(button)) {
  4024. button = true;
  4025. }
  4026. } catch (e) {
  4027. }
  4028. if (!vol) {
  4029. vol = 0;
  4030. }
  4031. if (vol < 0) {
  4032. vol = 0;
  4033. }
  4034. if (vol > 1) {
  4035. vol = 1;
  4036. }
  4037. try {
  4038. this.V.volume = vol;
  4039. } catch (error) {
  4040. }
  4041. this.volume = vol;
  4042. if (bg && this.showFace) {
  4043. var bgW = vol * this.CB['volumeBg'].offsetWidth;
  4044. if (bgW < 0) {
  4045. bgW = 0;
  4046. }
  4047. if (bgW > this.CB['volumeBg'].offsetWidth) {
  4048. bgW = this.CB['volumeBg'].offsetWidth;
  4049. }
  4050. this.css(this.CB['volumeUp'], 'width', bgW + 'px');
  4051. }
  4052.  
  4053. if (button && this.showFace) {
  4054. var buLeft = parseInt(this.CB['volumeUp'].offsetWidth - (this.CB['volumeBO'].offsetWidth * 0.5));
  4055. if (buLeft > this.CB['volumeBg'].offsetWidth - this.CB['volumeBO'].offsetWidth) {
  4056. buLeft = this.CB['volumeBg'].offsetWidth - this.CB['volumeBO'].offsetWidth
  4057. }
  4058. if (buLeft < 0) {
  4059. buLeft = 0;
  4060. }
  4061. this.css(this.CB['volumeBO'], 'left', buLeft + 'px');
  4062. }
  4063. },
  4064. /*
  4065. 接口函数
  4066. 静音
  4067. */
  4068. videoMute: function () {
  4069. if (!this.loaded) {
  4070. return;
  4071. }
  4072. if (this.playerType == 'flashplayer') {
  4073. this.V.videoMute();
  4074. return;
  4075. }
  4076. this.volumeTemp = this.V ? (this.V.volume > 0 ? this.V.volume : this.vars['volume']) : this.vars['volume'];
  4077. this.changeVolume(0);
  4078. },
  4079. /*
  4080. 接口函数
  4081. 取消静音
  4082. */
  4083. videoEscMute: function () {
  4084. if (!this.loaded) {
  4085. return;
  4086. }
  4087. if (this.playerType == 'flashplayer') {
  4088. this.V.videoEscMute();
  4089. return;
  4090. }
  4091. this.changeVolume(this.volumeTemp > 0 ? this.volumeTemp : this.vars['volume']);
  4092. },
  4093. /*
  4094. 接口函数
  4095. 快退
  4096. */
  4097. fastBack: function () {
  4098. if (!this.loaded) {
  4099. return;
  4100. }
  4101. if (this.playerType == 'flashplayer') {
  4102. this.V.fastBack();
  4103. return;
  4104. }
  4105. var time = this.time - this.ckplayerConfig['config']['timeJump'];
  4106. if (time < 0) {
  4107. time = 0;
  4108. }
  4109. this.videoSeek(time);
  4110. },
  4111. /*
  4112. 接口函数
  4113. 快进
  4114. */
  4115. fastNext: function () {
  4116. if (!this.loaded) {
  4117. return;
  4118. }
  4119. if (this.playerType == 'flashplayer') {
  4120. this.V.fastNext();
  4121. return;
  4122. }
  4123. var time = this.time + this.ckplayerConfig['config']['timeJump'];
  4124. if (time > this.V.duration) {
  4125. time = this.V.duration;
  4126. }
  4127. this.videoSeek(time);
  4128. },
  4129. /*
  4130. 接口函数
  4131. 获取当前播放的地址
  4132. */
  4133. getCurrentSrc: function () {
  4134. if (!this.loaded) {
  4135. return;
  4136. }
  4137. if (this.playerType == 'flashplayer') {
  4138. return this.V.getCurrentSrc();
  4139. }
  4140. return this.V.currentSrc;
  4141. },
  4142. /*
  4143. 内置函数
  4144. 全屏/退出全屏动作,该动作只能是用户操作才可以触发,比如用户点击按钮触发该事件
  4145. */
  4146. switchFull: function () {
  4147. if (this.full) {
  4148. this.quitFullScreen();
  4149. } else {
  4150. this.fullScreen();
  4151. }
  4152. },
  4153. /*
  4154. 内置函数
  4155. 全屏动作,该动作只能是用户操作才可以触发,比如用户点击按钮触发该事件
  4156. */
  4157. fullScreen: function () {
  4158. if (this.html5Video && this.playerType == 'html5video') {
  4159. var element = this.PD;
  4160. if (element.requestFullscreen) {
  4161. element.requestFullscreen();
  4162. } else if (element.mozRequestFullScreen) {
  4163. element.mozRequestFullScreen();
  4164. } else if (element.webkitRequestFullscreen) {
  4165. element.webkitRequestFullscreen();
  4166. } else if (element.msRequestFullscreen) {
  4167. element.msRequestFullscreen();
  4168. } else if (element.oRequestFullscreen) {
  4169. element.oRequestFullscreen();
  4170. }
  4171. this.judgeFullScreen();
  4172. } else {
  4173. //this.V.fullScreen();
  4174. }
  4175. },
  4176. /*
  4177. 接口函数
  4178. 退出全屏动作
  4179. */
  4180. quitFullScreen: function () {
  4181. if (this.html5Video && this.playerType == 'html5video') {
  4182. if (document.exitFullscreen) {
  4183. document.exitFullscreen();
  4184. } else if (document.msExitFullscreen) {
  4185. document.msExitFullscreen();
  4186. } else if (document.mozCancelFullScreen) {
  4187. document.mozCancelFullScreen();
  4188. } else if (document.oRequestFullscreen) {
  4189. document.oCancelFullScreen();
  4190. } else if (document.requestFullscreen) {
  4191. document.requestFullscreen();
  4192. } else if (document.webkitExitFullscreen) {
  4193. document.webkitExitFullscreen();
  4194. } else {
  4195. this.css(document.documentElement, 'cssText', '');
  4196. this.css(document.document.body, 'cssText', '');
  4197. this.css(this.PD, 'cssText', '');
  4198. }
  4199. this.judgeFullScreen();
  4200. }
  4201. },
  4202. /*
  4203. 下面列出只有flashplayer里支持的
  4204. */
  4205. videoRotation: function (n) {
  4206. if (!this.loaded) {
  4207. return;
  4208. }
  4209. if (this.playerType == 'flashplayer') {
  4210. this.V.videoRotation(n);
  4211. return;
  4212. }
  4213. if (this.isUndefined(n)) {
  4214. n = 0;
  4215. }
  4216. var tf = this.css(this.V, 'transform');
  4217. if (this.isUndefined(tf) && !tf) {
  4218. tf = 'rotate(0deg)';
  4219. }
  4220. var reg = tf.match(/rotate\([^)]+\)/);
  4221. reg = reg ? reg[0].replace('rotate(', '').replace('deg)', '') : '';
  4222. if (reg == '') {
  4223. reg = 0;
  4224. } else {
  4225. reg = parseInt(reg);
  4226. }
  4227. if (n == -1) {
  4228. reg -= 90;
  4229. } else if (n == 1) {
  4230. reg += 90;
  4231. } else {
  4232. if (n != 90 && n != 180 && n != 270 && n != -90 && n != -180 && n != -270) {
  4233. reg = 0;
  4234. } else {
  4235. reg = n;
  4236. }
  4237. }
  4238. n = reg;
  4239. tf = tf.replace(/rotate\([^)]+\)/, '') + ' rotate(' + n + 'deg)';
  4240. this.css(this.V, 'transform', tf);
  4241. return;
  4242. },
  4243. videoBrightness: function (n) {
  4244. if (!this.loaded) {
  4245. return;
  4246. }
  4247. if (this.playerType == 'flashplayer') {
  4248. this.V.videoBrightness(n);
  4249. return;
  4250. }
  4251. },
  4252. videoContrast: function (n) {
  4253. if (!this.loaded) {
  4254. return;
  4255. }
  4256. if (this.playerType == 'flashplayer') {
  4257. this.V.videoContrast(n);
  4258. return;
  4259. }
  4260. },
  4261. videoSaturation: function (n) {
  4262. if (!this.loaded) {
  4263. return;
  4264. }
  4265. if (this.playerType == 'flashplayer') {
  4266. this.V.videoSaturation(n);
  4267. return;
  4268. }
  4269. },
  4270. videoHue: function (n) {
  4271. if (!this.loaded) {
  4272. return;
  4273. }
  4274. if (this.playerType == 'flashplayer') {
  4275. this.V.videoHue(n);
  4276. return;
  4277. }
  4278. },
  4279. videoZoom: function (n) {
  4280. if (!this.loaded) {
  4281. return;
  4282. }
  4283. if (this.playerType == 'flashplayer') {
  4284. this.V.videoZoom(n);
  4285. return;
  4286. }
  4287. if (this.isUndefined(n)) {
  4288. n = 1;
  4289. }
  4290. if (n < 0) {
  4291. n = 0;
  4292. }
  4293. if (n > 2) {
  4294. n = 2;
  4295. }
  4296. var tf = this.css(this.V, 'transform');
  4297. tf = tf.replace(/scale\([^)]+\)/, '') + ' scale(' + n + ')';
  4298. this.css(this.V, 'transform', tf);
  4299. return;
  4300. },
  4301. videoProportion: function (w, h) {
  4302. if (!this.loaded) {
  4303. return;
  4304. }
  4305. if (this.playerType == 'flashplayer') {
  4306. this.V.videoProportion(w, h);
  4307. return;
  4308. }
  4309. },
  4310. adPlay: function () {
  4311. if (!this.loaded) {
  4312. return;
  4313. }
  4314. if (this.playerType == 'flashplayer') {
  4315. this.V.adPlay();
  4316. return;
  4317. }
  4318. },
  4319. adPause: function () {
  4320. if (!this.loaded) {
  4321. return;
  4322. }
  4323. if (this.playerType == 'flashplayer') {
  4324. this.V.adPause();
  4325. return;
  4326. }
  4327. },
  4328. videoError: function (n) {
  4329. if (!this.loaded) {
  4330. return;
  4331. }
  4332. if (this.playerType == 'flashplayer') {
  4333. this.V.videoError(n);
  4334. return;
  4335. }
  4336. },
  4337. changeConfig: function () {
  4338. if (!this.loaded) {
  4339. return;
  4340. }
  4341. if (this.playerType == 'flashplayer') {
  4342. this.V.changeConfig(arguments);
  4343. return;
  4344. }
  4345. var obj = this.ckplayerConfig;
  4346. var arg = arguments;
  4347. for (var i = 0; i < arg.length - 1; i++) {
  4348. if (obj.hasOwnProperty(arg[i])) {
  4349. obj = obj[arg[i]];
  4350. } else {
  4351. return;
  4352. }
  4353. }
  4354. var val = arg[arg.length - 1];
  4355. switch (arg.length) {
  4356. case 2:
  4357. this.ckplayerConfig[arg[0]] = val;
  4358. break;
  4359. case 3:
  4360. this.ckplayerConfig[arg[0]][arg[1]] = val;
  4361. break;
  4362. case 4:
  4363. this.ckplayerConfig[arg[0]][arg[1]][arg[2]] = val;
  4364. break;
  4365. case 5:
  4366. this.ckplayerConfig[arg[0]][arg[1]][arg[2]][arg[3]] = val;
  4367. break;
  4368. case 6:
  4369. this.ckplayerConfig[arg[0]][arg[1]][arg[2]][arg[3]][arg[4]] = val;
  4370. break;
  4371. case 7:
  4372. this.ckplayerConfig[arg[0]][arg[1]][arg[2]][arg[3]][arg[4]][arg[5]] = val;
  4373. break;
  4374. case 8:
  4375. this.ckplayerConfig[arg[0]][arg[1]][arg[2]][arg[3]][arg[4]][arg[5]][arg[6]] = val;
  4376. break;
  4377. case 9:
  4378. this.ckplayerConfig[arg[0]][arg[1]][arg[2]][arg[3]][arg[4]][arg[5]][arg[6]][arg[7]] = val;
  4379. break;
  4380. case 10:
  4381. this.ckplayerConfig[arg[0]][arg[1]][arg[2]][arg[3]][arg[4]][arg[5]][arg[6]][arg[7]][arg[8]] = val;
  4382. break;
  4383. default:
  4384. return;
  4385. break;
  4386. }
  4387. this.sendJS('configChange', this.ckplayerConfig);
  4388. },
  4389. custom: function () {
  4390. if (!this.loaded) {
  4391. return;
  4392. }
  4393. if (this.playerType == 'flashplayer') {
  4394. this.V.custom(arguments);
  4395. return;
  4396. }
  4397. },
  4398. getConfig: function () {
  4399. if (!this.loaded) {
  4400. return null;
  4401. }
  4402. if (this.playerType == 'flashplayer') {
  4403. return this.V.getConfig(arguments);
  4404. }
  4405. },
  4406. openUrl: function (n) {
  4407. if (!this.loaded) {
  4408. return;
  4409. }
  4410. if (this.playerType == 'flashplayer') {
  4411. this.V.openUrl(n);
  4412. return;
  4413. }
  4414. },
  4415. /*
  4416. 接口函数
  4417. 清除视频
  4418. */
  4419. videoClear: function () {
  4420. if (!this.loaded) {
  4421. return;
  4422. }
  4423. if (this.playerType == 'flashplayer') {
  4424. this.V.videoClear();
  4425. return;
  4426. }
  4427. },
  4428. /*
  4429. 接口函数
  4430. 向播放器传递新的视频地址
  4431. */
  4432. newVideo: function (c) {
  4433. if (this.playerType == 'flashplayer') {
  4434. this.V.newVideo(c);
  4435. return;
  4436. } else {
  4437. this.embed(c);
  4438. }
  4439. },
  4440. /*
  4441. 接口函数
  4442. 截图
  4443. */
  4444. screenshot: function (obj, save, name) {
  4445. if (!this.loaded) {
  4446. return;
  4447. }
  4448. if (this.playerType == 'flashplayer') {
  4449. try {
  4450. this.V.screenshot(obj, save, name);
  4451. } catch (error) {
  4452. this.log(error);
  4453. }
  4454. return;
  4455. }
  4456. if (obj == 'video') {
  4457. var newCanvas = document.createElement('canvas');
  4458. newCanvas.width = this.V.videoWidth;
  4459. newCanvas.height = this.V.videoHeight;
  4460. newCanvas.getContext('2d').drawImage(this.V, 0, 0, this.V.videoWidth, this.V.videoHeight);
  4461. try {
  4462. var base64 = newCanvas.toDataURL('image/jpeg');
  4463. this.sendJS('screenshot', {
  4464. object: obj,
  4465. save: save,
  4466. name: name,
  4467. base64: base64
  4468. });
  4469. } catch (error) {
  4470. this.log(error);
  4471. }
  4472. }
  4473. },
  4474. /*
  4475. 接口函数
  4476. 改变播放器尺寸
  4477. */
  4478. changeSize: function (w, h) {
  4479. if (this.isUndefined(w)) {
  4480. w = 0;
  4481. }
  4482. if (this.isUndefined(h)) {
  4483. h = 0;
  4484. }
  4485. if (w > 0) {
  4486. this.css(this.CD, 'width', w + 'px');
  4487. }
  4488. if (h > 0) {
  4489. this.css(this.CD, 'height', h + 'px');
  4490. }
  4491. if (this.html5Video) {
  4492. this.elementCoordinate();
  4493. }
  4494. },
  4495. /*
  4496. 接口函数
  4497. 改变视频播放速度
  4498. */
  4499. changePlaybackRate: function (n) {
  4500. if (this.html5Video) {
  4501. var arr = this.playbackRateArr;
  4502. n = parseInt(n);
  4503. if (n < arr.length) {
  4504. this.newPlaybackrate(arr[n][1]);
  4505. }
  4506. }
  4507. },
  4508. /*
  4509. 内部函数
  4510. 注册控制控制栏显示与隐藏函数
  4511. */
  4512. changeControlBarShow: function (show) {
  4513. if (!this.loaded) {
  4514. return;
  4515. }
  4516. if (this.playerType == 'flashplayer') {
  4517. this.V.changeControlBarShow(show);
  4518. return;
  4519. }
  4520. if (show) {
  4521. this.controlBarIsShow = true;
  4522. this.controlBarHide(false);
  4523. } else {
  4524. this.controlBarIsShow = false;
  4525. this.controlBarHide(true);
  4526. }
  4527. },
  4528. /*
  4529. -----------------------------------------------------------------------
  4530. 调用flashplayer
  4531. */
  4532. embedSWF: function () {
  4533. var vid = this.randomString();
  4534. var flashvars = this.getFlashVars();
  4535. var param = this.getFlashplayerParam();
  4536. var flashplayerUrl = 'http://www.macromedia.com/go/getflashplayer';
  4537. var html = '',
  4538. src = javascriptPath + 'ckplayer.swf';
  4539. id = 'id="' + vid + '" name="' + vid + '" ';
  4540. html += '<object pluginspage="' + flashplayerUrl + '" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=11,3,0,0" width="100%" height="100%" ' + id + ' align="middle">';
  4541. html += param['v'];
  4542. html += '<param name="movie" value="' + src + '">';
  4543. html += '<param name="flashvars" value="' + flashvars + '">';
  4544. html += '<embed ' + param['w'] + ' src="' + src + '" flashvars="' + flashvars + '" width="100%" height="100%" ' + id + ' align="middle" type="application/x-shockwave-flash" pluginspage="' + flashplayerUrl + '" />';
  4545. html += '</object>';
  4546. this.PD.innerHTML = html;
  4547. this.V = this.getObjectById(vid); //V:定义播放器对象全局变量
  4548. this.playerType = 'flashplayer';
  4549. //this.loaded=true;
  4550. },
  4551. /*
  4552. 内置函数
  4553. 将vars对象转换成字符
  4554. */
  4555. getFlashVars: function () {
  4556. this.getVarsObject();
  4557. var v = this.vars;
  4558. var z = '';
  4559. for (k in v) {
  4560. if (k != 'flashplayer' && k != 'container' && v[k] != '') {
  4561. if (z != '') {
  4562. z += '&';
  4563. }
  4564. var vk = v[k];
  4565. if (vk == true) {
  4566. vk = 1;
  4567. }
  4568. if (vk == false) {
  4569. vk = 0;
  4570. }
  4571. z += k + '=' + vk;
  4572. }
  4573.  
  4574. }
  4575. if (!v.hasOwnProperty('volume') || !v['volume']) {
  4576. if (z != '') {
  4577. z += '&';
  4578. }
  4579. z += 'volume=0';
  4580. }
  4581. return z;
  4582. },
  4583. /*
  4584. 内置函数
  4585. 将vars格式化成flash能接受的对象。再由getFlashVars函数转化成字符串或由newVideo直接使用
  4586. */
  4587. getVarsObject: function () {
  4588. var v = this.vars;
  4589. var f = '',
  4590. d = '',
  4591. w = ''; //f=视频地址,d=清晰度地址,w=权重,z=最终地址
  4592. var arr = this.VA;
  4593. var prompt = v['promptSpot'];
  4594. var i = 0;
  4595. var video = this.vars['video'];
  4596. if (typeof (video) == 'object') { //对象或数组
  4597. if (!this.isUndefined(typeof (video.length))) { //说明是数组
  4598. var arr = video;
  4599. for (i = 0; i < arr.length; i++) {
  4600. var arr2 = arr[i];
  4601. if (arr2) {
  4602. if (f != '') {
  4603. f += this.ckplayerConfig['config']['split'];
  4604. d += ',';
  4605. w += ',';
  4606. v['type'] += this.ckplayerConfig['config']['split'];
  4607. }
  4608. f += encodeURIComponent(decodeURIComponent(arr2[0]));
  4609. d += arr2[2];
  4610. w += arr2[3];
  4611. v['type'] += arr2[1].replace('video/', '');
  4612. }
  4613. }
  4614. } else {
  4615. f = encodeURIComponent(decodeURIComponent(video['file']));
  4616. if (!this.isUndefined(video['type'])) {
  4617. v['type'] = video['type'];
  4618. }
  4619. d = '';
  4620. w = '';
  4621. }
  4622. } else {
  4623. f = encodeURIComponent(decodeURIComponent(video));
  4624. }
  4625. if (v['preview'] != null) {
  4626. v['previewscale'] = v['preview']['scale'];
  4627. v['preview'] = v['preview']['file'].join(',');
  4628.  
  4629. }
  4630. if (prompt != null) {
  4631. v['promptspot'] = '';
  4632. v['promptspottime'] = '';
  4633. for (i = 0; i < prompt.length; i++) {
  4634. if (v['promptspot'] != '') {
  4635. v['promptspot'] += ',';
  4636. v['promptspottime'] += ',';
  4637. }
  4638. v['promptspot'] += prompt[i]['words'];
  4639. v['promptspottime'] += prompt[i]['time'];
  4640. }
  4641.  
  4642. }
  4643. if (f != '') {
  4644. v['video'] = f;
  4645. v['definition'] = d;
  4646. v['weight'] = w;
  4647. }
  4648. if (!v['volume']) {
  4649. v['volume'] = 0;
  4650. }
  4651. var newV = {};
  4652.  
  4653. for (var k in v) {
  4654. if (v[k] != null) {
  4655. newV[k] = v[k];
  4656. }
  4657. if (k == 'type') {
  4658. newV[k] = v[k].replace('video/m3u8', 'm3u8');
  4659. }
  4660. }
  4661.  
  4662. this.vars = newV;
  4663. },
  4664. /*
  4665. 内置函数
  4666. 将embedSWF里的param的对象进行转换
  4667. */
  4668. getFlashplayerParam: function () {
  4669. var w = '',
  4670. v = '',
  4671. o = {
  4672. allowScriptAccess: 'always',
  4673. allowFullScreen: true,
  4674. quality: 'high',
  4675. bgcolor: '#000'
  4676. };
  4677. for (var e in o) {
  4678. w += e + '="' + o[e] + '" ';
  4679. v += '<param name="' + e + '" value="' + o[e] + '" />';
  4680. }
  4681. w = w.replace('movie=', 'src=');
  4682. return {
  4683. w: w,
  4684. v: v
  4685. };
  4686. },
  4687.  
  4688. /*
  4689. 操作动作结束
  4690. -----------------------------------------------------------------------
  4691. 接口函数
  4692. 获取元数据部分
  4693. */
  4694. getMetaDate: function () {
  4695. if (!this.loaded || this.V == null) {
  4696. return false;
  4697. }
  4698. if (this.playerType == 'html5video') {
  4699. var duration = 0;
  4700. try {
  4701. duration = !isNaN(this.V.duration) ? this.V.duration : 0;
  4702. } catch (event) {
  4703. this.log(event);
  4704. }
  4705. var data = {
  4706. duration: duration,
  4707. volume: this.V.volume,
  4708. playbackRate: this.V.playbackRate,
  4709. width: this.PD.offsetWidth || this.V.offsetWidth || this.V.width,
  4710. height: this.PD.offsetHeight || this.V.offsetHeight || this.V.height,
  4711. streamWidth: this.V.videoWidth,
  4712. streamHeight: this.V.videoHeight,
  4713. videoWidth: this.V.offsetWidth,
  4714. videoHeight: this.V.offsetHeight,
  4715. paused: this.V.paused
  4716. };
  4717. return data;
  4718. } else {
  4719. try {
  4720. return this.V.getMetaDate();
  4721. } catch (event) {
  4722. this.log(event);
  4723. }
  4724. }
  4725. return false;
  4726. },
  4727. /*
  4728. 接口函数
  4729. 取当前提供给播放器播放的视频列表
  4730. */
  4731. getVideoUrl: function () {
  4732. if (this.playerType == 'flashplayer') {
  4733. return this.V.getVideoUrl();
  4734. }
  4735. var arr = [];
  4736. if (this.V.src) {
  4737. arr.push(this.V.src);
  4738. } else {
  4739. var uArr = this.V.childNodes;
  4740. for (var i = 0; i < uArr.length; i++) {
  4741. arr.push(uArr[i].src);
  4742. }
  4743. }
  4744. return arr;
  4745. },
  4746. /*
  4747. 内置函数
  4748. 格式化函数
  4749. */
  4750. clickEvent: function (call) {
  4751. if (call == 'none' || call == '' || call == null) {
  4752. return {
  4753. type: 'none'
  4754. };
  4755. }
  4756. var callArr = call.split('->');
  4757. var type = '',
  4758. fun = '',
  4759. link = '',
  4760. target = '';
  4761. if (callArr.length == 2) {
  4762. var callM = callArr[0];
  4763. var callE = callArr[1];
  4764. if (!callE) {
  4765. return {
  4766. type: 'none'
  4767. };
  4768. }
  4769. var val = '';
  4770. var eArr = [];
  4771. type = callM;
  4772. switch (callM) {
  4773. case 'actionScript':
  4774. //trace(THIS.hasOwnProperty(callE));
  4775.  
  4776. if (callE.indexOf('(') > -1) {
  4777. eArr = callE.split('(');
  4778. callE = eArr[0];
  4779. val = eArr[1].replace(')', '');
  4780. }
  4781. if (val == '') {
  4782. fun = 'thisTemp.' + callE + '()';
  4783. } else {
  4784. fun = 'thisTemp.' + callE + '(' + val + ')';
  4785. }
  4786. break;
  4787. case 'javaScript':
  4788. if (callE.substr(0, 11) == '[flashvars]') {
  4789. callE = callE.substr(11);
  4790. if (this.vars.hasOwnProperty(callE)) {
  4791. callE = this.vars[callE];
  4792. } else {
  4793. break;
  4794. }
  4795.  
  4796. }
  4797. if (callE.indexOf('(') > -1) {
  4798. eArr = callE.split('(');
  4799. callE = eArr[0];
  4800. val = eArr[1].replace(')', '');
  4801. }
  4802. if (val == '') {
  4803. fun = callE + '()';
  4804. } else {
  4805. fun = callE + '(' + val + ')';
  4806. }
  4807. break;
  4808. case "link":
  4809. var callLink = (callE + ',').split(',');
  4810. if (callLink[0].substr(0, 11) == '[flashvars]') {
  4811. var fl = callLink[0].replace('[flashvars]', '');
  4812. if (this.vars.hasOwnProperty(fl)) {
  4813. callLink[0] = this.vars[fl];
  4814. } else {
  4815. break;
  4816. }
  4817. }
  4818. if (!callLink[1]) {
  4819. callLink[1] = '_blank';
  4820. }
  4821. link = callLink[0];
  4822. target = callLink[1];
  4823. break;
  4824. }
  4825. }
  4826. return {
  4827. type: type,
  4828. fun: fun,
  4829. link: link,
  4830. target: target
  4831. }
  4832. },
  4833. /*
  4834. 内置函数
  4835. 向播放器界面添加一个文本
  4836. */
  4837. addElement: function (attribute) {
  4838. var thisTemp = this;
  4839. if (this.playerType == 'flashplayer') {
  4840. return this.V.addElement(attribute);
  4841. }
  4842. var i = 0;
  4843. var obj = {
  4844. list: null,
  4845. x: '100%',
  4846. y: "50%",
  4847. position: null,
  4848. alpha: 1,
  4849. backgroundColor: '',
  4850. backAlpha: 1,
  4851. backRadius: 0,
  4852. clickEvent: ''
  4853. };
  4854. obj = this.standardization(obj, attribute);
  4855. var list = obj['list'];
  4856. if (list == null) {
  4857. return '';
  4858. }
  4859. var id = 'element' + this.randomString(10);
  4860. var ele = document.createElement('div');
  4861. ele.className = id;
  4862. if (obj['x']) {
  4863. ele.setAttribute('data-x', obj['x']);
  4864. }
  4865. if (obj['y']) {
  4866. ele.setAttribute('data-y', obj['y']);
  4867. }
  4868. if (obj['position'] != null) {
  4869. ele.setAttribute('data-position', obj['position'].join(','));
  4870. }
  4871.  
  4872. this.PD.appendChild(ele);
  4873. var eid = this.getByElement(id);
  4874. this.css(eid, {
  4875. position: 'absolute',
  4876. filter: 'alpha(opacity:' + obj['alpha'] + ')',
  4877. opacity: obj['alpha'].toString(),
  4878. width: '800px',
  4879. zIndex: '20'
  4880. });
  4881. var bgid = 'elementbg' + this.randomString(10);
  4882. var bgAlpha = obj['alpha'].toString();
  4883. var bgColor = obj['backgroundColor'].replace('0x', '#');
  4884. var html = '';
  4885. var idArr = [];
  4886. var clickArr = [];
  4887. if (!this.isUndefined(list) && list.length > 0) {
  4888. var textObj, returnObj, clickEvent;
  4889. for (i = 0; i < list.length; i++) {
  4890. var newEleid = 'elementnew' + this.randomString(10);
  4891. switch (list[i]['type']) {
  4892. case 'image':
  4893. case 'png':
  4894. case 'jpg':
  4895. case 'jpeg':
  4896. case 'gif':
  4897. textObj = {
  4898. type: 'image',
  4899. file: '',
  4900. radius: 0, //圆角弧度
  4901. width: 30, //定义宽,必需要定义
  4902. height: 30, //定义高,必需要定义
  4903. alpha: 1, //透明度
  4904. paddingLeft: 0, //左边距离
  4905. paddingRight: 0, //右边距离
  4906. paddingTop: 0,
  4907. paddingBottom: 0,
  4908. marginLeft: 0,
  4909. marginRight: 0,
  4910. marginTop: 0,
  4911. marginBottom: 0,
  4912. backgroundColor: '',
  4913. clickEvent: ''
  4914. };
  4915.  
  4916. list[i] = this.standardization(textObj, list[i]);
  4917. clickEvent = this.clickEvent(list[i]['clickEvent']);
  4918. clickArr.push(clickEvent);
  4919. if (clickEvent['type'] == 'link') {
  4920. html += '<div class="' + newEleid + '" data-i="' + i + '"><a href="' + clickEvent['link'] + '" target="' + clickEvent['target'] + '"><img class="' + newEleid + '_image" src="' + list[i]['file'] + '" style="border:0;"></a></div>';
  4921. } else {
  4922. html += '<div class="' + newEleid + '" data-i="' + i + '"><img class="' + newEleid + '_image" src="' + list[i]['file'] + '" style="border:0;"></div>';
  4923. }
  4924. break;
  4925. case 'text':
  4926. textObj = {
  4927. type: 'text', //说明是文本
  4928. text: '', //文本内容
  4929. color: '0xFFFFFF',
  4930. size: 14,
  4931. font: this.fontFamily,
  4932. leading: 0,
  4933. alpha: 1, //透明度
  4934. paddingLeft: 0, //左边距离
  4935. paddingRight: 0, //右边距离
  4936. paddingTop: 0,
  4937. paddingBottom: 0,
  4938. marginLeft: 0,
  4939. marginRight: 0,
  4940. marginTop: 0,
  4941. marginBottom: 0,
  4942. backgroundColor: '',
  4943. backAlpha: 1,
  4944. backRadius: 0, //背景圆角弧度,支持数字统一设置,也支持分开设置[30,20,20,50],对应上左,上右,下右,下左
  4945. clickEvent: ''
  4946. };
  4947. list[i] = this.standardization(textObj, list[i]);
  4948. clickEvent = this.clickEvent(list[i]['clickEvent']);
  4949. clickArr.push(clickEvent);
  4950. if (clickEvent['type'] == 'link') {
  4951. html += '<div class="' + newEleid + '" data-i="' + i + '"><div class="' + newEleid + '_bg"></div><div class="' + newEleid + '_text"><a href="' + clickEvent['link'] + '" target="' + clickEvent['target'] + '">' + list[i]['text'] + '</a></div></div>';
  4952. } else {
  4953. html += '<div class="' + newEleid + '" data-i="' + i + '"><div class="' + newEleid + '_bg"></div><div class="' + newEleid + '_text">' + list[i]['text'] + '</div></div>';
  4954. }
  4955. break;
  4956. default:
  4957. break;
  4958. }
  4959. idArr.push(newEleid);
  4960. }
  4961. }
  4962. var objClickEvent = this.clickEvent(obj['clickEvent']);
  4963. /*if(objClickEvent['type']=='link'){
  4964. html = '<a href="'+objClickEvent['link']+'" target="'+objClickEvent['target']+'">' + html + '</a>';
  4965. }*/
  4966. eid.innerHTML = '<div class="' + bgid + '"></div><div class="' + bgid + '_c">' + html + '</div>';
  4967. if (objClickEvent['type'] == 'javaScript' || objClickEvent['type'] == 'actionScript') {
  4968. var objClickHandler = function () {
  4969. eval(objClickEvent['fun']);
  4970. thisTemp.sendJS('clickEvent', clk['type'] + '->' + clk['fun'].replace('thisTemp.', '').replace('()', ''));
  4971. };
  4972. this.addListenerInside('click', objClickHandler, this.getByElement(bgid + '_c'))
  4973. }
  4974. this.css(bgid + '_c', {
  4975. position: 'absolute',
  4976. zIndex: '2'
  4977. });
  4978. for (i = 0; i < idArr.length; i++) {
  4979. var clk = clickArr[i];
  4980.  
  4981. if (clk['type'] == 'javaScript' || clk['type'] == 'actionScript') {
  4982. var clickHandler = function () {
  4983. clk = clickArr[this.getAttribute('data-i')];
  4984. eval(clk['fun']);
  4985. thisTemp.sendJS('clickEvent', clk['type'] + '->' + clk['fun'].replace('thisTemp.', '').replace('()', ''));
  4986. };
  4987. this.addListenerInside('click', clickHandler, this.getByElement(idArr[i]))
  4988. }
  4989. switch (list[i]['type']) {
  4990. case 'image':
  4991. case 'png':
  4992. case 'jpg':
  4993. case 'jpeg':
  4994. case 'gif':
  4995. this.css(idArr[i], {
  4996. float: 'left',
  4997. width: list[i]['width'] + 'px',
  4998. height: list[i]['height'] + 'px',
  4999. filter: 'alpha(opacity:' + list[i]['alpha'] + ')',
  5000. opacity: list[i]['alpha'].toString(),
  5001. marginLeft: list[i]['marginLeft'] + 'px',
  5002. marginRight: list[i]['marginRight'] + 'px',
  5003. marginTop: list[i]['marginTop'] + 'px',
  5004. marginBottom: list[i]['marginBottom'] + 'px',
  5005. borderRadius: list[i]['radius'] + 'px',
  5006. cursor: 'pointer'
  5007. });
  5008. this.css(idArr[i] + '_image', {
  5009. width: list[i]['width'] + 'px',
  5010. height: list[i]['height'] + 'px',
  5011. borderRadius: list[i]['radius'] + 'px'
  5012. });
  5013. break;
  5014. case 'text':
  5015. this.css(idArr[i] + '_text', {
  5016. filter: 'alpha(opacity:' + list[i]['alpha'] + ')',
  5017. opacity: list[i]['alpha'].toString(),
  5018. borderRadius: list[i]['radius'] + 'px',
  5019. fontFamily: list[i]['font'],
  5020. fontSize: list[i]['size'] + 'px',
  5021. color: list[i]['color'].replace('0x', '#'),
  5022. lineHeight: list[i]['leading'] > 0 ? list[i]['leading'] + 'px' : '',
  5023. paddingLeft: list[i]['paddingLeft'] + 'px',
  5024. paddingRight: list[i]['paddingRight'] + 'px',
  5025. paddingTop: list[i]['paddingTop'] + 'px',
  5026. paddingBottom: list[i]['paddingBottom'] + 'px',
  5027. whiteSpace: 'nowrap',
  5028. position: 'absolute',
  5029. zIndex: '3',
  5030. cursor: 'pointer'
  5031. });
  5032. this.css(idArr[i], {
  5033. float: 'left',
  5034. width: this.getByElement(idArr[i] + '_text').offsetWidth + 'px',
  5035. height: this.getByElement(idArr[i] + '_text').offsetHeight + 'px',
  5036. marginLeft: list[i]['marginLeft'] + 'px',
  5037. marginRight: list[i]['marginRight'] + 'px',
  5038. marginTop: list[i]['marginTop'] + 'px',
  5039. marginBottom: list[i]['marginBottom'] + 'px'
  5040. });
  5041. this.css(idArr[i] + '_bg', {
  5042. width: this.getByElement(idArr[i] + '_text').offsetWidth + 'px',
  5043. height: this.getByElement(idArr[i] + '_text').offsetHeight + 'px',
  5044. filter: 'alpha(opacity:' + list[i]['backAlpha'] + ')',
  5045. opacity: list[i]['backAlpha'].toString(),
  5046. borderRadius: list[i]['backRadius'] + 'px',
  5047. backgroundColor: list[i]['backgroundColor'].replace('0x', '#'),
  5048. position: 'absolute',
  5049. zIndex: '2'
  5050. });
  5051. break;
  5052. default:
  5053. break;
  5054. }
  5055. }
  5056. this.css(bgid, {
  5057. width: this.getByElement(bgid + '_c').offsetWidth + 'px',
  5058. height: this.getByElement(bgid + '_c').offsetHeight + 'px',
  5059. position: 'absolute',
  5060. filter: 'alpha(opacity:' + bgAlpha + ')',
  5061. opacity: bgAlpha,
  5062. backgroundColor: bgColor.replace('0x', '#'),
  5063. borderRadius: obj['backRadius'] + 'px',
  5064. zIndex: '1'
  5065. });
  5066. this.css(eid, {
  5067. width: this.getByElement(bgid).offsetWidth + 'px',
  5068. height: this.getByElement(bgid).offsetHeight + 'px'
  5069. });
  5070. var eidCoor = this.calculationCoor(eid);
  5071. this.css(eid, {
  5072. left: eidCoor['x'] + 'px',
  5073. top: eidCoor['y'] + 'px'
  5074. });
  5075.  
  5076. this.elementArr.push(eid.className);
  5077. return eid;
  5078. },
  5079. /*
  5080. 内置函数
  5081. 获取元件的属性,包括x,y,width,height,alpha
  5082. */
  5083. getElement: function (element) {
  5084. if (this.playerType == 'flashplayer') {
  5085. return this.V.getElement(element);
  5086. }
  5087. var ele = element;
  5088. if (typeof (element) == 'string') {
  5089. ele = this.getByElement(element);
  5090. }
  5091. var coor = this.getCoor(ele);
  5092. return {
  5093. x: coor['x'],
  5094. y: coor['y'],
  5095. width: ele.offsetWidth,
  5096. height: ele.offsetHeight,
  5097. alpha: !this.isUndefined(this.css(ele, 'opacity')) ? parseFloat(this.css(ele, 'opacity')) : 1
  5098. };
  5099. },
  5100. /*
  5101. 内置函数
  5102. 根据节点的x,y计算在播放器里的坐标
  5103. */
  5104. calculationCoor: function (ele) {
  5105. if (this.playerType == 'flashplayer') {
  5106. return this.V.calculationCoor(ele);
  5107. }
  5108. if (ele == []) {
  5109. return;
  5110. }
  5111. var x, y, position = [];
  5112. var w = this.PD.offsetWidth,
  5113. h = this.PD.offsetHeight;
  5114. var ew = ele.offsetWidth,
  5115. eh = ele.offsetHeight;
  5116. if (!this.isUndefined(this.getDataset(ele, 'x'))) {
  5117. x = this.getDataset(ele, 'x');
  5118. }
  5119. if (!this.isUndefined(this.getDataset(ele, 'y'))) {
  5120. y = this.getDataset(ele, 'y');
  5121. }
  5122. if (!this.isUndefined(this.getDataset(ele, 'position'))) {
  5123. try {
  5124. position = this.getDataset(ele, 'position').toString().split(',');
  5125. } catch (event) {
  5126. }
  5127. }
  5128. if (position.length > 0) {
  5129. position.push(null, null, null, null);
  5130. var i = 0;
  5131. for (i = 0; i < position.length; i++) {
  5132. if (this.isUndefined(position[i]) || position[i] == null || position[i] == 'null' || position[i] == '') {
  5133. position[i] = null;
  5134. } else {
  5135. position[i] = parseFloat(position[i]);
  5136. }
  5137. }
  5138.  
  5139. if (position[2] == null) {
  5140. switch (position[0]) {
  5141. case 0:
  5142. x = 0;
  5143. break;
  5144. case 1:
  5145. x = parseInt((w - ew) * 0.5);
  5146. break;
  5147. default:
  5148. x = w - ew;
  5149. break;
  5150. }
  5151. } else {
  5152. switch (position[0]) {
  5153. case 0:
  5154. x = position[2];
  5155. break;
  5156. case 1:
  5157. x = parseInt(w * 0.5) + position[2];
  5158. break;
  5159. default:
  5160. x = w + position[2];
  5161. break;
  5162. }
  5163. }
  5164. if (position[3] == null) {
  5165. switch (position[1]) {
  5166. case 0:
  5167. y = 0;
  5168. break;
  5169. case 1:
  5170. y = parseInt((h - eh) * 0.5);
  5171. break;
  5172. default:
  5173. y = h - eh;
  5174. break;
  5175. }
  5176. } else {
  5177. switch (position[1]) {
  5178. case 0:
  5179. y = position[3];
  5180. break;
  5181. case 1:
  5182. y = parseInt(h * 0.5) + position[3];
  5183. break;
  5184. default:
  5185. y = h + position[3];
  5186. break;
  5187. }
  5188. }
  5189. } else {
  5190. if (x.substring(x.length - 1, x.length) == '%') {
  5191. x = Math.floor(parseInt(x.substring(0, x.length - 1)) * w * 0.01);
  5192. }
  5193. if (y.substring(y.length - 1, y.length) == '%') {
  5194. y = Math.floor(parseInt(y.substring(0, y.length - 1)) * h * 0.01);
  5195. }
  5196. }
  5197. return {
  5198. x: x,
  5199. y: y
  5200. }
  5201.  
  5202. },
  5203. /*
  5204. 内置函数
  5205. 修改新增元件的坐标
  5206. */
  5207. changeElementCoor: function () {
  5208. for (var i = 0; i < this.elementArr.length; i++) {
  5209. if (this.getByElement(this.elementArr[i]) != []) {
  5210. var c = this.calculationCoor(this.getByElement(this.elementArr[i]));
  5211. if (c['x'] && c['y']) {
  5212. this.css(this.elementArr[i], {
  5213. top: c['y'] + 'px',
  5214. left: c['x'] + 'px'
  5215. });
  5216. }
  5217. }
  5218. }
  5219. },
  5220. /*
  5221. 内置函数
  5222. 缓动效果集
  5223. */
  5224. tween: function () {
  5225. var Tween = {
  5226. None: {//均速运动
  5227. easeIn: function (t, b, c, d) {
  5228. return c * t / d + b;
  5229. },
  5230. easeOut: function (t, b, c, d) {
  5231. return c * t / d + b;
  5232. },
  5233. easeInOut: function (t, b, c, d) {
  5234. return c * t / d + b;
  5235. }
  5236. },
  5237. Quadratic: {
  5238. easeIn: function (t, b, c, d) {
  5239. return c * (t /= d) * t + b;
  5240. },
  5241. easeOut: function (t, b, c, d) {
  5242. return -c * (t /= d) * (t - 2) + b;
  5243. },
  5244. easeInOut: function (t, b, c, d) {
  5245. if ((t /= d / 2) < 1)
  5246. return c / 2 * t * t + b;
  5247. return -c / 2 * ((--t) * (t - 2) - 1) + b;
  5248. }
  5249. },
  5250. Cubic: {
  5251. easeIn: function (t, b, c, d) {
  5252. return c * (t /= d) * t * t + b;
  5253. },
  5254. easeOut: function (t, b, c, d) {
  5255. return c * ((t = t / d - 1) * t * t + 1) + b;
  5256. },
  5257. easeInOut: function (t, b, c, d) {
  5258. if ((t /= d / 2) < 1)
  5259. return c / 2 * t * t * t + b;
  5260. return c / 2 * ((t -= 2) * t * t + 2) + b;
  5261. }
  5262. },
  5263. Quartic: {
  5264. easeIn: function (t, b, c, d) {
  5265. return c * (t /= d) * t * t * t + b;
  5266. },
  5267. easeOut: function (t, b, c, d) {
  5268. return -c * ((t = t / d - 1) * t * t * t - 1) + b;
  5269. },
  5270. easeInOut: function (t, b, c, d) {
  5271. if ((t /= d / 2) < 1)
  5272. return c / 2 * t * t * t * t + b;
  5273. return -c / 2 * ((t -= 2) * t * t * t - 2) + b;
  5274. }
  5275. },
  5276. Quintic: {
  5277. easeIn: function (t, b, c, d) {
  5278. return c * (t /= d) * t * t * t * t + b;
  5279. },
  5280. easeOut: function (t, b, c, d) {
  5281. return c * ((t = t / d - 1) * t * t * t * t + 1) + b;
  5282. },
  5283. easeInOut: function (t, b, c, d) {
  5284. if ((t /= d / 2) < 1)
  5285. return c / 2 * t * t * t * t * t + b;
  5286. return c / 2 * ((t -= 2) * t * t * t * t + 2) + b;
  5287. }
  5288. },
  5289. Sine: {
  5290. easeIn: function (t, b, c, d) {
  5291. return -c * Math.cos(t / d * (Math.PI / 2)) + c + b;
  5292. },
  5293. easeOut: function (t, b, c, d) {
  5294. return c * Math.sin(t / d * (Math.PI / 2)) + b;
  5295. },
  5296. easeInOut: function (t, b, c, d) {
  5297. return -c / 2 * (Math.cos(Math.PI * t / d) - 1) + b;
  5298. }
  5299. },
  5300. Exponential: {
  5301. easeIn: function (t, b, c, d) {
  5302. return(t == 0) ? b : c * Math.pow(2, 10 * (t / d - 1)) + b;
  5303. },
  5304. easeOut: function (t, b, c, d) {
  5305. return(t == d) ? b + c : c * (-Math.pow(2, -10 * t / d) + 1) + b;
  5306. },
  5307. easeInOut: function (t, b, c, d) {
  5308. if (t == 0)
  5309. return b;
  5310. if (t == d)
  5311. return b + c;
  5312. if ((t /= d / 2) < 1)
  5313. return c / 2 * Math.pow(2, 10 * (t - 1)) + b;
  5314. return c / 2 * (-Math.pow(2, -10 * --t) + 2) + b;
  5315. }
  5316. },
  5317. Circular: {
  5318. easeIn: function (t, b, c, d) {
  5319. return -c * (Math.sqrt(1 - (t /= d) * t) - 1) + b;
  5320. },
  5321. easeOut: function (t, b, c, d) {
  5322. return c * Math.sqrt(1 - (t = t / d - 1) * t) + b;
  5323. },
  5324. easeInOut: function (t, b, c, d) {
  5325. if ((t /= d / 2) < 1)
  5326. return -c / 2 * (Math.sqrt(1 - t * t) - 1) + b;
  5327. return c / 2 * (Math.sqrt(1 - (t -= 2) * t) + 1) + b;
  5328. }
  5329. },
  5330. Elastic: {
  5331. easeIn: function (t, b, c, d, a, p) {
  5332. if (t == 0)
  5333. return b;
  5334. if ((t /= d) == 1)
  5335. return b + c;
  5336. if (!p)
  5337. p = d * .3;
  5338. if (!a || a < Math.abs(c)) {
  5339. a = c;
  5340. var s = p / 4;
  5341. } else
  5342. var s = p / (2 * Math.PI) * Math.asin(c / a);
  5343. return -(a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p)) + b;
  5344. },
  5345. easeOut: function (t, b, c, d, a, p) {
  5346. if (t == 0)
  5347. return b;
  5348. if ((t /= d) == 1)
  5349. return b + c;
  5350. if (!p)
  5351. p = d * .3;
  5352. if (!a || a < Math.abs(c)) {
  5353. a = c;
  5354. var s = p / 4;
  5355. } else
  5356. var s = p / (2 * Math.PI) * Math.asin(c / a);
  5357. return(a * Math.pow(2, -10 * t) * Math.sin((t * d - s) * (2 * Math.PI) / p) + c + b);
  5358. },
  5359. easeInOut: function (t, b, c, d, a, p) {
  5360. if (t == 0)
  5361. return b;
  5362. if ((t /= d / 2) == 2)
  5363. return b + c;
  5364. if (!p)
  5365. p = d * (.3 * 1.5);
  5366. if (!a || a < Math.abs(c)) {
  5367. a = c;
  5368. var s = p / 4;
  5369. } else
  5370. var s = p / (2 * Math.PI) * Math.asin(c / a);
  5371. if (t < 1)
  5372. return -.5 * (a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p)) + b;
  5373. return a * Math.pow(2, -10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p) * .5 + c + b;
  5374. }
  5375. },
  5376. Back: {
  5377. easeIn: function (t, b, c, d, s) {
  5378. if (s == undefined)
  5379. s = 1.70158;
  5380. return c * (t /= d) * t * ((s + 1) * t - s) + b;
  5381. },
  5382. easeOut: function (t, b, c, d, s) {
  5383. if (s == undefined)
  5384. s = 1.70158;
  5385. return c * ((t = t / d - 1) * t * ((s + 1) * t + s) + 1) + b;
  5386. },
  5387. easeInOut: function (t, b, c, d, s) {
  5388. if (s == undefined)
  5389. s = 1.70158;
  5390. if ((t /= d / 2) < 1)
  5391. return c / 2 * (t * t * (((s *= (1.525)) + 1) * t - s)) + b;
  5392. return c / 2 * ((t -= 2) * t * (((s *= (1.525)) + 1) * t + s) + 2) + b;
  5393. }
  5394. },
  5395. Bounce: {
  5396. easeIn: function (t, b, c, d) {
  5397. return c - Tween.Bounce.easeOut(d - t, 0, c, d) + b;
  5398. },
  5399. easeOut: function (t, b, c, d) {
  5400. if ((t /= d) < (1 / 2.75)) {
  5401. return c * (7.5625 * t * t) + b;
  5402. } else if (t < (2 / 2.75)) {
  5403. return c * (7.5625 * (t -= (1.5 / 2.75)) * t + .75) + b;
  5404. } else if (t < (2.5 / 2.75)) {
  5405. return c * (7.5625 * (t -= (2.25 / 2.75)) * t + .9375) + b;
  5406. } else {
  5407. return c * (7.5625 * (t -= (2.625 / 2.75)) * t + .984375) + b;
  5408. }
  5409. },
  5410. easeInOut: function (t, b, c, d) {
  5411. if (t < d / 2)
  5412. return Tween.Bounce.easeIn(t * 2, 0, c, d) * .5 + b;
  5413. else
  5414. return Tween.Bounce.easeOut(t * 2 - d, 0, c, d) * .5 + c * .5 + b;
  5415. }
  5416. }
  5417. };
  5418. return Tween;
  5419. },
  5420. /*
  5421. 接口函数
  5422. 缓动效果
  5423. ele:Object=需要缓动的对象,
  5424. parameter:String=需要改变的属性:x,y,width,height,alpha,
  5425. effect:String=效果名称,
  5426. start:Int=起始值,
  5427. end:Int=结束值,
  5428. speed:Number=运动的总秒数,支持小数
  5429. */
  5430. animate: function (attribute) {
  5431. if (this.playerType == 'flashplayer') {
  5432. return this.V.animate(attribute);
  5433. }
  5434. var thisTemp = this;
  5435. var animateId = 'animate_' + this.randomString();
  5436. var obj = {
  5437. element: null,
  5438. parameter: 'x',
  5439. static: false,
  5440. effect: 'None.easeIn',
  5441. start: null,
  5442. end: null,
  5443. speed: 0,
  5444. overStop: false,
  5445. pauseStop: false, //暂停播放时缓动是否暂停
  5446. callBack: null
  5447. };
  5448. obj = this.standardization(obj, attribute);
  5449. if (obj['element'] == null || obj['speed'] == 0) {
  5450. return false;
  5451. }
  5452. var w = this.PD.offsetWidth,
  5453. h = this.PD.offsetHeight;
  5454. var effArr = (obj['effect'] + '.').split('.');
  5455. var tweenFun = this.tween()[effArr[0]][effArr[1]];
  5456. var eleCoor = {
  5457. x: 0,
  5458. y: 0
  5459. };
  5460. if (this.isUndefined(tweenFun)) {
  5461. return false;
  5462. }
  5463. //先将该元件从元件数组里删除,让其不再跟随播放器的尺寸改变而改变位置
  5464. var def = this.arrIndexOf(this.elementArr, obj['element'].className);
  5465. if (def > -1) {
  5466. this.elementArr.splice(def, 1);
  5467. }
  5468. //var run = true;
  5469. var css = {};
  5470. //对传递的参数进行转化,x和y转化成left,top
  5471. var pm = this.getElement(obj['element']); //包含x,y,width,height,alpha属性
  5472. var t = 0; //当前时间
  5473. var b = 0; //初始值
  5474. var c = 0; //变化量
  5475. var d = obj['speed'] * 1000; //持续时间
  5476. var timerTween = null;
  5477. var tweenObj = null;
  5478. var start = obj['start'] == null ? '' : obj['start'].toString();
  5479. var end = obj['end'] == null ? '' : obj['end'].toString();
  5480. switch (obj['parameter']) {
  5481. case 'x':
  5482. if (obj['start'] == null) {
  5483. b = pm['x'];
  5484. } else {
  5485. if (start.substring(start.length - 1, start.length) == '%') {
  5486. b = parseInt(start) * w * 0.01;
  5487. } else {
  5488. b = parseInt(start);
  5489. }
  5490.  
  5491. }
  5492. if (obj['end'] == null) {
  5493. c = pm['x'] - b;
  5494. } else {
  5495. if (end.substring(end.length - 1, end.length) == '%') {
  5496. c = parseInt(end) * w * 0.01 - b;
  5497. } else if (end.substring(0, 1) == '-' || end.substring(0, 1) == '+') {
  5498. if (typeof (obj['end']) == 'number') {
  5499. c = parseInt(obj['end']) - b;
  5500. } else {
  5501. c = parseInt(end);
  5502. }
  5503.  
  5504. } else {
  5505. c = parseInt(end) - b;
  5506. }
  5507. }
  5508. break;
  5509. case 'y':
  5510. if (obj['start'] == null) {
  5511. b = pm['y'];
  5512. } else {
  5513. if (start.substring(start.length - 1, start.length) == '%') {
  5514. b = parseInt(start) * h * 0.01;
  5515. } else {
  5516. b = parseInt(start);
  5517. }
  5518.  
  5519. }
  5520. if (obj['end'] == null) {
  5521. c = pm['y'] - b;
  5522. } else {
  5523. if (end.substring(end.length - 1, end.length) == '%') {
  5524. c = parseInt(end) * h * 0.01 - b;
  5525. } else if (end.substring(0, 1) == '-' || end.substring(0, 1) == '+') {
  5526. if (typeof (obj['end']) == 'number') {
  5527. c = parseInt(obj['end']) - b;
  5528. } else {
  5529. c = parseInt(end);
  5530. }
  5531. } else {
  5532. c = parseInt(end) - b;
  5533. }
  5534. }
  5535. break;
  5536. case 'alpha':
  5537. if (obj['start'] == null) {
  5538. b = pm['alpha'] * 100;
  5539. } else {
  5540. if (start.substring(start.length - 1, start.length) == '%') {
  5541. b = parseInt(obj['start']);
  5542. } else {
  5543. b = parseInt(obj['start'] * 100);
  5544. }
  5545.  
  5546. }
  5547. if (obj['end'] == null) {
  5548. c = pm['alpha'] * 100 - b;
  5549. } else {
  5550. if (end.substring(end.length - 1, end.length) == '%') {
  5551. c = parseInt(end) - b;
  5552. } else if (end.substring(0, 1) == '-' || end.substring(0, 1) == '+') {
  5553. if (typeof (obj['end']) == 'number') {
  5554. c = parseInt(obj['end']) * 100 - b;
  5555. } else {
  5556. c = parseInt(obj['end']) * 100;
  5557. }
  5558. } else {
  5559. c = parseInt(obj['end']) * 100 - b;
  5560. }
  5561. }
  5562. break;
  5563. }
  5564. var callBack = function () {
  5565. var index = thisTemp.arrIndexOf(thisTemp.animateElementArray, animateId);
  5566. if (index > -1) {
  5567. thisTemp.animateArray.splice(index, 1);
  5568. thisTemp.animateElementArray.splice(index, 1);
  5569. }
  5570. index = thisTemp.arrIndexOf(thisTemp.animatePauseArray, animateId);
  5571. if (index > -1) {
  5572. thisTemp.animatePauseArray.splice(index, 1);
  5573. }
  5574. if (obj['callBack'] != null && obj['element'] && obj['callBack'] != 'callBack' && obj['callBack'] != 'tweenX' && obj['tweenY'] != 'callBack' && obj['callBack'] != 'tweenAlpha') {
  5575. var cb = eval(obj['callBack']);
  5576. cb(obj['element']);
  5577. obj['callBack'] = null;
  5578. }
  5579. };
  5580. var stopTween = function () {
  5581. if (timerTween != null) {
  5582. if (timerTween.runing) {
  5583. timerTween.stop();
  5584. }
  5585. timerTween = null;
  5586. }
  5587. };
  5588. var tweenX = function () {
  5589. if (t < d) {
  5590. t += 10;
  5591. css = {
  5592. left: Math.ceil(tweenFun(t, b, c, d)) + 'px'
  5593. };
  5594. if (obj['static']) {
  5595. eleCoor = thisTemp.calculationCoor(obj['element']);
  5596. css['top'] = eleCoor['y'] + 'px';
  5597. }
  5598. thisTemp.css(obj['element'], css);
  5599.  
  5600. } else {
  5601. stopTween();
  5602. thisTemp.elementArr.push(obj['element'].className);
  5603. callBack();
  5604. }
  5605. };
  5606. var tweenY = function () {
  5607. if (t < d) {
  5608. t += 10;
  5609. css = {
  5610. top: Math.ceil(tweenFun(t, b, c, d)) + 'px'
  5611. };
  5612. if (obj['static']) {
  5613. eleCoor = thisTemp.calculationCoor(obj['element']);
  5614. css['left'] = eleCoor['x'] + 'px';
  5615. }
  5616. thisTemp.css(obj['element'], css);
  5617. } else {
  5618. stopTween();
  5619. thisTemp.elementArr.push(obj['element'].className);
  5620. callBack();
  5621. }
  5622. };
  5623. var tweenAlpha = function () {
  5624. if (t < d) {
  5625. t += 10;
  5626. eleCoor = thisTemp.calculationCoor(obj['element']);
  5627. var ap = Math.ceil(tweenFun(t, b, c, d)) * 0.01;
  5628. css = {
  5629. filter: 'alpha(opacity:' + ap + ')',
  5630. opacity: ap.toString()
  5631. };
  5632. if (obj['static']) {
  5633. eleCoor = thisTemp.calculationCoor(obj['element']);
  5634. css['top'] = eleCoor['y'] + 'px';
  5635. css['left'] = eleCoor['x'] + 'px';
  5636. }
  5637. thisTemp.css(obj['element'], css);
  5638. } else {
  5639. stopTween();
  5640. thisTemp.elementArr.push(obj['element'].className);
  5641. callBack();
  5642. }
  5643. };
  5644. switch (obj['parameter']) {
  5645. case 'x':
  5646. tweenObj = tweenX;
  5647. break;
  5648. case 'y':
  5649. tweenObj = tweenY;
  5650. break;
  5651. case 'alpha':
  5652. tweenObj = tweenAlpha;
  5653. break;
  5654. default:
  5655. break;
  5656. }
  5657. timerTween = new thisTemp.timer(10, tweenObj);
  5658. timerTween.callBackFunction = callBack;
  5659. if (obj['overStop']) {
  5660. var mouseOver = function () {
  5661. if (timerTween != null && timerTween.runing) {
  5662. timerTween.stop();
  5663. }
  5664. };
  5665. this.addListenerInside('mouseover', mouseOver, obj['element']);
  5666. var mouseOut = function () {
  5667. var start = true;
  5668. if (obj['pauseStop'] && thisTemp.getMetaDate()['paused']) {
  5669. start = false;
  5670. }
  5671. if (timerTween != null && !timerTween.runing && start) {
  5672. timerTween.start();
  5673. }
  5674. };
  5675. this.addListenerInside('mouseout', mouseOut, obj['element']);
  5676. }
  5677.  
  5678. this.animateArray.push(timerTween);
  5679. this.animateElementArray.push(animateId);
  5680. if (obj['pauseStop']) {
  5681. this.animatePauseArray.push(animateId);
  5682. }
  5683. return animateId;
  5684. },
  5685. /*
  5686. 接口函数函数
  5687. 继续运行animate
  5688. */
  5689. animateResume: function (id) {
  5690. if (this.playerType == 'flashplayer') {
  5691. this.V.animateResume(this.isUndefined(id) ? '' : id);
  5692. return;
  5693. }
  5694. var arr = [];
  5695. if (id != '' && !this.isUndefined(id) && id != 'pause') {
  5696. arr.push(id);
  5697. } else {
  5698. if (id === 'pause') {
  5699. arr = this.animatePauseArray;
  5700. } else {
  5701. arr = this.animateElementArray;
  5702. }
  5703. }
  5704. for (var i = 0; i < arr.length; i++) {
  5705. var index = this.arrIndexOf(this.animateElementArray, arr[i]);
  5706. if (index > -1) {
  5707. this.animateArray[index].start();
  5708. }
  5709. }
  5710.  
  5711. },
  5712. /*
  5713. 接口函数
  5714. 暂停运行animate
  5715. */
  5716. animatePause: function (id) {
  5717. if (this.playerType == 'flashplayer') {
  5718. this.V.animatePause(this.isUndefined(id) ? '' : id);
  5719. return;
  5720. }
  5721. var arr = [];
  5722. if (id != '' && !this.isUndefined(id) && id != 'pause') {
  5723. arr.push(id);
  5724. } else {
  5725. if (id === 'pause') {
  5726. arr = this.animatePauseArray;
  5727. } else {
  5728. arr = this.animateElementArray;
  5729. }
  5730. }
  5731. for (var i = 0; i < arr.length; i++) {
  5732. var index = this.arrIndexOf(this.animateElementArray, arr[i]);
  5733. if (index > -1) {
  5734. this.animateArray[index].stop();
  5735. }
  5736. }
  5737. },
  5738. /*
  5739. 内置函数
  5740. 根据ID删除数组里对应的内容
  5741. */
  5742. deleteAnimate: function (id) {
  5743. if (this.playerType == 'flashplayer' && this.V) {
  5744. try {
  5745. this.V.deleteAnimate(id);
  5746. } catch (event) {
  5747. this.log(event);
  5748. }
  5749. return;
  5750. }
  5751. //console.log(this.animateElementArray)
  5752. var index = this.arrIndexOf(this.animateElementArray, id);
  5753. if (index > -1) {
  5754. this.animateArray[index].callBackFunction();
  5755. this.animateArray.splice(index, 1);
  5756. this.animateElementArray.splice(index, 1);
  5757. }
  5758. },
  5759. /*
  5760. 内置函数
  5761. 删除外部新建的元件
  5762. */
  5763. deleteElement: function (ele) {
  5764. if (this.playerType == 'flashplayer' && this.V) {
  5765. try {
  5766. this.V.deleteElement(ele);
  5767. } catch (event) {
  5768. }
  5769. return;
  5770. }
  5771. //先将该元件从元件数组里删除,让其不再跟随播放器的尺寸改变而改变位置
  5772. var def = this.arrIndexOf(this.elementArr, ele.className);
  5773. if (def > -1) {
  5774. this.elementArr.splice(def, 1);
  5775. }
  5776. this.deleteAnimate(ele);
  5777. this.deleteChild(ele);
  5778.  
  5779. },
  5780. /*
  5781. --------------------------------------------------------------
  5782. 共用函数部分
  5783. 以下函数并非只能在本程序中使用,也可以在页面其它项目中使用
  5784. 根据ID获取元素对象
  5785. */
  5786. getByElement: function (obj, parent) {
  5787. if (this.isUndefined(parent)) {
  5788. parent = document;
  5789. }
  5790. var num = obj.substr(0, 1);
  5791. var res = [];
  5792. if (num != '#') {
  5793. if (num == '.') {
  5794. obj = obj.substr(1, obj.length);
  5795. }
  5796. if (parent.getElementsByClassName) {
  5797. res = parent.getElementsByClassName(obj);
  5798. } else {
  5799. var reg = new RegExp(' ' + obj + ' ', 'i');
  5800. var ele = parent.getElementsByTagName('*');
  5801.  
  5802. for (var i = 0; i < ele.length; i++) {
  5803. if (reg.test(' ' + ele[i].className + ' ')) {
  5804. res.push(ele[i]);
  5805. }
  5806. }
  5807. }
  5808.  
  5809. if (res.length > 0) {
  5810. return res[0];
  5811. } else {
  5812. return res;
  5813. }
  5814. } else {
  5815. if (num == '#') {
  5816. obj = obj.substr(1, obj.length);
  5817. }
  5818. return document.getElementById(obj);
  5819. }
  5820. },
  5821. /*
  5822. 共用函数
  5823. 功能:修改样式或获取指定样式的值,
  5824. elem:ID对象或ID对应的字符,如果多个对象一起设置,则可以使用数组
  5825. attribute:样式名称或对象,如果是对象,则省略掉value值
  5826. value:attribute为样式名称时,定义的样式值
  5827. 示例一:
  5828. this.css(ID,'width','100px');
  5829. 示例二:
  5830. this.css('id','width','100px');
  5831. 示例三:
  5832. this.css([ID1,ID2,ID3],'width','100px');
  5833. 示例四:
  5834. this.css(ID,{
  5835. width:'100px',
  5836. height:'100px'
  5837. });
  5838. 示例五(获取宽度):
  5839. var width=this.css(ID,'width');
  5840. */
  5841. css: function (elem, attribute, value) {
  5842. var i = 0;
  5843. var k = '';
  5844. if (typeof (elem) == 'object') { //对象或数组
  5845. if (!this.isUndefined(typeof (elem.length))) { //说明是数组
  5846. for (i = 0; i < elem.length; i++) {
  5847. var el;
  5848. if (typeof (elem[i]) == 'string') {
  5849. el = this.getByElement(elem[i])
  5850. } else {
  5851. el = elem[i];
  5852. }
  5853. if (typeof (attribute) != 'object') {
  5854. if (!this.isUndefined(value)) {
  5855. el.style[attribute] = value;
  5856. }
  5857. } else {
  5858. for (k in attribute) {
  5859. if (!this.isUndefined(attribute[k])) {
  5860. el.style[k] = attribute[k];
  5861. }
  5862. }
  5863. }
  5864. }
  5865. return;
  5866. }
  5867.  
  5868. }
  5869. if (typeof (elem) == 'string') {
  5870. elem = this.getByElement(elem);
  5871. }
  5872.  
  5873. if (typeof (attribute) != 'object') {
  5874. if (!this.isUndefined(value)) {
  5875. elem.style[attribute] = value;
  5876. } else {
  5877. if (!this.isUndefined(this.getStyle(elem, attribute))) {
  5878. return this.getStyle(elem, attribute);
  5879. } else {
  5880. return false;
  5881. }
  5882. }
  5883. } else {
  5884. for (k in attribute) {
  5885. if (!this.isUndefined(attribute[k])) {
  5886. elem.style[k] = attribute[k];
  5887. }
  5888. }
  5889. }
  5890.  
  5891. },
  5892. /*
  5893. 内置函数
  5894. 兼容型获取style
  5895. */
  5896. getStyle: function (obj, attr) {
  5897. if (!this.isUndefined(obj.style[attr])) {
  5898. return obj.style[attr];
  5899. } else {
  5900. if (obj.currentStyle) {
  5901. return obj.currentStyle[attr];
  5902. } else {
  5903. return getComputedStyle(obj, false)[attr];
  5904. }
  5905. }
  5906. },
  5907. /*
  5908. 共用函数
  5909. 判断变量是否存在或值是否为undefined
  5910. */
  5911. isUndefined: function (value) {
  5912. try {
  5913. if (value == 'undefined' || value == undefined) {
  5914. return true;
  5915. }
  5916. } catch (event) {
  5917. this.log(event);
  5918. }
  5919. return false;
  5920. },
  5921. /*
  5922. 共用函数
  5923. 外部监听函数
  5924. */
  5925. addListener: function (name, funName) {
  5926. if (name && funName) {
  5927. if (this.playerType == 'flashplayer') {
  5928. var ff = ''; //定义用来向flashplayer传递的函数字符
  5929. if (typeof (funName) == 'function') {
  5930. ff = this.getParameterNames(funName);
  5931. }
  5932. this.V.addListener(name, ff);
  5933. return;
  5934. }
  5935. var have = false;
  5936. for (var i = 0; i < this.listenerJsArr.length; i++) {
  5937. var arr = this.listenerJsArr[i];
  5938. if (arr[0] == name && arr[1] == funName) {
  5939. have = true;
  5940. break;
  5941. }
  5942. }
  5943. if (!have) {
  5944. this.listenerJsArr.push([name, funName]);
  5945. }
  5946. }
  5947. },
  5948. /*
  5949. 共用函数
  5950. 外部删除监听函数
  5951. */
  5952. removeListener: function (name, funName) {
  5953. if (name && funName) {
  5954. if (this.playerType == 'flashplayer') {
  5955. var ff = ''; //定义用来向flashplayer传递的函数字符
  5956. if (typeof (funName) == 'function') {
  5957. ff = this.getParameterNames(funName);
  5958. }
  5959. this.V.removeListener(name, ff);
  5960. return;
  5961. }
  5962. for (var i = 0; i < this.listenerJsArr.length; i++) {
  5963. var arr = this.listenerJsArr[i];
  5964. if (arr[0] == name && arr[1] == funName) {
  5965. this.listenerJsArr.splice(i, 1);
  5966. break;
  5967. }
  5968. }
  5969. }
  5970. },
  5971. /*
  5972. 内部监听函数,调用方式:
  5973. this.addListenerInside('click',function(event){},[ID]);
  5974. d值为空时,则表示监听当前的视频播放器
  5975. */
  5976. addListenerInside: function (e, f, d, t) {
  5977. if (this.isUndefined(t)) {
  5978. t = false;
  5979. }
  5980. var o = this.V;
  5981. if (!this.isUndefined(d)) {
  5982. o = d;
  5983. }
  5984. if (o.addEventListener) {
  5985. try {
  5986. o.addEventListener(e, f, t);
  5987. } catch (event) {
  5988. }
  5989. } else if (o.attachEvent) {
  5990. try {
  5991. o.attachEvent('on' + e, f);
  5992. } catch (event) {
  5993. }
  5994. } else {
  5995. o['on' + e] = f;
  5996. }
  5997. },
  5998. /*
  5999. 删除内部监听函数,调用方式:
  6000. this.removeListenerInside('click',function(event){}[,ID]);
  6001. d值为空时,则表示监听当前的视频播放器
  6002. */
  6003. removeListenerInside: function (e, f, d, t) {
  6004. /*if(this.playerType=='flashplayer' && this.getParameterNames(f) && this.isUndefined(d)) {
  6005. return;
  6006. }*/
  6007. if (this.isUndefined(t)) {
  6008. t = false;
  6009. }
  6010. var o = this.V;
  6011. if (!this.isUndefined(d)) {
  6012. o = d;
  6013. }
  6014. if (o.removeEventListener) {
  6015. try {
  6016. this.addNum--;
  6017. o.removeEventListener(e, f, t);
  6018. } catch (e) {
  6019. }
  6020. } else if (o.detachEvent) {
  6021. try {
  6022. o.detachEvent('on' + e, f);
  6023. } catch (e) {
  6024. }
  6025. } else {
  6026. o['on' + e] = null;
  6027. }
  6028. },
  6029. /*
  6030. 共用函数
  6031. 统一分配监听,以达到跟as3同样效果
  6032. */
  6033. sendJS: function (name, val) {
  6034. var list = this.listenerJsArr;
  6035. var obj = {
  6036. variable: this.vars['variable']
  6037. };
  6038. if (this.vars['playerID']) {
  6039. obj['playerID'] = this.vars['playerID'];
  6040. }
  6041. for (var i = 0; i < list.length; i++) {
  6042. var arr = list[i];
  6043. if (arr[0] == name) {
  6044. if (val) {
  6045. switch (arr[1].length) {
  6046. case 1:
  6047. arr[1](val);
  6048. break;
  6049. case 2:
  6050. arr[1](val, obj);
  6051. break;
  6052. default:
  6053. arr[1]();
  6054. break;
  6055. }
  6056.  
  6057. } else {
  6058. switch (arr[1].length) {
  6059. case 1:
  6060. arr[1](obj);
  6061. break;
  6062. default:
  6063. arr[1]();
  6064. break;
  6065. }
  6066.  
  6067. }
  6068. }
  6069. }
  6070. },
  6071. /*
  6072. 共用函数
  6073. 获取函数名称,如 function ckplayer(){} var fun=ckplayer,则getParameterNames(fun)=ckplayer
  6074. */
  6075. getParameterNames: function (fn) {
  6076. if (typeof (fn) !== 'function') {
  6077. return false;
  6078. }
  6079. var COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg;
  6080. var code = fn.toString().replace(COMMENTS, '');
  6081. var result = code.slice(code.indexOf(' ') + 1, code.indexOf('('));
  6082. return result === null ? false : result;
  6083. },
  6084. /*
  6085. 共用函数
  6086. 获取当前本地时间
  6087. */
  6088. getNowDate: function () {
  6089. var nowDate = new Date();
  6090. var month = nowDate.getMonth() + 1;
  6091. var date = nowDate.getDate();
  6092. var hours = nowDate.getHours();
  6093. var minutes = nowDate.getMinutes();
  6094. var seconds = nowDate.getSeconds();
  6095. var tMonth = '',
  6096. tDate = '',
  6097. tHours = '',
  6098. tMinutes = '',
  6099. tSeconds = '',
  6100. tSeconds = (seconds < 10) ? '0' + seconds : seconds + '',
  6101. tMinutes = (minutes < 10) ? '0' + minutes : minutes + '',
  6102. tHours = (hours < 10) ? '0' + hours : hours + '',
  6103. tDate = (date < 10) ? '0' + date : date + '',
  6104. tMonth = (month < 10) ? '0' + month : month + '';
  6105. return tMonth + '/' + tDate + ' ' + tHours + ':' + tMinutes + ':' + tSeconds;
  6106. },
  6107. /*
  6108. 共用函数
  6109. 格式化时分秒
  6110. seconds:Int:秒数
  6111. ishours:Boolean:是否显示小时,如果设置成false,则会显示如80:20,表示1小时20分钟20秒
  6112. */
  6113. formatTime: function (seconds, ishours) {
  6114. var tSeconds = '',
  6115. tMinutes = '',
  6116. tHours = '';
  6117. if (isNaN(seconds)) {
  6118. seconds = 0;
  6119. }
  6120. var s = Math.floor(seconds % 60),
  6121. m = 0,
  6122. h = 0;
  6123. if (ishours) {
  6124. m = Math.floor(seconds / 60) % 60;
  6125. h = Math.floor(seconds / 3600);
  6126. } else {
  6127. m = Math.floor(seconds / 60);
  6128. }
  6129. tSeconds = (s < 10) ? '0' + s : s + '';
  6130. tMinutes = (m > 0) ? ((m < 10) ? '0' + m + ':' : m + ':') : '00:';
  6131. tHours = (h > 0) ? ((h < 10) ? '0' + h + ':' : h + ':') : '';
  6132. if (ishours) {
  6133. return tHours + tMinutes + tSeconds;
  6134. } else {
  6135. return tMinutes + tSeconds;
  6136. }
  6137. },
  6138. /*
  6139. 共用函数
  6140. 获取一个随机字符
  6141. len:随机字符长度
  6142. */
  6143. randomString: function (len) {
  6144. len = len || 16;
  6145. var chars = 'abcdefghijklmnopqrstuvwxyz';
  6146. var maxPos = chars.length;
  6147. var val = '';
  6148. for (i = 0; i < len; i++) {
  6149. val += chars.charAt(Math.floor(Math.random() * maxPos));
  6150. }
  6151. return 'ch' + val;
  6152. },
  6153. /*
  6154. 共用函数
  6155. 获取字符串长度,中文算两,英文数字算1
  6156. */
  6157. getStringLen: function (str) {
  6158. var len = 0;
  6159. for (var i = 0; i < str.length; i++) {
  6160. if (str.charCodeAt(i) > 127 || str.charCodeAt(i) == 94) {
  6161. len += 2;
  6162. } else {
  6163. len++;
  6164. }
  6165. }
  6166. return len;
  6167. },
  6168. /*
  6169. 内部函数
  6170. 用来为ajax提供支持
  6171. */
  6172. createXHR: function () {
  6173. if (window.XMLHttpRequest) {
  6174. //IE7+、Firefox、Opera、Chrome 和Safari
  6175. return new XMLHttpRequest();
  6176. } else if (window.ActiveXObject) {
  6177. //IE6 及以下
  6178. try {
  6179. return new ActiveXObject('Microsoft.XMLHTTP');
  6180. } catch (event) {
  6181. try {
  6182. return new ActiveXObject('Msxml2.XMLHTTP');
  6183. } catch (event) {
  6184. this.eject(this.errorList[7]);
  6185. }
  6186. }
  6187. } else {
  6188. this.eject(this.errorList[8]);
  6189. }
  6190. },
  6191. /*
  6192. 共用函数
  6193. ajax调用
  6194. */
  6195. ajax: function (cObj) {
  6196. var thisTemp = this;
  6197. var callback = null;
  6198. var obj = {
  6199. method: 'get', //请求类型
  6200. dataType: 'json', //请求的数据类型
  6201. charset: 'utf-8',
  6202. async: false, //true表示异步,false表示同步
  6203. url: '',
  6204. data: null,
  6205. success: null
  6206. };
  6207. if (typeof (cObj) != 'object') {
  6208. this.eject(this.errorList[9]);
  6209. return;
  6210. }
  6211. obj = this.standardization(obj, cObj);
  6212. if (obj.dataType === 'json' || obj.dataType === 'text' || obj.dataType === 'html') {
  6213. var xhr = this.createXHR();
  6214. callback = function () {
  6215. //判断http的交互是否成功
  6216. if (xhr.status == 200) {
  6217. if (obj.success == null) {
  6218. return;
  6219. }
  6220. if (obj.dataType === 'json') {
  6221. try {
  6222. obj.success(eval('(' + xhr.responseText + ')')); //回调传递参数
  6223. } catch (event) {
  6224. obj.success(null);
  6225. }
  6226. } else {
  6227. obj.success(xhr.responseText); //回调传递参数
  6228. }
  6229. } else {
  6230. thisTemp.eject(thisTemp.errorList[10], 'Ajax.status:' + xhr.status);
  6231. }
  6232. };
  6233. obj.url = obj.url + '?rand=' + this.randomString(6);
  6234. obj.data = this.formatParams(obj.data); //通过params()将名值对转换成字符串
  6235. if (obj.method === 'get' && !this.isUndefined(obj.data)) {
  6236. obj.url += obj.url.indexOf('?') == -1 ? '?' + obj.data : '&' + obj.data;
  6237. }
  6238. if (obj.async === true) { //true表示异步,false表示同步
  6239. xhr.onreadystatechange = function () {
  6240. if (xhr.readyState == 4) { //判断对象的状态是否交互完成
  6241. callback(); //回调
  6242. }
  6243. };
  6244. }
  6245. xhr.open(obj.method, obj.url, obj.async);
  6246. if (obj.method === 'post') {
  6247. xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  6248. xhr.setRequestHeader('charset', obj['charset']);
  6249. xhr.send(obj.data);
  6250. } else {
  6251. xhr.send(null); //get方式则填null
  6252. }
  6253. if (obj.async === false) { //同步
  6254. callback();
  6255. }
  6256.  
  6257. } else if (obj.dataType === 'jsonp') {
  6258. var oHead = document.getElementsByTagName('head')[0];
  6259. var oScript = document.createElement('script');
  6260. var callbackName = 'callback' + new Date().getTime();
  6261. var params = this.formatParams(obj.data) + '&callback=' + callbackName; //按时间戳拼接字符串
  6262. callback = obj.success;
  6263. //拼接好src
  6264. oScript.src = obj.url.split('?') + '?' + params;
  6265. //插入script标签
  6266. oHead.insertBefore(oScript, oHead.firstChild);
  6267. //jsonp的回调函数
  6268. window[callbackName] = function (json) {
  6269. callback(json);
  6270. oHead.removeChild(oScript);
  6271. };
  6272. }
  6273. },
  6274. /*
  6275. 内置函数
  6276. 动态加载js
  6277. */
  6278. loadJs: function (path, success) {
  6279. var oHead = document.getElementsByTagName('HEAD').item(0);
  6280. var oScript = document.createElement('script');
  6281. oScript.type = 'text/javascript';
  6282. oScript.src = this.getNewUrl(path);
  6283. oHead.appendChild(oScript);
  6284. oScript.onload = function () {
  6285. success();
  6286. }
  6287. },
  6288. /*
  6289. 共用函数
  6290. 排除IE6-9
  6291. */
  6292. isMsie: function () {
  6293. var browser = navigator.appName;
  6294. var b_version = navigator.appVersion;
  6295. var version = b_version.split(';');
  6296. var trim_Version = '';
  6297. if (version.length > 1) {
  6298. trim_Version = version[1].replace(/[ ]/g, '');
  6299. }
  6300. if (browser == 'Microsoft Internet Explorer' && (trim_Version == 'MSIE6.0' || trim_Version == 'MSIE7.0' || trim_Version == 'MSIE8.0' || trim_Version == 'MSIE9.0' || trim_Version == 'MSIE10.0')) {
  6301. return false;
  6302. }
  6303. return true;
  6304. },
  6305. /*
  6306. 共用函数
  6307. 判断是否安装了flashplayer
  6308. */
  6309. uploadFlash: function () {
  6310. var swf;
  6311. if (navigator.userAgent.indexOf('MSIE') > 0) {
  6312. try {
  6313. var swf = new ActiveXObject('ShockwaveFlash.ShockwaveFlash');
  6314. return true;
  6315. } catch (e) {
  6316. return false;
  6317. }
  6318. }
  6319. if (navigator.userAgent.indexOf('Firefox') > 0) {
  6320. swf = navigator.plugins['Shockwave Flash'];
  6321. if (swf) {
  6322. return true
  6323. } else {
  6324. return false;
  6325. }
  6326. }
  6327. return true;
  6328. },
  6329. /*
  6330. 共用函数
  6331. 检测浏览器是否支持HTML5-Video
  6332. */
  6333. supportVideo: function () {
  6334. if (!this.isMsie()) {
  6335. return false;
  6336. }
  6337. if (!!document.createElement('video').canPlayType) {
  6338. var vidTest = document.createElement('video');
  6339. var oggTest;
  6340. try {
  6341. oggTest = vidTest.canPlayType('video/ogg; codecs="theora, vorbis"');
  6342. } catch (error) {
  6343. oggTest = false;
  6344. }
  6345. if (!oggTest) {
  6346. var h264Test;
  6347. try {
  6348. h264Test = vidTest.canPlayType('video/mp4; codecs="avc1.42E01E, mp4a.40.2"');
  6349. } catch (error) {
  6350. h264Test = false;
  6351. }
  6352. if (!h264Test) {
  6353. return false;
  6354. } else {
  6355. if (h264Test == "probably") {
  6356. return true;
  6357. } else {
  6358. return false;
  6359. }
  6360. }
  6361. } else {
  6362. if (oggTest == "probably") {
  6363. return true;
  6364. } else {
  6365. return false;
  6366. }
  6367. }
  6368. } else {
  6369. return false;
  6370. }
  6371. },
  6372. /*
  6373. 共用函数
  6374. 获取属性值
  6375. */
  6376. getDataset: function (ele, z) {
  6377. try {
  6378. return ele.dataset[z];
  6379. } catch (error) {
  6380. try {
  6381. return ele.getAttribute('data-' + z)
  6382. } catch (error) {
  6383. return false;
  6384. }
  6385. }
  6386. },
  6387. /*
  6388. 共用函数
  6389. 返回flashplayer的对象
  6390. */
  6391. getObjectById: function (id) {
  6392. var x = null;
  6393. var y = this.getByElement('#' + id);
  6394. var r = 'embed';
  6395. if (y && y.nodeName == 'OBJECT') {
  6396. if (typeof (y.SetVariable) != 'undefined') {
  6397. x = y;
  6398. } else {
  6399. var z = y.getElementsByTagName(r)[0];
  6400. if (z) {
  6401. x = z;
  6402. }
  6403. }
  6404. }
  6405. return x;
  6406. },
  6407. /*
  6408. 共用函数
  6409. 对象转地址字符串
  6410. */
  6411. formatParams: function (data) {
  6412. var arr = [];
  6413. for (var i in data) {
  6414. arr.push(encodeURIComponent(i) + '=' + encodeURIComponent(data[i]));
  6415. }
  6416. return arr.join('&');
  6417. },
  6418. /*
  6419. 内置函数
  6420. 对地址进行冒泡排序
  6421. */
  6422. arrSort: function (arr) {
  6423. var temp = [];
  6424. for (var i = 0; i < arr.length; i++) {
  6425. for (var j = 0; j < arr.length - i; j++) {
  6426. if (!this.isUndefined(arr[j + 1]) && arr[j][3] < arr[j + 1][3]) {
  6427. temp = arr[j + 1];
  6428. arr[j + 1] = arr[j];
  6429. arr[j] = temp;
  6430. }
  6431. }
  6432. }
  6433. return arr;
  6434. },
  6435. /*
  6436. 内置函数
  6437. 判断文件后缀
  6438. */
  6439. getFileExt: function (filepath) {
  6440. if (filepath != '' && !this.isUndefined(filepath)) {
  6441. if (filepath.indexOf('?') > -1) {
  6442. filepath = filepath.split('?')[0];
  6443. }
  6444. var pos = '.' + filepath.replace(/.+\./, '');
  6445. return pos;
  6446. }
  6447. return '';
  6448. },
  6449. /*
  6450. 内置函数
  6451. 判断是否是移动端
  6452. */
  6453. isMobile: function () {
  6454. if (navigator.userAgent.match(/(iPhone|iPad|iPod|Android|ios)/i)) {
  6455. return true;
  6456. }
  6457. return false;
  6458. },
  6459. /*
  6460. 内置函数
  6461. 搜索字符串str是否包含key
  6462. */
  6463. isContains: function (str, key) {
  6464. return str.indexOf(key) > -1;
  6465. },
  6466. /*
  6467. 内置函数
  6468. 给地址添加随机数
  6469. */
  6470. getNewUrl: function (url) {
  6471. if (this.isContains(url, '?')) {
  6472. return url += '&' + this.randomString(8) + '=' + this.randomString(8);
  6473. } else {
  6474. return url += '?' + this.randomString(8) + '=' + this.randomString(8);
  6475. }
  6476. },
  6477. /*
  6478. 共用函数
  6479. 获取clientX和clientY
  6480. */
  6481. client: function (event) {
  6482. var eve = event || window.event;
  6483. if (this.isUndefined(eve)) {
  6484. eve = {
  6485. clientX: 0,
  6486. clientY: 0
  6487. };
  6488. }
  6489. return {
  6490. x: eve.clientX + (document.documentElement.scrollLeft || this.body.scrollLeft) - this.pdCoor['x'],
  6491. y: eve.clientY + (document.documentElement.scrollTop || this.body.scrollTop) - this.pdCoor['y']
  6492. }
  6493. },
  6494. /*
  6495. 内置函数
  6496. 获取节点的绝对坐标
  6497. */
  6498. getCoor: function (obj) {
  6499. var coor = this.getXY(obj);
  6500. return {
  6501. x: coor['x'] - this.pdCoor['x'],
  6502. y: coor['y'] - this.pdCoor['y']
  6503. };
  6504. },
  6505. getXY: function (obj) {
  6506. var parObj = obj;
  6507. var left = obj.offsetLeft;
  6508. var top = obj.offsetTop;
  6509. while (parObj = parObj.offsetParent) {
  6510. left += parObj.offsetLeft;
  6511. top += parObj.offsetTop;
  6512. }
  6513. return {
  6514. x: left,
  6515. y: top
  6516. };
  6517. },
  6518. /*
  6519. 内置函数
  6520. 删除本对象的所有属性
  6521. */
  6522. removeChild: function () {
  6523. if (this.playerType == 'html5video') {
  6524. //删除计时器
  6525. var i = 0;
  6526. var timerArr = [this.timerError, this.timerFull, this.timerTime, this.timerBuffer, this.timerClick, this.timerLoading, this.timerCBar, this.timerVCanvas];
  6527. for (i = 0; i < timerArr.length; i++) {
  6528. if (timerArr[i] != null) {
  6529. if (timerArr[i].runing) {
  6530. timerArr[i].stop();
  6531. }
  6532. timerArr[i] = null;
  6533. }
  6534. }
  6535. //删除事件监听
  6536. var ltArr = this.listenerJsArr;
  6537. for (i = 0; i < ltArr.length; i++) {
  6538. this.removeListener(ltArr[i][0], ltArr[i][1]);
  6539. }
  6540. }
  6541. this.playerType == '';
  6542. this.V = null;
  6543. if (this.showFace) {
  6544. this.deleteChild(this.CB['menu']);
  6545. }
  6546. this.deleteChild(this.PD);
  6547. this.CD.innerHTML = '';
  6548. },
  6549. /*
  6550. 内置函数
  6551. 画封闭的图形
  6552. */
  6553. canvasFill: function (name, path) {
  6554. name.beginPath();
  6555. for (var i = 0; i < path.length; i++) {
  6556. var d = path[i];
  6557. if (i > 0) {
  6558. name.lineTo(d[0], d[1]);
  6559. } else {
  6560. name.moveTo(d[0], d[1]);
  6561. }
  6562. }
  6563. name.closePath();
  6564. name.fill();
  6565. },
  6566. /*
  6567. 内置函数
  6568. 画矩形
  6569. */
  6570. canvasFillRect: function (name, path) {
  6571. for (var i = 0; i < path.length; i++) {
  6572. var d = path[i];
  6573. name.fillRect(d[0], d[1], d[2], d[3]);
  6574. }
  6575. },
  6576. /*
  6577. 共用函数
  6578. 删除容器节点
  6579. */
  6580. deleteChild: function (f) {
  6581. var def = this.arrIndexOf(this.elementArr, f.className);
  6582. if (def > -1) {
  6583. this.elementArr.splice(def, 1);
  6584. }
  6585. var childs = f.childNodes;
  6586. for (var i = childs.length - 1; i >= 0; i--) {
  6587. f.removeChild(childs[i]);
  6588. }
  6589.  
  6590. if (f && f != null && f.parentNode) {
  6591. try {
  6592. if (f.parentNode) {
  6593. f.parentNode.removeChild(f);
  6594.  
  6595. }
  6596.  
  6597. } catch (event) {
  6598. }
  6599. }
  6600. },
  6601. /*
  6602. 内置函数
  6603. 根据容器的宽高,内部节点的宽高计算出内部节点的宽高及坐标
  6604. */
  6605. getProportionCoor: function (stageW, stageH, vw, vh) {
  6606. var w = 0,
  6607. h = 0,
  6608. x = 0,
  6609. y = 0;
  6610. if (stageW / stageH < vw / vh) {
  6611. w = stageW;
  6612. h = w * vh / vw;
  6613. } else {
  6614. h = stageH;
  6615. w = h * vw / vh;
  6616. }
  6617. x = (stageW - w) * 0.5;
  6618. y = (stageH - h) * 0.5;
  6619. return {
  6620. width: parseInt(w),
  6621. height: parseInt(h),
  6622. x: parseInt(x),
  6623. y: parseInt(y)
  6624. };
  6625. },
  6626. /*
  6627. 共用函数
  6628. 将字幕文件内容转换成数组
  6629. */
  6630. parseSrtSubtitles: function (srt) {
  6631. var subtitles = [];
  6632. var textSubtitles = [];
  6633. var i = 0;
  6634. var arrs = srt.split('\n');
  6635. var arr = [];
  6636. var delHtmlTag = function (str) {
  6637. return str.replace(/<[^>]+>/g, ''); //去掉所有的html标记
  6638. };
  6639. for (i = 0; i < arrs.length; i++) {
  6640. if (arrs[i].replace(/\s/g, '').length > 0) {
  6641. arr.push(arrs[i]);
  6642. } else {
  6643. if (arr.length > 0) {
  6644. textSubtitles.push(arr);
  6645. }
  6646. arr = [];
  6647. }
  6648. }
  6649. for (i = 0; i < textSubtitles.length; ++i) {
  6650. var textSubtitle = textSubtitles[i];
  6651. if (textSubtitle.length >= 2) {
  6652. var sn = textSubtitle[0]; // 字幕的序号
  6653. var startTime = this.toSeconds(this.trim(textSubtitle[1].split(' --> ')[0])); // 字幕的开始时间
  6654. var endTime = this.toSeconds(this.trim(textSubtitle[1].split(' --> ')[1])); // 字幕的结束时间
  6655. var content = [delHtmlTag(textSubtitle[2])]; // 字幕的内容
  6656. // 字幕可能有多行
  6657. if (textSubtitle.length > 2) {
  6658. for (var j = 3; j < textSubtitle.length; j++) {
  6659. content.push(delHtmlTag(textSubtitle[j]));
  6660. }
  6661. }
  6662. // 字幕对象
  6663. var subtitle = {
  6664. sn: sn,
  6665. startTime: startTime,
  6666. endTime: endTime,
  6667. content: content
  6668. };
  6669. subtitles.push(subtitle);
  6670. }
  6671. }
  6672. return subtitles;
  6673. },
  6674. /*
  6675. 共用函数
  6676. 计时器,该函数模拟as3中的timer原理
  6677. time:计时时间,单位:毫秒
  6678. fun:接受函数
  6679. number:运行次数,不设置则无限运行
  6680. */
  6681. timer: function (time, fun, number) {
  6682. var thisTemp = this;
  6683. this.time = 10; //运行间隔
  6684. this.fun = null; //监听函数
  6685. this.timeObj = null; //setInterval对象
  6686. this.number = 0; //已运行次数
  6687. this.numberTotal = null; //总至需要次数
  6688. this.runing = false; //当前状态
  6689. this.startFun = function () {
  6690. thisTemp.number++;
  6691. thisTemp.fun();
  6692. if (thisTemp.numberTotal != null && thisTemp.number >= thisTemp.numberTotal) {
  6693. thisTemp.stop();
  6694. }
  6695. };
  6696. this.start = function () {
  6697. if (!thisTemp.runing) {
  6698. thisTemp.runing = true;
  6699. thisTemp.timeObj = window.setInterval(thisTemp.startFun, time);
  6700. }
  6701. };
  6702. this.stop = function () {
  6703. if (thisTemp.runing) {
  6704. thisTemp.runing = false;
  6705. window.clearInterval(thisTemp.timeObj);
  6706. thisTemp.timeObj = null;
  6707. }
  6708. };
  6709. if (time) {
  6710. this.time = time;
  6711. }
  6712. if (fun) {
  6713. this.fun = fun;
  6714. }
  6715. if (number) {
  6716. this.numberTotal = number;
  6717. }
  6718. this.start();
  6719. },
  6720. /*
  6721. 共用函数
  6722. 将时分秒转换成秒
  6723. */
  6724. toSeconds: function (t) {
  6725. var s = 0.0;
  6726. if (t) {
  6727. var p = t.split(':');
  6728. for (i = 0; i < p.length; i++) {
  6729. s = s * 60 + parseFloat(p[i].replace(',', '.'));
  6730. }
  6731. }
  6732. return s;
  6733. },
  6734. /*
  6735. 共用函数
  6736. 将对象Object标准化
  6737. */
  6738. standardization: function (o, n) { //n替换进o
  6739. var h = {};
  6740. var k;
  6741. for (k in o) {
  6742. h[k] = o[k];
  6743. }
  6744. for (k in n) {
  6745. var type = typeof (h[k]);
  6746. switch (type) {
  6747. case 'number':
  6748. h[k] = parseFloat(n[k]);
  6749. break;
  6750. default:
  6751. h[k] = n[k];
  6752. break;
  6753. }
  6754.  
  6755. }
  6756. return h;
  6757. },
  6758. /*
  6759. 共用函数
  6760. 搜索数组
  6761. */
  6762. arrIndexOf: function (arr, key) {
  6763. var re = new RegExp(key, ['']);
  6764. return(arr.toString().replace(re, '┢').replace(/[^,┢]/g, '')).indexOf('┢');
  6765. },
  6766. /*
  6767. 共用函数
  6768. 去掉空格
  6769. */
  6770. trim: function (str) {
  6771. if (str != '') {
  6772. return str.replace(/(^\s*)|(\s*$)/g, '');
  6773. }
  6774. return '';
  6775. },
  6776. /*
  6777. 共用函数
  6778. 输出内容到控制台
  6779. */
  6780. log: function (val) {
  6781. try {
  6782. console.log(val);
  6783. } catch (e) {
  6784. }
  6785. },
  6786. /*
  6787. 共用函数
  6788. 弹出提示
  6789. */
  6790. eject: function (er, val) {
  6791. if (!this.vars['debug']) {
  6792. return;
  6793. }
  6794. var errorVal = er[1];
  6795. if (!this.isUndefined(val)) {
  6796. errorVal = errorVal.replace('[error]', val);
  6797. }
  6798. var value = 'error ' + er[0] + ':' + errorVal;
  6799. try {
  6800. this.log(value);
  6801. } catch (e) {
  6802. }
  6803. }
  6804. };
  6805. window.ckplayer = ckplayer;
  6806. })();