From d390f223be881153799576e4121e2f3f6db74463 Mon Sep 17 00:00:00 2001 From: Kiwi Date: Wed, 13 May 2015 19:23:39 +0800 Subject: [PATCH] fix baseDir --- dist/player.js | 16 +++++----------- dist/player.min.js | 4 ++-- dist/zepto-player.js | 16 +++++----------- dist/zepto-player.min.js | 4 ++-- src/js/core/cfg.coffee | 2 -- src/js/player.coffee | 16 ++++++---------- 6 files changed, 20 insertions(+), 38 deletions(-) diff --git a/dist/player.js b/dist/player.js index 65a2aae..20d0204 100644 --- a/dist/player.js +++ b/dist/player.js @@ -21,7 +21,6 @@ namespace: root._mu, version: '1.0.0', timerResolution: 25, - cdn: 'http://apps.bdimg.com/libs/muplayer/', engine: { TYPES: { FLASH_MP3: 'FlashMP3Core', @@ -2396,7 +2395,7 @@ var slice = [].slice; instance = null; Player.defaults = { - baseDir: "" + cfg.cdn + cfg.version, + baseDir: 'http://mu5.bdstatic.com/cms/muplayer/1-0-0/', mode: 'loop', mute: false, volume: 80, @@ -2474,20 +2473,15 @@ var slice = [].slice; */ function Player(options) { - var baseDir, opts; + var baseDir, opts, singleton; this.opts = opts = $.extend({}, Player.defaults, options); this.waitingTimer = new Timer(100); this._checkFrozen(['play', 'pause', 'stop', 'next', 'prev', 'retry', 'replay', 'setVolume', 'setMute', 'setUrl', 'setCurrentPosition', '_startWaitingTimer']); - baseDir = opts.baseDir; - if (baseDir === false) { - baseDir = ''; - } else if (!baseDir) { - throw new Error("baseDir must be set! Usually, it should point to the MuPlayer's dist directory."); - } - if (baseDir && !baseDir.endsWith('/')) { + baseDir = opts.baseDir, singleton = opts.singleton; + if (!baseDir.endsWith('/')) { baseDir = baseDir + '/'; } - if (opts.singleton) { + if (singleton) { if (instance) { return instance; } diff --git a/dist/player.min.js b/dist/player.min.js index 5aabaae..5b98ead 100644 --- a/dist/player.min.js +++ b/dist/player.min.js @@ -3,5 +3,5 @@ // ------------------------- // (c) 2014 FE Team of Baidu Music // Can be freely distributed under the BSD license. -(function(t,e){if(typeof t._mu==="undefined"){t._mu={}}if(typeof exports==="object"){return module.exports=e()}else if(typeof define==="function"&&define.amd){return define("muplayer/core/cfg",e)}else{return t._mu.cfg=e()}})(this,function(){var t;t=this;return $.extend({namespace:t._mu,version:"1.0.0",timerResolution:25,cdn:"http://apps.bdimg.com/libs/muplayer/",engine:{TYPES:{FLASH_MP3:"FlashMP3Core",FLASH_MP4:"FlashMP4Core",AUDIO:"AudioCore"},EVENTS:{STATECHANGE:"engine:statechange",POSITIONCHANGE:"engine:postionchange",PROGRESS:"engine:progress",ERROR:"engine:error",INIT:"engine:init",INIT_FAIL:"engine:init_fail",WAITING_TIMEOUT:"engine:waiting_timeout"},STATES:{CANPLAYTHROUGH:"canplaythrough",PREBUFFER:"waiting",BUFFERING:"loadeddata",PLAYING:"playing",PAUSE:"pause",STOP:"suspend",END:"ended"},ERRCODE:{MEDIA_ERR_ABORTED:"1",MEDIA_ERR_NETWORK:"2",MEDIA_ERR_DECODE:"3",MEDIA_ERR_SRC_NOT_SUPPORTED:"4"}}},typeof t._mu==="undefined"?{}:t._mu.cfg)});(function(t,e){if(typeof exports==="object"){return module.exports=e()}else if(typeof define==="function"&&define.amd){return define("muplayer/core/utils",["muplayer/core/cfg"],e)}else{return t._mu.utils=e(t._mu.cfg)}})(this,function(t){var e,n,r,i,o,s,u,a,p,f,l,c,h,g,y,d,m;m={};i=String.prototype;n=Number.prototype;r=Object.prototype;e=Array.prototype;h=e.push;y=e.slice;d=r.toString;a=r.hasOwnProperty;c=Object.create;u=/\.(\w+)(\?.*)?$/;g=["Arguments","Function","String","Number","Date","RegExp"];for(p=0,f=g.length;p-1){r=n.split(p);f=[0,r.length],i=f[0],s=f[1];while(i";e.firstChild.href=t;e.innerHTML=e.innerHTML;return e.firstChild.href},getExt:function(t){var e;e="";if(u.test(decodeURIComponent(t))){e=RegExp.$1.toLocaleLowerCase()}return e}});return m});(function(t,e){if(typeof exports==="object"){module.exports=e()}else if(typeof define==="function"&&define.amd){define("muplayer/lib/Timer",e)}else{t._mu.Timer=e()}})(this,function(){function t(t){if(typeof t==="string"){if(isNaN(parseInt(t,10))){t="1"+t}var e=t.replace(/[^a-z0-9\.]/g,"").match(/(?:(\d+(?:\.\d+)?)(?:days?|d))?(?:(\d+(?:\.\d+)?)(?:hours?|hrs?|h))?(?:(\d+(?:\.\d+)?)(?:minutes?|mins?|m\b))?(?:(\d+(?:\.\d+)?)(?:seconds?|secs?|s))?(?:(\d+(?:\.\d+)?)(?:milliseconds?|ms))?/);if(e[0]){return parseFloat(e[1]||0)*864e5+parseFloat(e[2]||0)*36e5+parseFloat(e[3]||0)*6e4+parseFloat(e[4]||0)*1e3+parseInt(e[5]||0,10)}if(!isNaN(parseInt(t,10))){return parseInt(t,10)}}if(typeof t==="number"){return t}return 0}function e(t,e){return parseInt(t/e,10)||1}function n(e){if(this instanceof n===false){return new n(e)}this._notifications=[];this._resolution=t(e)||1e3;this._running=false;this._ticks=0;this._timer=null;this._drift=0}n.prototype={start:function(){var t=this;if(!this._running){this._running=!this._running;setTimeout(function e(){t._ticks++;for(var n=0,r=t._notifications.length;n=0;a-=2){if(!(r&&u[a]!==r||i&&u[a+1]!==i)){u.splice(a,2)}}}return this};e.prototype.trigger=function(e){var n,i,o,s,u,a,p=[],f,l=true;if(!(n=this.__events))return this;e=e.split(t);for(u=1,a=arguments.length;ue;0<=e?t++:t--){i.push(t)}return i}.apply(this));this.cur=this.list[this._listRandom[e]];return this.trigger("playlist:resetListRandom")}};e.prototype._formatSid=function(e){var n,r,i;n=this.opts.absoluteUrl;r=function(e){return n&&t.toAbsoluteUrl(e)||""+e};return $.isArray(e)&&function(){var t,n,o;o=[];for(t=0,n=e.length;t=s){this._supportedTypes.push(o)}}e={};i=new Audio;i.preload=p.preload;i.autoplay=p.autoplay;i.loop=false;i.on=function(t,n){var r;i.addEventListener(t,n,false);r=e[t];if(!r){r=[]}r.push(n);return i};i.off=function(t,n){var r,o,s;if(!t&&!n){for(t in e){s=e[t];for(r=0,o=s.length;ri?i:e;return i&&(e/i).toFixed(2)*1||0};n.prototype.getTotalTime=function(){var t,e,n,r,i;i=this.audio,r=i.duration,e=i.buffered,n=i.currentTime;r=~~r;if(r===0&&e){t=e.length;if(t>0){r=e.end(--t)}else{r=n}}return r&&r*1e3||0};return n}(n);return i});(function(t,e){if(typeof exports==="object"){module.exports=e()}else if(typeof define==="function"&&define.amd){define("muplayer/lib/jquery.swfobject",e)}else{e()}})(this,function(){(function(t,e,n){var r="object",i=true;function o(t,e){var n=(t[0]||0)-(e[0]||0);return n>0||!n&&t.length>0&&o(t.slice(1),e.slice(1))}function s(t){if(typeof t!=r){return t}var e=[],n="";for(var o in t){if(typeof t[o]==r){n=s(t[o])}else{n=[o,i?encodeURI(t[o]):t[o]].join("=")}e.push(n)}return e.join("&")}function u(t){var e=[];for(var n in t){if(t[n]){e.push([n,'="',t[n],'"'].join(""))}}return e.join(" ")}function a(t){var e=[];for(var n in t){e.push([''].join(""))}return e.join("")}try{var p=n.description||function(){return new n("ShockwaveFlash.ShockwaveFlash").GetVariable("$version")}()}catch(f){p="Unavailable"}var l=p.match(/\d+/g)||[0];t[e]={available:l[0]>0,activeX:n&&!n.name,version:{original:p,array:l,string:l.join("."),major:parseInt(l[0],10)||0,minor:parseInt(l[1],10)||0,release:parseInt(l[2],10)||0},hasVersion:function(t){var e=/string|number/.test(typeof t)?t.toString().split("."):/object/.test(typeof t)?[t.major,t.minor]:t||[0,0];return o(l,e)},encodeParams:true,expressInstall:"expressInstall.swf",expressInstallIsActive:false,create:function(t){var e=this;if(!t.swf||e.expressInstallIsActive||!e.available&&!t.hasVersionFail){return false}if(!e.hasVersion(t.hasVersion||1)){e.expressInstallIsActive=true;if(typeof t.hasVersionFail=="function"){if(!t.hasVersionFail.apply(t)){return false}}t={swf:t.expressInstall||e.expressInstall,height:137,width:214,flashvars:{MMredirectURL:location.href,MMplayerType:e.activeX?"ActiveX":"PlugIn",MMdoctitle:document.title.slice(0,47)+" - Flash Player Installation"}}}attrs={data:t.swf,type:"application/x-shockwave-flash",id:t.id||"flash_"+Math.floor(Math.random()*999999999),width:t.width||320,height:t.height||180,style:t.style||""};i=typeof t.useEncode!=="undefined"?t.useEncode:e.encodeParams;t.movie=t.swf;t.wmode=t.wmode||"opaque";delete t.fallback;delete t.hasVersion;delete t.hasVersionFail;delete t.height;delete t.id;delete t.swf;delete t.useEncode;delete t.width;var n=document.createElement("div");n.innerHTML=["",a(t),""].join("");return n.firstChild}};t.fn[e]=function(n){var i=this.find(r).andSelf().filter(r);if(/string|object/.test(typeof n)){this.each(function(){var i=t(this),o;n=typeof n==r?n:{swf:n};n.fallback=this;o=t[e].create(n);if(o){i.children().remove();i.html(o)}})}if(typeof n=="function"){i.each(function(){var r=this,i="jsInteractionTimeoutMs";r[i]=r[i]||0;if(r[i]<660){if(r.clientWidth||r.clientHeight){n.call(r)}else{setTimeout(function(){t(r)[e](n)},r[i]+66)}}})}return i}})(jQuery,"flash",navigator.plugins["Shockwave Flash"]||window.ActiveXObject)});var extend=function(t,e){for(var n in e){if(hasProp.call(e,n))t[n]=e[n]}function r(){this.constructor=t}r.prototype=e.prototype;t.prototype=new r;t.__super__=e.prototype;return t},hasProp={}.hasOwnProperty,slice=[].slice;(function(t,e){if(typeof exports==="object"){return module.exports=e()}else if(typeof define==="function"&&define.amd){return define("muplayer/core/engines/flashCore",["muplayer/core/cfg","muplayer/core/utils","muplayer/lib/Timer","muplayer/core/engines/engineCore","muplayer/lib/jquery.swfobject"],e)}else{return t._mu.FlashCore=e(_mu.cfg,_mu.utils,_mu.Timer,_mu.EngineCore)}})(this,function(t,e,n,r){var i,o,s,u,a,p,f;p=t.engine,o=p.EVENTS,u=p.STATES,i=p.ERRCODE;f=t.timerResolution;a={1:u.CANPLAYTHROUGH,2:u.PREBUFFER,3:u.BUFFERING,4:u.PLAYING,5:u.PAUSE,6:u.STOP,7:u.END};s=function(t){extend(r,t);r.defaults={expressInstaller:"expressInstall.swf"};function r(t){var n,i,o,s;this.opts=s=$.extend({},r.defaults,this.defaults,t);this._state=u.STOP;this._loaded=false;this._queue=[];this._needFlashReady(["play","pause","stop","setCurrentPosition","_setUrl","_setVolume","_setMute"]);this._unexceptionGet(["getCurrentPosition","getLoadedPercent","getTotalTime"]);n=s.baseDir;i="muplayer_"+setTimeout(function(){},0);o=s.instanceName+"_"+i;e.namespace("engines")[o]=this;o="_mu.engines."+o;this.flash=$.flash.create({swf:n+s.swf+"?t="+ +new Date,id:i,height:1,width:1,allowscriptaccess:"always",wmode:"transparent",expressInstaller:n+s.expressInstaller,flashvars:{_instanceName:o,_buffertime:5e3}});this.flash.tabIndex=-1;s.$el.append(this.flash);this._initEvents()}r.prototype._test=function(){if(!this.flash||!$.flash.hasVersion(this.opts.flashVer)){return false}return true};r.prototype._initEvents=function(){var t,e,r;t=this;this.progressTimer=new n(f);this.positionTimer=new n(f);r=function(){var e;e=t.getLoadedPercent();if(t._lastPer!==e){t._lastPer=e;t.trigger(o.PROGRESS,e)}if(e===1){return t.progressTimer.stop()}};e=function(){var e;e=t.getCurrentPosition();if(t._lastPos!==e){t._lastPos=e;return t.trigger(o.POSITIONCHANGE,e)}};this.progressTimer.every("100 ms",r);this.positionTimer.every("100 ms",e);return this.on(o.STATECHANGE,function(n){var r;r=n.newState;switch(r){case u.PREBUFFER:case u.PLAYING:t.progressTimer.start();break;case u.PAUSE:case u.STOP:t.progressTimer.stop();break;case u.END:t.progressTimer.reset()}switch(r){case u.PLAYING:return t.positionTimer.start();case u.PAUSE:case u.STOP:t.positionTimer.stop();return e();case u.END:t.positionTimer.reset();return delete t._lastPos}})};r.prototype._needFlashReady=function(t){var n,r,i,o;o=[];for(n=0,r=t.length;n';Engine.prototype.defaults={engines:[{type:FlashMP3Core},{type:FlashMP4Core},{type:AudioCore}]};function Engine(t){this.opts=$.extend({},this.defaults,t);this._initEngines()}Engine.prototype._initEngines=function(){var $el,args,engine,i,j,len,opts,ref1,type;this.engines=[];opts=this.opts;this.$el=$el=$(Engine.el.replace(/{{DATETIME}}/g,+new Date)).appendTo("body");this._lastE={};ref1=opts.engines;for(i=j=0,len=ref1.length;j=0&&t<=100){this.curEngine.setVolume(t)}return this};Engine.prototype.getVolume=function(){return this.curEngine.getVolume()};Engine.prototype.setCurrentPosition=function(t){t=~~t;this.curEngine.setCurrentPosition(t);return this};Engine.prototype.getCurrentPosition=function(){if(this.getState()===STATES.STOP){this.setCurrentPosition(0)}return this.curEngine.getCurrentPosition()};Engine.prototype.getLoadedPercent=function(){return this.curEngine.getLoadedPercent()};Engine.prototype.getTotalTime=function(){return this.curEngine.getTotalTime()};Engine.prototype.getEngineType=function(){return this.curEngine.engineType};return Engine}();Events.mixTo(Engine);return Engine});var slice=[].slice;(function(t,e){if(typeof exports==="object"){return module.exports=e()}else if(typeof define==="function"&&define.amd){return define("muplayer/player",["muplayer/core/cfg","muplayer/core/utils","muplayer/lib/Timer","muplayer/lib/events","muplayer/core/playlist","muplayer/core/engines/engine"],e)}else{return t._mu.Player=e(_mu.cfg,_mu.utils,_mu.Timer,_mu.Events,_mu.Playlist,_mu.Engine)}})(this,function(t,e,n,r,i,o){var s,u,a,p,f,l;f=t.engine,s=f.EVENTS,a=f.STATES;l=e.time2str;p=function(t,e){var n,r;if(t!=="prev"&&t!=="next"){return this}r=function(n){return function(){var r;r={cur:n.getCur()};if(e){r.auto=e}n.trigger("player:"+t,r);return n.stop(false).play()}}(this);if(this.getSongsNum()){n=this.playlist;if(!n.cur){r()}else if(n[t].call(n,e)){r()}else{this.trigger("player:"+t+":fail",e)}}return this};u=function(){var r;r=null;u.defaults={baseDir:""+t.cdn+t.version,mode:"loop",mute:false,volume:80,singleton:true,absoluteUrl:true,maxRetryTimes:1,maxWaitingTime:4,recoverMethod:"retry",fetch:function(){var t,e;e=$.Deferred();t=this.getCur();setTimeout(function(n){return function(){n.setUrl(t);return e.resolve()}}(this),0);return e.promise()}};function u(t){var e,s;this.opts=s=$.extend({},u.defaults,t);this.waitingTimer=new n(100);this._checkFrozen(["play","pause","stop","next","prev","retry","replay","setVolume","setMute","setUrl","setCurrentPosition","_startWaitingTimer"]);e=s.baseDir;if(e===false){e=""}else if(!e){throw new Error("baseDir must be set! Usually, it should point to the MuPlayer's dist directory.")}if(e&&!e.endsWith("/")){e=e+"/"}if(s.singleton){if(r){return r}r=this}this.playlist=new i({absoluteUrl:s.absoluteUrl});this.playlist.setMode(s.mode);this._initEngine(new o({baseDir:e,engines:s.engines}));this.setMute(s.mute);this.setVolume(s.volume);this.reset()}u.prototype._initEngine=function(t){var e,n;n=this;e=this.opts.recoverMethod;this.engine=t;return this.engine.on(s.STATECHANGE,function(t){var e;e=t.newState;n.trigger("player:statechange",t);n.trigger(e);if(e===a.END){return n._clearWaitingTimer().next(true)}}).on(s.POSITIONCHANGE,function(t){var e;t=~~t;if(!t){return}e=n.getState();if(n.getUrl()&&(e===a.PLAYING||e===a.PREBUFFER||e===a.BUFFERING||e===a.CANPLAYTHROUGH)){n.trigger("timeupdate",t);return n._startWaitingTimer()}}).on(s.PROGRESS,function(t){return n.trigger("progress",t)}).on(s.ERROR,function(t){if(n.getUrl()){if(typeof console!=="undefined"&&console!==null){if(typeof console.error==="function"){console.error("error: ",t)}}return n.trigger("error",t)}}).on(s.WAITING_TIMEOUT,function(){if(n.getEngineType()==="AudioCore"&&n.engine.curEngine._isEmpty()){return}if(!n.getUrl()){return}if(e==="retry"||e==="next"){n[e]()}return n.trigger("player:waiting_timeout")})};u.prototype.retry=function(){var t,e,n;if(this._retryTimes++0){this.waitingTimer.clear().after(t+" seconds",function(t){return function(){return t.engine.trigger(s.WAITING_TIMEOUT)}}(this)).start()}return this};u.prototype._clearWaitingTimer=function(){this.waitingTimer.clear();return this};return u}();r.mixTo(u);return u}); \ No newline at end of file +(function(t,e){if(typeof t._mu==="undefined"){t._mu={}}if(typeof exports==="object"){return module.exports=e()}else if(typeof define==="function"&&define.amd){return define("muplayer/core/cfg",e)}else{return t._mu.cfg=e()}})(this,function(){var t;t=this;return $.extend({namespace:t._mu,version:"1.0.0",timerResolution:25,engine:{TYPES:{FLASH_MP3:"FlashMP3Core",FLASH_MP4:"FlashMP4Core",AUDIO:"AudioCore"},EVENTS:{STATECHANGE:"engine:statechange",POSITIONCHANGE:"engine:postionchange",PROGRESS:"engine:progress",ERROR:"engine:error",INIT:"engine:init",INIT_FAIL:"engine:init_fail",WAITING_TIMEOUT:"engine:waiting_timeout"},STATES:{CANPLAYTHROUGH:"canplaythrough",PREBUFFER:"waiting",BUFFERING:"loadeddata",PLAYING:"playing",PAUSE:"pause",STOP:"suspend",END:"ended"},ERRCODE:{MEDIA_ERR_ABORTED:"1",MEDIA_ERR_NETWORK:"2",MEDIA_ERR_DECODE:"3",MEDIA_ERR_SRC_NOT_SUPPORTED:"4"}}},typeof t._mu==="undefined"?{}:t._mu.cfg)});(function(t,e){if(typeof exports==="object"){return module.exports=e()}else if(typeof define==="function"&&define.amd){return define("muplayer/core/utils",["muplayer/core/cfg"],e)}else{return t._mu.utils=e(t._mu.cfg)}})(this,function(t){var e,n,r,i,o,s,u,a,p,f,l,c,h,g,y,d,m;m={};i=String.prototype;n=Number.prototype;r=Object.prototype;e=Array.prototype;h=e.push;y=e.slice;d=r.toString;a=r.hasOwnProperty;c=Object.create;u=/\.(\w+)(\?.*)?$/;g=["Arguments","Function","String","Number","Date","RegExp"];for(p=0,f=g.length;p-1){r=n.split(p);f=[0,r.length],i=f[0],s=f[1];while(i";e.firstChild.href=t;e.innerHTML=e.innerHTML;return e.firstChild.href},getExt:function(t){var e;e="";if(u.test(decodeURIComponent(t))){e=RegExp.$1.toLocaleLowerCase()}return e}});return m});(function(t,e){if(typeof exports==="object"){module.exports=e()}else if(typeof define==="function"&&define.amd){define("muplayer/lib/Timer",e)}else{t._mu.Timer=e()}})(this,function(){function t(t){if(typeof t==="string"){if(isNaN(parseInt(t,10))){t="1"+t}var e=t.replace(/[^a-z0-9\.]/g,"").match(/(?:(\d+(?:\.\d+)?)(?:days?|d))?(?:(\d+(?:\.\d+)?)(?:hours?|hrs?|h))?(?:(\d+(?:\.\d+)?)(?:minutes?|mins?|m\b))?(?:(\d+(?:\.\d+)?)(?:seconds?|secs?|s))?(?:(\d+(?:\.\d+)?)(?:milliseconds?|ms))?/);if(e[0]){return parseFloat(e[1]||0)*864e5+parseFloat(e[2]||0)*36e5+parseFloat(e[3]||0)*6e4+parseFloat(e[4]||0)*1e3+parseInt(e[5]||0,10)}if(!isNaN(parseInt(t,10))){return parseInt(t,10)}}if(typeof t==="number"){return t}return 0}function e(t,e){return parseInt(t/e,10)||1}function n(e){if(this instanceof n===false){return new n(e)}this._notifications=[];this._resolution=t(e)||1e3;this._running=false;this._ticks=0;this._timer=null;this._drift=0}n.prototype={start:function(){var t=this;if(!this._running){this._running=!this._running;setTimeout(function e(){t._ticks++;for(var n=0,r=t._notifications.length;n=0;a-=2){if(!(r&&u[a]!==r||i&&u[a+1]!==i)){u.splice(a,2)}}}return this};e.prototype.trigger=function(e){var n,i,o,s,u,a,p=[],f,l=true;if(!(n=this.__events))return this;e=e.split(t);for(u=1,a=arguments.length;ue;0<=e?t++:t--){i.push(t)}return i}.apply(this));this.cur=this.list[this._listRandom[e]];return this.trigger("playlist:resetListRandom")}};e.prototype._formatSid=function(e){var n,r,i;n=this.opts.absoluteUrl;r=function(e){return n&&t.toAbsoluteUrl(e)||""+e};return $.isArray(e)&&function(){var t,n,o;o=[];for(t=0,n=e.length;t=s){this._supportedTypes.push(o)}}e={};i=new Audio;i.preload=p.preload;i.autoplay=p.autoplay;i.loop=false;i.on=function(t,n){var r;i.addEventListener(t,n,false);r=e[t];if(!r){r=[]}r.push(n);return i};i.off=function(t,n){var r,o,s;if(!t&&!n){for(t in e){s=e[t];for(r=0,o=s.length;ri?i:e;return i&&(e/i).toFixed(2)*1||0};n.prototype.getTotalTime=function(){var t,e,n,r,i;i=this.audio,r=i.duration,e=i.buffered,n=i.currentTime;r=~~r;if(r===0&&e){t=e.length;if(t>0){r=e.end(--t)}else{r=n}}return r&&r*1e3||0};return n}(n);return i});(function(t,e){if(typeof exports==="object"){module.exports=e()}else if(typeof define==="function"&&define.amd){define("muplayer/lib/jquery.swfobject",e)}else{e()}})(this,function(){(function(t,e,n){var r="object",i=true;function o(t,e){var n=(t[0]||0)-(e[0]||0);return n>0||!n&&t.length>0&&o(t.slice(1),e.slice(1))}function s(t){if(typeof t!=r){return t}var e=[],n="";for(var o in t){if(typeof t[o]==r){n=s(t[o])}else{n=[o,i?encodeURI(t[o]):t[o]].join("=")}e.push(n)}return e.join("&")}function u(t){var e=[];for(var n in t){if(t[n]){e.push([n,'="',t[n],'"'].join(""))}}return e.join(" ")}function a(t){var e=[];for(var n in t){e.push([''].join(""))}return e.join("")}try{var p=n.description||function(){return new n("ShockwaveFlash.ShockwaveFlash").GetVariable("$version")}()}catch(f){p="Unavailable"}var l=p.match(/\d+/g)||[0];t[e]={available:l[0]>0,activeX:n&&!n.name,version:{original:p,array:l,string:l.join("."),major:parseInt(l[0],10)||0,minor:parseInt(l[1],10)||0,release:parseInt(l[2],10)||0},hasVersion:function(t){var e=/string|number/.test(typeof t)?t.toString().split("."):/object/.test(typeof t)?[t.major,t.minor]:t||[0,0];return o(l,e)},encodeParams:true,expressInstall:"expressInstall.swf",expressInstallIsActive:false,create:function(t){var e=this;if(!t.swf||e.expressInstallIsActive||!e.available&&!t.hasVersionFail){return false}if(!e.hasVersion(t.hasVersion||1)){e.expressInstallIsActive=true;if(typeof t.hasVersionFail=="function"){if(!t.hasVersionFail.apply(t)){return false}}t={swf:t.expressInstall||e.expressInstall,height:137,width:214,flashvars:{MMredirectURL:location.href,MMplayerType:e.activeX?"ActiveX":"PlugIn",MMdoctitle:document.title.slice(0,47)+" - Flash Player Installation"}}}attrs={data:t.swf,type:"application/x-shockwave-flash",id:t.id||"flash_"+Math.floor(Math.random()*999999999),width:t.width||320,height:t.height||180,style:t.style||""};i=typeof t.useEncode!=="undefined"?t.useEncode:e.encodeParams;t.movie=t.swf;t.wmode=t.wmode||"opaque";delete t.fallback;delete t.hasVersion;delete t.hasVersionFail;delete t.height;delete t.id;delete t.swf;delete t.useEncode;delete t.width;var n=document.createElement("div");n.innerHTML=["",a(t),""].join("");return n.firstChild}};t.fn[e]=function(n){var i=this.find(r).andSelf().filter(r);if(/string|object/.test(typeof n)){this.each(function(){var i=t(this),o;n=typeof n==r?n:{swf:n};n.fallback=this;o=t[e].create(n);if(o){i.children().remove();i.html(o)}})}if(typeof n=="function"){i.each(function(){var r=this,i="jsInteractionTimeoutMs";r[i]=r[i]||0;if(r[i]<660){if(r.clientWidth||r.clientHeight){n.call(r)}else{setTimeout(function(){t(r)[e](n)},r[i]+66)}}})}return i}})(jQuery,"flash",navigator.plugins["Shockwave Flash"]||window.ActiveXObject)});var extend=function(t,e){for(var n in e){if(hasProp.call(e,n))t[n]=e[n]}function r(){this.constructor=t}r.prototype=e.prototype;t.prototype=new r;t.__super__=e.prototype;return t},hasProp={}.hasOwnProperty,slice=[].slice;(function(t,e){if(typeof exports==="object"){return module.exports=e()}else if(typeof define==="function"&&define.amd){return define("muplayer/core/engines/flashCore",["muplayer/core/cfg","muplayer/core/utils","muplayer/lib/Timer","muplayer/core/engines/engineCore","muplayer/lib/jquery.swfobject"],e)}else{return t._mu.FlashCore=e(_mu.cfg,_mu.utils,_mu.Timer,_mu.EngineCore)}})(this,function(t,e,n,r){var i,o,s,u,a,p,f;p=t.engine,o=p.EVENTS,u=p.STATES,i=p.ERRCODE;f=t.timerResolution;a={1:u.CANPLAYTHROUGH,2:u.PREBUFFER,3:u.BUFFERING,4:u.PLAYING,5:u.PAUSE,6:u.STOP,7:u.END};s=function(t){extend(r,t);r.defaults={expressInstaller:"expressInstall.swf"};function r(t){var n,i,o,s;this.opts=s=$.extend({},r.defaults,this.defaults,t);this._state=u.STOP;this._loaded=false;this._queue=[];this._needFlashReady(["play","pause","stop","setCurrentPosition","_setUrl","_setVolume","_setMute"]);this._unexceptionGet(["getCurrentPosition","getLoadedPercent","getTotalTime"]);n=s.baseDir;i="muplayer_"+setTimeout(function(){},0);o=s.instanceName+"_"+i;e.namespace("engines")[o]=this;o="_mu.engines."+o;this.flash=$.flash.create({swf:n+s.swf+"?t="+ +new Date,id:i,height:1,width:1,allowscriptaccess:"always",wmode:"transparent",expressInstaller:n+s.expressInstaller,flashvars:{_instanceName:o,_buffertime:5e3}});this.flash.tabIndex=-1;s.$el.append(this.flash);this._initEvents()}r.prototype._test=function(){if(!this.flash||!$.flash.hasVersion(this.opts.flashVer)){return false}return true};r.prototype._initEvents=function(){var t,e,r;t=this;this.progressTimer=new n(f);this.positionTimer=new n(f);r=function(){var e;e=t.getLoadedPercent();if(t._lastPer!==e){t._lastPer=e;t.trigger(o.PROGRESS,e)}if(e===1){return t.progressTimer.stop()}};e=function(){var e;e=t.getCurrentPosition();if(t._lastPos!==e){t._lastPos=e;return t.trigger(o.POSITIONCHANGE,e)}};this.progressTimer.every("100 ms",r);this.positionTimer.every("100 ms",e);return this.on(o.STATECHANGE,function(n){var r;r=n.newState;switch(r){case u.PREBUFFER:case u.PLAYING:t.progressTimer.start();break;case u.PAUSE:case u.STOP:t.progressTimer.stop();break;case u.END:t.progressTimer.reset()}switch(r){case u.PLAYING:return t.positionTimer.start();case u.PAUSE:case u.STOP:t.positionTimer.stop();return e();case u.END:t.positionTimer.reset();return delete t._lastPos}})};r.prototype._needFlashReady=function(t){var n,r,i,o;o=[];for(n=0,r=t.length;n';Engine.prototype.defaults={engines:[{type:FlashMP3Core},{type:FlashMP4Core},{type:AudioCore}]};function Engine(t){this.opts=$.extend({},this.defaults,t);this._initEngines()}Engine.prototype._initEngines=function(){var $el,args,engine,i,j,len,opts,ref1,type;this.engines=[];opts=this.opts;this.$el=$el=$(Engine.el.replace(/{{DATETIME}}/g,+new Date)).appendTo("body");this._lastE={};ref1=opts.engines;for(i=j=0,len=ref1.length;j=0&&t<=100){this.curEngine.setVolume(t)}return this};Engine.prototype.getVolume=function(){return this.curEngine.getVolume()};Engine.prototype.setCurrentPosition=function(t){t=~~t;this.curEngine.setCurrentPosition(t);return this};Engine.prototype.getCurrentPosition=function(){if(this.getState()===STATES.STOP){this.setCurrentPosition(0)}return this.curEngine.getCurrentPosition()};Engine.prototype.getLoadedPercent=function(){return this.curEngine.getLoadedPercent()};Engine.prototype.getTotalTime=function(){return this.curEngine.getTotalTime()};Engine.prototype.getEngineType=function(){return this.curEngine.engineType};return Engine}();Events.mixTo(Engine);return Engine});var slice=[].slice;(function(t,e){if(typeof exports==="object"){return module.exports=e()}else if(typeof define==="function"&&define.amd){return define("muplayer/player",["muplayer/core/cfg","muplayer/core/utils","muplayer/lib/Timer","muplayer/lib/events","muplayer/core/playlist","muplayer/core/engines/engine"],e)}else{return t._mu.Player=e(_mu.cfg,_mu.utils,_mu.Timer,_mu.Events,_mu.Playlist,_mu.Engine)}})(this,function(t,e,n,r,i,o){var s,u,a,p,f,l;f=t.engine,s=f.EVENTS,a=f.STATES;l=e.time2str;p=function(t,e){var n,r;if(t!=="prev"&&t!=="next"){return this}r=function(n){return function(){var r;r={cur:n.getCur()};if(e){r.auto=e}n.trigger("player:"+t,r);return n.stop(false).play()}}(this);if(this.getSongsNum()){n=this.playlist;if(!n.cur){r()}else if(n[t].call(n,e)){r()}else{this.trigger("player:"+t+":fail",e)}}return this};u=function(){var t;t=null;r.defaults={baseDir:"http://mu5.bdstatic.com/cms/muplayer/1-0-0/",mode:"loop",mute:false,volume:80,singleton:true,absoluteUrl:true,maxRetryTimes:1,maxWaitingTime:4,recoverMethod:"retry",fetch:function(){var t,e;e=$.Deferred();t=this.getCur();setTimeout(function(n){return function(){n.setUrl(t);return e.resolve()}}(this),0);return e.promise()}};function r(e){var s,u,a;this.opts=u=$.extend({},r.defaults,e);this.waitingTimer=new n(100);this._checkFrozen(["play","pause","stop","next","prev","retry","replay","setVolume","setMute","setUrl","setCurrentPosition","_startWaitingTimer"]);s=u.baseDir,a=u.singleton;if(!s.endsWith("/")){s=s+"/"}if(a){if(t){return t}t=this}this.playlist=new i({absoluteUrl:u.absoluteUrl});this.playlist.setMode(u.mode);this._initEngine(new o({baseDir:s,engines:u.engines}));this.setMute(u.mute);this.setVolume(u.volume);this.reset()}r.prototype._initEngine=function(t){var e,n;n=this;e=this.opts.recoverMethod;this.engine=t;return this.engine.on(s.STATECHANGE,function(t){var e;e=t.newState;n.trigger("player:statechange",t);n.trigger(e);if(e===a.END){return n._clearWaitingTimer().next(true)}}).on(s.POSITIONCHANGE,function(t){var e;t=~~t;if(!t){return}e=n.getState();if(n.getUrl()&&(e===a.PLAYING||e===a.PREBUFFER||e===a.BUFFERING||e===a.CANPLAYTHROUGH)){n.trigger("timeupdate",t);return n._startWaitingTimer()}}).on(s.PROGRESS,function(t){return n.trigger("progress",t)}).on(s.ERROR,function(t){if(n.getUrl()){if(typeof console!=="undefined"&&console!==null){if(typeof console.error==="function"){console.error("error: ",t)}}return n.trigger("error",t)}}).on(s.WAITING_TIMEOUT,function(){if(n.getEngineType()==="AudioCore"&&n.engine.curEngine._isEmpty()){return}if(!n.getUrl()){return}if(e==="retry"||e==="next"){n[e]()}return n.trigger("player:waiting_timeout")})};r.prototype.retry=function(){var t,e,n;if(this._retryTimes++0){this.waitingTimer.clear().after(t+" seconds",function(t){return function(){return t.engine.trigger(s.WAITING_TIMEOUT)}}(this)).start()}return this};r.prototype._clearWaitingTimer=function(){this.waitingTimer.clear();return this};return r}();r.mixTo(u);return u}); \ No newline at end of file diff --git a/dist/zepto-player.js b/dist/zepto-player.js index 9690778..e372e4d 100644 --- a/dist/zepto-player.js +++ b/dist/zepto-player.js @@ -71,7 +71,6 @@ namespace: root._mu, version: '1.0.0', timerResolution: 25, - cdn: 'http://apps.bdimg.com/libs/muplayer/', engine: { TYPES: { FLASH_MP3: 'FlashMP3Core', @@ -1818,7 +1817,7 @@ var slice = [].slice; instance = null; Player.defaults = { - baseDir: "" + cfg.cdn + cfg.version, + baseDir: 'http://mu5.bdstatic.com/cms/muplayer/1-0-0/', mode: 'loop', mute: false, volume: 80, @@ -1896,20 +1895,15 @@ var slice = [].slice; */ function Player(options) { - var baseDir, opts; + var baseDir, opts, singleton; this.opts = opts = $.extend({}, Player.defaults, options); this.waitingTimer = new Timer(100); this._checkFrozen(['play', 'pause', 'stop', 'next', 'prev', 'retry', 'replay', 'setVolume', 'setMute', 'setUrl', 'setCurrentPosition', '_startWaitingTimer']); - baseDir = opts.baseDir; - if (baseDir === false) { - baseDir = ''; - } else if (!baseDir) { - throw new Error("baseDir must be set! Usually, it should point to the MuPlayer's dist directory."); - } - if (baseDir && !baseDir.endsWith('/')) { + baseDir = opts.baseDir, singleton = opts.singleton; + if (!baseDir.endsWith('/')) { baseDir = baseDir + '/'; } - if (opts.singleton) { + if (singleton) { if (instance) { return instance; } diff --git a/dist/zepto-player.min.js b/dist/zepto-player.min.js index 60c17ea..3c93bdb 100644 --- a/dist/zepto-player.min.js +++ b/dist/zepto-player.min.js @@ -3,5 +3,5 @@ // ------------------------- // (c) 2014 FE Team of Baidu Music // Can be freely distributed under the BSD license. -(function(t){var e=Object.prototype,n=e.toString;t.isString=function(t){return n.call(t)==="[object String]"};t.isNumeric=function(t){return n.call(t)==="[object Number]"};t.getScript=function(e,n){var r=document,i=r.createElement("script");i.async="async";if(!n){n={}}else if(t.isFunction(n)){n={callback:n}}if(n.charset){i.charset=n.charset}i.src=e;var o=r.getElementsByTagName("head")[0];i.onload=i.onreadystatechange=function(t,e){if(e||!i.readyState||/loaded|complete/.test(i.readyState)){i.onload=i.onreadystatechange=null;if(o&&i.parentNode){o.removeChild(i)}i=undefined;if(!e&&n.callback){n.callback()}}};o.insertBefore(i,o.firstChild)}})(Zepto);(function(t,e){if(typeof t._mu==="undefined"){t._mu={}}if(typeof exports==="object"){return module.exports=e()}else if(typeof define==="function"&&define.amd){return define("muplayer/core/cfg",e)}else{return t._mu.cfg=e()}})(this,function(){var t;t=this;return $.extend({namespace:t._mu,version:"1.0.0",timerResolution:25,cdn:"http://apps.bdimg.com/libs/muplayer/",engine:{TYPES:{FLASH_MP3:"FlashMP3Core",FLASH_MP4:"FlashMP4Core",AUDIO:"AudioCore"},EVENTS:{STATECHANGE:"engine:statechange",POSITIONCHANGE:"engine:postionchange",PROGRESS:"engine:progress",ERROR:"engine:error",INIT:"engine:init",INIT_FAIL:"engine:init_fail",WAITING_TIMEOUT:"engine:waiting_timeout"},STATES:{CANPLAYTHROUGH:"canplaythrough",PREBUFFER:"waiting",BUFFERING:"loadeddata",PLAYING:"playing",PAUSE:"pause",STOP:"suspend",END:"ended"},ERRCODE:{MEDIA_ERR_ABORTED:"1",MEDIA_ERR_NETWORK:"2",MEDIA_ERR_DECODE:"3",MEDIA_ERR_SRC_NOT_SUPPORTED:"4"}}},typeof t._mu==="undefined"?{}:t._mu.cfg)});(function(t,e){if(typeof exports==="object"){return module.exports=e()}else if(typeof define==="function"&&define.amd){return define("muplayer/core/utils",["muplayer/core/cfg"],e)}else{return t._mu.utils=e(t._mu.cfg)}})(this,function(t){var e,n,r,i,o,s,u,a,f,p,l,c,h,g,y,d,m;m={};i=String.prototype;n=Number.prototype;r=Object.prototype;e=Array.prototype;h=e.push;y=e.slice;d=r.toString;a=r.hasOwnProperty;c=Object.create;u=/\.(\w+)(\?.*)?$/;g=["Arguments","Function","String","Number","Date","RegExp"];for(f=0,p=g.length;f-1){r=n.split(f);p=[0,r.length],i=p[0],s=p[1];while(i";e.firstChild.href=t;e.innerHTML=e.innerHTML;return e.firstChild.href},getExt:function(t){var e;e="";if(u.test(decodeURIComponent(t))){e=RegExp.$1.toLocaleLowerCase()}return e}});return m});(function(t,e){if(typeof exports==="object"){module.exports=e()}else if(typeof define==="function"&&define.amd){define("muplayer/lib/Timer",e)}else{t._mu.Timer=e()}})(this,function(){function t(t){if(typeof t==="string"){if(isNaN(parseInt(t,10))){t="1"+t}var e=t.replace(/[^a-z0-9\.]/g,"").match(/(?:(\d+(?:\.\d+)?)(?:days?|d))?(?:(\d+(?:\.\d+)?)(?:hours?|hrs?|h))?(?:(\d+(?:\.\d+)?)(?:minutes?|mins?|m\b))?(?:(\d+(?:\.\d+)?)(?:seconds?|secs?|s))?(?:(\d+(?:\.\d+)?)(?:milliseconds?|ms))?/);if(e[0]){return parseFloat(e[1]||0)*864e5+parseFloat(e[2]||0)*36e5+parseFloat(e[3]||0)*6e4+parseFloat(e[4]||0)*1e3+parseInt(e[5]||0,10)}if(!isNaN(parseInt(t,10))){return parseInt(t,10)}}if(typeof t==="number"){return t}return 0}function e(t,e){return parseInt(t/e,10)||1}function n(e){if(this instanceof n===false){return new n(e)}this._notifications=[];this._resolution=t(e)||1e3;this._running=false;this._ticks=0;this._timer=null;this._drift=0}n.prototype={start:function(){var t=this;if(!this._running){this._running=!this._running;setTimeout(function e(){t._ticks++;for(var n=0,r=t._notifications.length;n=0;a-=2){if(!(r&&u[a]!==r||i&&u[a+1]!==i)){u.splice(a,2)}}}return this};e.prototype.trigger=function(e){var n,i,o,s,u,a,f=[],p,l=true;if(!(n=this.__events))return this;e=e.split(t);for(u=1,a=arguments.length;ue;0<=e?t++:t--){i.push(t)}return i}.apply(this));this.cur=this.list[this._listRandom[e]];return this.trigger("playlist:resetListRandom")}};e.prototype._formatSid=function(e){var n,r,i;n=this.opts.absoluteUrl;r=function(e){return n&&t.toAbsoluteUrl(e)||""+e};return $.isArray(e)&&function(){var t,n,o;o=[];for(t=0,n=e.length;t=s){this._supportedTypes.push(o)}}e={};i=new Audio;i.preload=f.preload;i.autoplay=f.autoplay;i.loop=false;i.on=function(t,n){var r;i.addEventListener(t,n,false);r=e[t];if(!r){r=[]}r.push(n);return i};i.off=function(t,n){var r,o,s;if(!t&&!n){for(t in e){s=e[t];for(r=0,o=s.length;ri?i:e;return i&&(e/i).toFixed(2)*1||0};n.prototype.getTotalTime=function(){var t,e,n,r,i;i=this.audio,r=i.duration,e=i.buffered,n=i.currentTime;r=~~r;if(r===0&&e){t=e.length;if(t>0){r=e.end(--t)}else{r=n}}return r&&r*1e3||0};return n}(n);return i});(function(t,e){if(typeof exports==="object"){return module.exports=e()}else if(typeof define==="function"&&define.amd){return define("muplayer/core/engines/engine",["muplayer/core/cfg","muplayer/core/utils","muplayer/lib/events","muplayer/core/engines/engineCore","muplayer/core/engines/audioCore"],e)}else{return t._mu.Engine=e(_mu.cfg,_mu.utils,_mu.Events,_mu.EngineCore,_mu.AudioCore)}})(this,function(cfg,utils,Events,EngineCore,AudioCore,FlashMP3Core,FlashMP4Core){var EVENTS,Engine,STATES,ref,timerResolution;ref=cfg.engine,EVENTS=ref.EVENTS,STATES=ref.STATES;timerResolution=cfg.timerResolution;Engine=function(){Engine.el='
';Engine.prototype.defaults={engines:[{type:AudioCore}]};function Engine(t){this.opts=$.extend({},this.defaults,t);this._initEngines()}Engine.prototype._initEngines=function(){var $el,args,engine,i,j,len,opts,ref1,type;this.engines=[];opts=this.opts;this.$el=$el=$(Engine.el.replace(/{{DATETIME}}/g,+new Date)).appendTo("body");this._lastE={};ref1=opts.engines;for(i=j=0,len=ref1.length;j=0&&t<=100){this.curEngine.setVolume(t)}return this};Engine.prototype.getVolume=function(){return this.curEngine.getVolume()};Engine.prototype.setCurrentPosition=function(t){t=~~t;this.curEngine.setCurrentPosition(t);return this};Engine.prototype.getCurrentPosition=function(){if(this.getState()===STATES.STOP){this.setCurrentPosition(0)}return this.curEngine.getCurrentPosition()};Engine.prototype.getLoadedPercent=function(){return this.curEngine.getLoadedPercent()};Engine.prototype.getTotalTime=function(){return this.curEngine.getTotalTime()};Engine.prototype.getEngineType=function(){return this.curEngine.engineType};return Engine}();Events.mixTo(Engine);return Engine});var slice=[].slice;(function(t,e){if(typeof exports==="object"){return module.exports=e()}else if(typeof define==="function"&&define.amd){return define("muplayer/player",["muplayer/core/cfg","muplayer/core/utils","muplayer/lib/Timer","muplayer/lib/events","muplayer/core/playlist","muplayer/core/engines/engine"],e)}else{return t._mu.Player=e(_mu.cfg,_mu.utils,_mu.Timer,_mu.Events,_mu.Playlist,_mu.Engine)}})(this,function(t,e,n,r,i,o){var s,u,a,f,p,l;p=t.engine,s=p.EVENTS,a=p.STATES;l=e.time2str;f=function(t,e){var n,r;if(t!=="prev"&&t!=="next"){return this}r=function(n){return function(){var r;r={cur:n.getCur()};if(e){r.auto=e}n.trigger("player:"+t,r);return n.stop(false).play()}}(this);if(this.getSongsNum()){n=this.playlist;if(!n.cur){r()}else if(n[t].call(n,e)){r()}else{this.trigger("player:"+t+":fail",e)}}return this};u=function(){var r;r=null;u.defaults={baseDir:""+t.cdn+t.version,mode:"loop",mute:false,volume:80,singleton:true,absoluteUrl:true,maxRetryTimes:1,maxWaitingTime:4,recoverMethod:"retry",fetch:function(){var t,e;e=$.Deferred();t=this.getCur();setTimeout(function(n){return function(){n.setUrl(t);return e.resolve()}}(this),0);return e.promise()}};function u(t){var e,s;this.opts=s=$.extend({},u.defaults,t);this.waitingTimer=new n(100);this._checkFrozen(["play","pause","stop","next","prev","retry","replay","setVolume","setMute","setUrl","setCurrentPosition","_startWaitingTimer"]);e=s.baseDir;if(e===false){e=""}else if(!e){throw new Error("baseDir must be set! Usually, it should point to the MuPlayer's dist directory.")}if(e&&!e.endsWith("/")){e=e+"/"}if(s.singleton){if(r){return r}r=this}this.playlist=new i({absoluteUrl:s.absoluteUrl});this.playlist.setMode(s.mode);this._initEngine(new o({baseDir:e,engines:s.engines}));this.setMute(s.mute);this.setVolume(s.volume);this.reset()}u.prototype._initEngine=function(t){var e,n;n=this;e=this.opts.recoverMethod;this.engine=t;return this.engine.on(s.STATECHANGE,function(t){var e;e=t.newState;n.trigger("player:statechange",t);n.trigger(e);if(e===a.END){return n._clearWaitingTimer().next(true)}}).on(s.POSITIONCHANGE,function(t){var e;t=~~t;if(!t){return}e=n.getState();if(n.getUrl()&&(e===a.PLAYING||e===a.PREBUFFER||e===a.BUFFERING||e===a.CANPLAYTHROUGH)){n.trigger("timeupdate",t);return n._startWaitingTimer()}}).on(s.PROGRESS,function(t){return n.trigger("progress",t)}).on(s.ERROR,function(t){if(n.getUrl()){if(typeof console!=="undefined"&&console!==null){if(typeof console.error==="function"){console.error("error: ",t)}}return n.trigger("error",t)}}).on(s.WAITING_TIMEOUT,function(){if(n.getEngineType()==="AudioCore"&&n.engine.curEngine._isEmpty()){return}if(!n.getUrl()){return}if(e==="retry"||e==="next"){n[e]()}return n.trigger("player:waiting_timeout")})};u.prototype.retry=function(){var t,e,n;if(this._retryTimes++0){this.waitingTimer.clear().after(t+" seconds",function(t){return function(){return t.engine.trigger(s.WAITING_TIMEOUT)}}(this)).start()}return this};u.prototype._clearWaitingTimer=function(){this.waitingTimer.clear();return this};return u}();r.mixTo(u);return u}); \ No newline at end of file +(function(t){var e=Object.prototype,n=e.toString;t.isString=function(t){return n.call(t)==="[object String]"};t.isNumeric=function(t){return n.call(t)==="[object Number]"};t.getScript=function(e,n){var r=document,i=r.createElement("script");i.async="async";if(!n){n={}}else if(t.isFunction(n)){n={callback:n}}if(n.charset){i.charset=n.charset}i.src=e;var o=r.getElementsByTagName("head")[0];i.onload=i.onreadystatechange=function(t,e){if(e||!i.readyState||/loaded|complete/.test(i.readyState)){i.onload=i.onreadystatechange=null;if(o&&i.parentNode){o.removeChild(i)}i=undefined;if(!e&&n.callback){n.callback()}}};o.insertBefore(i,o.firstChild)}})(Zepto);(function(t,e){if(typeof t._mu==="undefined"){t._mu={}}if(typeof exports==="object"){return module.exports=e()}else if(typeof define==="function"&&define.amd){return define("muplayer/core/cfg",e)}else{return t._mu.cfg=e()}})(this,function(){var t;t=this;return $.extend({namespace:t._mu,version:"1.0.0",timerResolution:25,engine:{TYPES:{FLASH_MP3:"FlashMP3Core",FLASH_MP4:"FlashMP4Core",AUDIO:"AudioCore"},EVENTS:{STATECHANGE:"engine:statechange",POSITIONCHANGE:"engine:postionchange",PROGRESS:"engine:progress",ERROR:"engine:error",INIT:"engine:init",INIT_FAIL:"engine:init_fail",WAITING_TIMEOUT:"engine:waiting_timeout"},STATES:{CANPLAYTHROUGH:"canplaythrough",PREBUFFER:"waiting",BUFFERING:"loadeddata",PLAYING:"playing",PAUSE:"pause",STOP:"suspend",END:"ended"},ERRCODE:{MEDIA_ERR_ABORTED:"1",MEDIA_ERR_NETWORK:"2",MEDIA_ERR_DECODE:"3",MEDIA_ERR_SRC_NOT_SUPPORTED:"4"}}},typeof t._mu==="undefined"?{}:t._mu.cfg)});(function(t,e){if(typeof exports==="object"){return module.exports=e()}else if(typeof define==="function"&&define.amd){return define("muplayer/core/utils",["muplayer/core/cfg"],e)}else{return t._mu.utils=e(t._mu.cfg)}})(this,function(t){var e,n,r,i,o,s,u,a,f,p,l,c,h,g,y,d,m;m={};i=String.prototype;n=Number.prototype;r=Object.prototype;e=Array.prototype;h=e.push;y=e.slice;d=r.toString;a=r.hasOwnProperty;c=Object.create;u=/\.(\w+)(\?.*)?$/;g=["Arguments","Function","String","Number","Date","RegExp"];for(f=0,p=g.length;f-1){r=n.split(f);p=[0,r.length],i=p[0],s=p[1];while(i";e.firstChild.href=t;e.innerHTML=e.innerHTML;return e.firstChild.href},getExt:function(t){var e;e="";if(u.test(decodeURIComponent(t))){e=RegExp.$1.toLocaleLowerCase()}return e}});return m});(function(t,e){if(typeof exports==="object"){module.exports=e()}else if(typeof define==="function"&&define.amd){define("muplayer/lib/Timer",e)}else{t._mu.Timer=e()}})(this,function(){function t(t){if(typeof t==="string"){if(isNaN(parseInt(t,10))){t="1"+t}var e=t.replace(/[^a-z0-9\.]/g,"").match(/(?:(\d+(?:\.\d+)?)(?:days?|d))?(?:(\d+(?:\.\d+)?)(?:hours?|hrs?|h))?(?:(\d+(?:\.\d+)?)(?:minutes?|mins?|m\b))?(?:(\d+(?:\.\d+)?)(?:seconds?|secs?|s))?(?:(\d+(?:\.\d+)?)(?:milliseconds?|ms))?/);if(e[0]){return parseFloat(e[1]||0)*864e5+parseFloat(e[2]||0)*36e5+parseFloat(e[3]||0)*6e4+parseFloat(e[4]||0)*1e3+parseInt(e[5]||0,10)}if(!isNaN(parseInt(t,10))){return parseInt(t,10)}}if(typeof t==="number"){return t}return 0}function e(t,e){return parseInt(t/e,10)||1}function n(e){if(this instanceof n===false){return new n(e)}this._notifications=[];this._resolution=t(e)||1e3;this._running=false;this._ticks=0;this._timer=null;this._drift=0}n.prototype={start:function(){var t=this;if(!this._running){this._running=!this._running;setTimeout(function e(){t._ticks++;for(var n=0,r=t._notifications.length;n=0;a-=2){if(!(r&&u[a]!==r||i&&u[a+1]!==i)){u.splice(a,2)}}}return this};e.prototype.trigger=function(e){var n,i,o,s,u,a,f=[],p,l=true;if(!(n=this.__events))return this;e=e.split(t);for(u=1,a=arguments.length;ue;0<=e?t++:t--){i.push(t)}return i}.apply(this));this.cur=this.list[this._listRandom[e]];return this.trigger("playlist:resetListRandom")}};e.prototype._formatSid=function(e){var n,r,i;n=this.opts.absoluteUrl;r=function(e){return n&&t.toAbsoluteUrl(e)||""+e};return $.isArray(e)&&function(){var t,n,o;o=[];for(t=0,n=e.length;t=s){this._supportedTypes.push(o)}}e={};i=new Audio;i.preload=f.preload;i.autoplay=f.autoplay;i.loop=false;i.on=function(t,n){var r;i.addEventListener(t,n,false);r=e[t];if(!r){r=[]}r.push(n);return i};i.off=function(t,n){var r,o,s;if(!t&&!n){for(t in e){s=e[t];for(r=0,o=s.length;ri?i:e;return i&&(e/i).toFixed(2)*1||0};n.prototype.getTotalTime=function(){var t,e,n,r,i;i=this.audio,r=i.duration,e=i.buffered,n=i.currentTime;r=~~r;if(r===0&&e){t=e.length;if(t>0){r=e.end(--t)}else{r=n}}return r&&r*1e3||0};return n}(n);return i});(function(t,e){if(typeof exports==="object"){return module.exports=e()}else if(typeof define==="function"&&define.amd){return define("muplayer/core/engines/engine",["muplayer/core/cfg","muplayer/core/utils","muplayer/lib/events","muplayer/core/engines/engineCore","muplayer/core/engines/audioCore"],e)}else{return t._mu.Engine=e(_mu.cfg,_mu.utils,_mu.Events,_mu.EngineCore,_mu.AudioCore)}})(this,function(cfg,utils,Events,EngineCore,AudioCore,FlashMP3Core,FlashMP4Core){var EVENTS,Engine,STATES,ref,timerResolution;ref=cfg.engine,EVENTS=ref.EVENTS,STATES=ref.STATES;timerResolution=cfg.timerResolution;Engine=function(){Engine.el='
';Engine.prototype.defaults={engines:[{type:AudioCore}]};function Engine(t){this.opts=$.extend({},this.defaults,t);this._initEngines()}Engine.prototype._initEngines=function(){var $el,args,engine,i,j,len,opts,ref1,type;this.engines=[];opts=this.opts;this.$el=$el=$(Engine.el.replace(/{{DATETIME}}/g,+new Date)).appendTo("body");this._lastE={};ref1=opts.engines;for(i=j=0,len=ref1.length;j=0&&t<=100){this.curEngine.setVolume(t)}return this};Engine.prototype.getVolume=function(){return this.curEngine.getVolume()};Engine.prototype.setCurrentPosition=function(t){t=~~t;this.curEngine.setCurrentPosition(t);return this};Engine.prototype.getCurrentPosition=function(){if(this.getState()===STATES.STOP){this.setCurrentPosition(0)}return this.curEngine.getCurrentPosition()};Engine.prototype.getLoadedPercent=function(){return this.curEngine.getLoadedPercent()};Engine.prototype.getTotalTime=function(){return this.curEngine.getTotalTime()};Engine.prototype.getEngineType=function(){return this.curEngine.engineType};return Engine}();Events.mixTo(Engine);return Engine});var slice=[].slice;(function(t,e){if(typeof exports==="object"){return module.exports=e()}else if(typeof define==="function"&&define.amd){return define("muplayer/player",["muplayer/core/cfg","muplayer/core/utils","muplayer/lib/Timer","muplayer/lib/events","muplayer/core/playlist","muplayer/core/engines/engine"],e)}else{return t._mu.Player=e(_mu.cfg,_mu.utils,_mu.Timer,_mu.Events,_mu.Playlist,_mu.Engine)}})(this,function(t,e,n,r,i,o){var s,u,a,f,p,l;p=t.engine,s=p.EVENTS,a=p.STATES;l=e.time2str;f=function(t,e){var n,r;if(t!=="prev"&&t!=="next"){return this}r=function(n){return function(){var r;r={cur:n.getCur()};if(e){r.auto=e}n.trigger("player:"+t,r);return n.stop(false).play()}}(this);if(this.getSongsNum()){n=this.playlist;if(!n.cur){r()}else if(n[t].call(n,e)){r()}else{this.trigger("player:"+t+":fail",e)}}return this};u=function(){var t;t=null;r.defaults={baseDir:"http://mu5.bdstatic.com/cms/muplayer/1-0-0/",mode:"loop",mute:false,volume:80,singleton:true,absoluteUrl:true,maxRetryTimes:1,maxWaitingTime:4,recoverMethod:"retry",fetch:function(){var t,e;e=$.Deferred();t=this.getCur();setTimeout(function(n){return function(){n.setUrl(t);return e.resolve()}}(this),0);return e.promise()}};function r(e){var s,u,a;this.opts=u=$.extend({},r.defaults,e);this.waitingTimer=new n(100);this._checkFrozen(["play","pause","stop","next","prev","retry","replay","setVolume","setMute","setUrl","setCurrentPosition","_startWaitingTimer"]);s=u.baseDir,a=u.singleton;if(!s.endsWith("/")){s=s+"/"}if(a){if(t){return t}t=this}this.playlist=new i({absoluteUrl:u.absoluteUrl});this.playlist.setMode(u.mode);this._initEngine(new o({baseDir:s,engines:u.engines}));this.setMute(u.mute);this.setVolume(u.volume);this.reset()}r.prototype._initEngine=function(t){var e,n;n=this;e=this.opts.recoverMethod;this.engine=t;return this.engine.on(s.STATECHANGE,function(t){var e;e=t.newState;n.trigger("player:statechange",t);n.trigger(e);if(e===a.END){return n._clearWaitingTimer().next(true)}}).on(s.POSITIONCHANGE,function(t){var e;t=~~t;if(!t){return}e=n.getState();if(n.getUrl()&&(e===a.PLAYING||e===a.PREBUFFER||e===a.BUFFERING||e===a.CANPLAYTHROUGH)){n.trigger("timeupdate",t);return n._startWaitingTimer()}}).on(s.PROGRESS,function(t){return n.trigger("progress",t)}).on(s.ERROR,function(t){if(n.getUrl()){if(typeof console!=="undefined"&&console!==null){if(typeof console.error==="function"){console.error("error: ",t)}}return n.trigger("error",t)}}).on(s.WAITING_TIMEOUT,function(){if(n.getEngineType()==="AudioCore"&&n.engine.curEngine._isEmpty()){return}if(!n.getUrl()){return}if(e==="retry"||e==="next"){n[e]()}return n.trigger("player:waiting_timeout")})};r.prototype.retry=function(){var t,e,n;if(this._retryTimes++0){this.waitingTimer.clear().after(t+" seconds",function(t){return function(){return t.engine.trigger(s.WAITING_TIMEOUT)}}(this)).start()}return this};r.prototype._clearWaitingTimer=function(){this.waitingTimer.clear();return this};return r}();r.mixTo(u);return u}); \ No newline at end of file diff --git a/src/js/core/cfg.coffee b/src/js/core/cfg.coffee index c9aa3ab..00edc50 100644 --- a/src/js/core/cfg.coffee +++ b/src/js/core/cfg.coffee @@ -9,8 +9,6 @@ do (root = @, factory = -> # 这个不经测试调优就尽量不要改, 会影响部分统计数据和性能。 timerResolution: 25 - cdn: 'http://apps.bdimg.com/libs/muplayer/' - engine: TYPES: FLASH_MP3: 'FlashMP3Core' diff --git a/src/js/player.coffee b/src/js/player.coffee index 478a323..fe0b805 100644 --- a/src/js/player.coffee +++ b/src/js/player.coffee @@ -36,7 +36,7 @@ do (root = this, factory = ( instance = null @defaults: - baseDir: "#{cfg.cdn}#{cfg.version}" + baseDir: 'http://mu5.bdstatic.com/cms/muplayer/1-0-0/' mode: 'loop' mute: false volume: 80 @@ -121,17 +121,13 @@ do (root = this, factory = ( 'setCurrentPosition', '_startWaitingTimer' ]) - baseDir = opts.baseDir - if baseDir is false - baseDir = '' - else unless baseDir - throw new Error "baseDir must be set! Usually, it should point to the MuPlayer's dist directory." - if baseDir and not baseDir.endsWith('/') + { baseDir, singleton } = opts + + unless baseDir.endsWith('/') baseDir = baseDir + '/' - if opts.singleton - if instance - return instance + if singleton + return instance if instance instance = @ @playlist = new Playlist(absoluteUrl: opts.absoluteUrl)