U.PL.js 4.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. Namespace.register("U.PL");
  2. //#region 变量处理
  3. U.PL._er = {};
  4. U.PL._ev = ["loadstart", "ended", "progress", "suspend", "abort", "error", "stalled", "play", "pause", "loadedmetadata", "loadeddata", "waiting", "playing", "canplay", "readystatechange", "canplaythrough", "seeking", "seeked", "timeupdate", "ended", "ratechange", "durationchange", "volumechange"]; //vedio所有的事件
  5. //#endregoin
  6. //视频初始化
  7. U.PL.vi = function (UDE, UDPD, UCE) {
  8. if ($$("video").canPlayType) {
  9. return new U.PL.vi.init(UDE, UDPD, UCE);
  10. }
  11. else { return false; }
  12. }
  13. //初始化视屏播放器
  14. U.PL.vi.init = function (UDE, UDPD, UCE) {
  15. this.obj = UDE || {}; //
  16. this.pa = UDPD; //
  17. this.vi = null;//
  18. this.config(UCE);
  19. return this;
  20. }
  21. U.PL.vi.init.prototype = {
  22. type: { "ogg": 'video/ogg; codecs="theora, vorbis"', "mp4": 'video/mp4; codecs="avc1.42E01E, mp4a.40.2"', "webm": 'audio/webm; codecs="vorbis"' },
  23. attr: { at: "audioTracks", ap: "autoPlay", bf: "buffered", cl: "controller", cr: "controls", co: "crossOrigin", cs: "currentSrc", cTime: "currentTime", dm: "defaultMuted", dp: "defaultPlaybackRate", dt: "duration", ed: "ended", er: "error", lt: "initialTime", lp: "loop", mg: "mediaGroup", mt: "muted", ns: "networkState", pe: "paused", pr: "playbackRate", sTime: "startTime", pr: "playbackRate", py: "played", pl: "preload", rd: "readyState", si: "seeking", sk: "seekable", st: "startOffsetTime", tt: "textTracks", vt: "videoTracks", vl: "volume" }, // video属性
  24. config: function (UDE) { //配置文件
  25. U.Ut.AddObj((this.cf = this.cf || {}), UDE); U.Ut.AddObj(this.cf, { l: this.cf.l || 0, urls: this.cf.urls || [] }); //配置视频
  26. },
  27. init: function (UDE, UDPD, UCE) { //初始化视屏播放器
  28. U.Ut.AddObj(this, { obj: UDE || {}, pa: UDPD, vi: null }); this.config(UCE); return this;
  29. },
  30. create: function (URL, UDPD) { //src poster preload autoplay loop controls width height viode属性
  31. var _UCE = this.cf, _UVE = _UCE.html || { "style": { "cssText": "margin:auto;display:block;height:100%;width:auto;" }, "autoplay": "autoplay", "controls": "controls", "accesskey": true, "poster": "" };
  32. if ((URL = ((this.cf.urls.push(URL), URL) || this.cf.urls[this.l]))) {
  33. if (!this.vi) { this.vi = $$("video", _UVE, UDPD || this.pa || document.body); this.event(); } if (!U.Ut.isString(URL) && this.vi.srcObject) { this.vi.srcObject = URL } else { this.vi.src = U.Ut.isString(URL) ? URL : (window.URL || window.webkitURL).createObjectURL(URL); } this.set(this.obj); //if (this.isPaly(U.UP.GetUpName(URL)[1])) { };
  34. }
  35. else { U.Alert("链接无效"); }
  36. return this;
  37. },
  38. load: function (URL) { //重新加载
  39. URL = URL || this.cf.urls[this.cf.l]; if (this.vi) { this.vi.url = URL; } else { this.create(); }
  40. },
  41. event: function () { //事件监听
  42. var i, _UDOD = this.vi; //监听所有的事件
  43. if (U.PL._ev) { for (i = 0; i < U.PL._ev.length; i++) { U.M.AddEvent(U.PL._ev[i], _UDOD, U.M.apply(this, [[this.cb, [U.PL._ev[i]]]])); } }
  44. },
  45. cb: function (UTP) { //所有事件监听回调
  46. (this.cf[UTP]) && (this.cf[UTP])(); //回调函数
  47. return true;
  48. },
  49. getType: function (UTF) { //获取属性
  50. return this.vi[this.attr[UTF] || UTF];
  51. },
  52. set: function (UTP, UV) { //设置值
  53. var i, _UAE = this.attr, _USE = UTP; (U.Ut.isString(UTP)) && (_USE = {}, _USE[UTP] = UV);
  54. for (i in _USE) { this.vi[(_UAE[i] || i)] = _USE[i]; }
  55. },
  56. exec: function (UTF) { //执行获取
  57. return this[UTF] ? this[UTF]() : this.vi[UTF];
  58. },
  59. next: function () { //上一片
  60. var _URL; this.cf.l = this.cf.l - 1 < 0 ? this.cf.urls.length - 1 : this.cf.l - 1; if ((_URL = this.cf.urls[this.cf.l])) { this.load(_URL); }
  61. },
  62. lower: function () { //下一篇片
  63. var _URL; this.cf.l = this.cf.l + 1 >= this.cf.urls.length ? 0 : this.cf.l - 1; if ((_URL = this.cf.urls[this.cf.l])) { this.load(_URL); }
  64. },
  65. isPlay: function (UTF, UDOD) { //判断是否允许播放该格式
  66. return (UDOD || this.vi).canPlayType(this.type[UTF.toLowerCase()]);
  67. },
  68. play: function (UTF) { //播放和暂停
  69. this.vi[UTF ? "play" : "pause"]();
  70. },
  71. backRate: function (UVE) { //播放速度
  72. this.vi.playbackRate = UVE;
  73. },
  74. error: function (UE) { //发生错误
  75. var _UDE = ["", "网络异常", "解码失败", "URL无效"];
  76. (!UE.code) && (U.Alert(_UDE[UE.code]));
  77. },
  78. fullScreen: function () {//视频全屏
  79. var _funcname = U.M.GetFullSreeenName("requestFullScreen"); //全屏函数名
  80. if (_funcname != null)
  81. this.vi[_funcname](); //执行全屏函数
  82. },
  83. fullScreen: function () {//取消视频全屏
  84. U.M.cancelfullScreen();
  85. }
  86. }