laya.wxmini.js 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917
  1. window=window||global;if(!window.layalib){window.layalib=function(f,i){(window._layalibs || (window._layalibs=[])).push({f:f,i:i});}}
  2. window.layalib(function(window,document,Laya){
  3. var __un=Laya.un,__uns=Laya.uns,__static=Laya.static,__class=Laya.class,__getset=Laya.getset,__newvec=Laya.__newvec;
  4. var Browser=laya.utils.Browser,Event=laya.events.Event,EventDispatcher=laya.events.EventDispatcher;
  5. var HTMLImage=laya.resource.HTMLImage,Handler=laya.utils.Handler,Input=laya.display.Input,Loader=laya.net.Loader;
  6. var LocalStorage=laya.net.LocalStorage,Matrix=laya.maths.Matrix,Render=laya.renders.Render,RunDriver=laya.utils.RunDriver;
  7. var SoundChannel=laya.media.SoundChannel,SoundManager=laya.media.SoundManager,Stage=laya.display.Stage,URL=laya.net.URL;
  8. var Utils=laya.utils.Utils;
  9. /**@private **/
  10. //class laya.wx.mini.MiniLocation
  11. var MiniLocation=(function(){
  12. function MiniLocation(){}
  13. __class(MiniLocation,'laya.wx.mini.MiniLocation');
  14. MiniLocation.__init__=function(){
  15. MiniAdpter.window.navigator.geolocation.getCurrentPosition=MiniLocation.getCurrentPosition;
  16. MiniAdpter.window.navigator.geolocation.watchPosition=MiniLocation.watchPosition;
  17. MiniAdpter.window.navigator.geolocation.clearWatch=MiniLocation.clearWatch;
  18. }
  19. MiniLocation.getCurrentPosition=function(success,error,options){
  20. var paramO;
  21. paramO={};
  22. paramO.success=getSuccess;
  23. paramO.fail=error;
  24. MiniAdpter.window.wx.getLocation(paramO);
  25. function getSuccess (res){
  26. if (success !=null){
  27. success(res);
  28. }
  29. }
  30. }
  31. MiniLocation.watchPosition=function(success,error,options){
  32. MiniLocation._curID++;
  33. var curWatchO;
  34. curWatchO={};
  35. curWatchO.success=success;
  36. curWatchO.error=error;
  37. MiniLocation._watchDic[MiniLocation._curID]=curWatchO;
  38. Laya.systemTimer.loop(1000,null,MiniLocation._myLoop);
  39. return MiniLocation._curID;
  40. }
  41. MiniLocation.clearWatch=function(id){
  42. delete MiniLocation._watchDic[id];
  43. if (!MiniLocation._hasWatch()){
  44. Laya.systemTimer.clear(null,MiniLocation._myLoop);
  45. }
  46. }
  47. MiniLocation._hasWatch=function(){
  48. var key;
  49. for (key in MiniLocation._watchDic){
  50. if (MiniLocation._watchDic[key])return true;
  51. }
  52. return false;
  53. }
  54. MiniLocation._myLoop=function(){
  55. MiniLocation.getCurrentPosition(MiniLocation._mySuccess,MiniLocation._myError);
  56. }
  57. MiniLocation._mySuccess=function(res){
  58. var rst={};
  59. rst.coords=res;
  60. rst.timestamp=Browser.now();
  61. var key;
  62. for (key in MiniLocation._watchDic){
  63. if (MiniLocation._watchDic[key].success){
  64. MiniLocation._watchDic[key].success(rst);
  65. }
  66. }
  67. }
  68. MiniLocation._myError=function(res){
  69. var key;
  70. for (key in MiniLocation._watchDic){
  71. if (MiniLocation._watchDic[key].error){
  72. MiniLocation._watchDic[key].error(res);
  73. }
  74. }
  75. }
  76. MiniLocation._watchDic={};
  77. MiniLocation._curID=0;
  78. return MiniLocation;
  79. })()
  80. /**@private **/
  81. //class laya.wx.mini.MiniFileMgr
  82. var MiniFileMgr=(function(){
  83. function MiniFileMgr(){}
  84. __class(MiniFileMgr,'laya.wx.mini.MiniFileMgr');
  85. MiniFileMgr.isLocalNativeFile=function(url){
  86. for(var i=0,sz=MiniAdpter.nativefiles.length;i<sz;i++){
  87. if(url.indexOf(MiniAdpter.nativefiles[i])!=-1)
  88. return true;
  89. }
  90. return false;
  91. }
  92. MiniFileMgr.getFileInfo=function(fileUrl){
  93. var fileNativePath=fileUrl;
  94. var fileObj=MiniFileMgr.filesListObj[fileNativePath];
  95. if (fileObj==null)
  96. return null;
  97. else
  98. return fileObj;
  99. return null;
  100. }
  101. MiniFileMgr.read=function(filePath,encoding,callBack,readyUrl,isSaveFile,fileType){
  102. (encoding===void 0)&& (encoding="ascill");
  103. (readyUrl===void 0)&& (readyUrl="");
  104. (isSaveFile===void 0)&& (isSaveFile=false);
  105. (fileType===void 0)&& (fileType="");
  106. var fileUrl;
  107. if(readyUrl!="" && (readyUrl.indexOf("http://")!=-1 || readyUrl.indexOf("https://")!=-1)){
  108. fileUrl=MiniFileMgr.getFileNativePath(filePath)
  109. }else{
  110. fileUrl=filePath;
  111. }
  112. fileUrl=URL.getAdptedFilePath(fileUrl);
  113. MiniFileMgr.fs.readFile({filePath:fileUrl,encoding:encoding,success:function (data){
  114. callBack !=null && callBack.runWith([0,data]);
  115. },fail:function (data){
  116. if (data && readyUrl !="")
  117. MiniFileMgr.downFiles(readyUrl,encoding,callBack,readyUrl,isSaveFile,fileType);
  118. else
  119. callBack !=null && callBack.runWith([1]);
  120. }});
  121. }
  122. MiniFileMgr.downFiles=function(fileUrl,encoding,callBack,readyUrl,isSaveFile,fileType,isAutoClear){
  123. (encoding===void 0)&& (encoding="ascii");
  124. (readyUrl===void 0)&& (readyUrl="");
  125. (isSaveFile===void 0)&& (isSaveFile=false);
  126. (fileType===void 0)&& (fileType="");
  127. (isAutoClear===void 0)&& (isAutoClear=true);
  128. var downloadTask=MiniFileMgr.wxdown({url:fileUrl,success:function (data){
  129. if (data.statusCode===200)
  130. MiniFileMgr.readFile(data.tempFilePath,encoding,callBack,readyUrl,isSaveFile,fileType,isAutoClear);
  131. else
  132. if(data.statusCode===403){
  133. callBack !=null && callBack.runWith([0,fileUrl]);
  134. }else{
  135. callBack !=null && callBack.runWith([1,data]);
  136. }
  137. },fail:function (data){
  138. callBack !=null && callBack.runWith([1,data]);
  139. }});
  140. downloadTask.onProgressUpdate(function(data){
  141. callBack !=null && callBack.runWith([2,data.progress]);
  142. });
  143. }
  144. MiniFileMgr.readFile=function(filePath,encoding,callBack,readyUrl,isSaveFile,fileType,isAutoClear){
  145. (encoding===void 0)&& (encoding="ascill");
  146. (readyUrl===void 0)&& (readyUrl="");
  147. (isSaveFile===void 0)&& (isSaveFile=false);
  148. (fileType===void 0)&& (fileType="");
  149. (isAutoClear===void 0)&& (isAutoClear=true);
  150. filePath=URL.getAdptedFilePath(filePath);
  151. MiniFileMgr.fs.readFile({filePath:filePath,encoding:encoding,success:function (data){
  152. if (filePath.indexOf("http://")!=-1 || filePath.indexOf("https://")!=-1){
  153. if(MiniAdpter.autoCacheFile || isSaveFile){
  154. MiniFileMgr.copyFile(filePath,readyUrl,callBack,encoding,isAutoClear);
  155. }
  156. }
  157. else
  158. callBack !=null && callBack.runWith([0,data]);
  159. },fail:function (data){
  160. if (data)
  161. callBack !=null && callBack.runWith([1,data]);
  162. }});
  163. }
  164. MiniFileMgr.downOtherFiles=function(fileUrl,callBack,readyUrl,isSaveFile,isAutoClear){
  165. (readyUrl===void 0)&& (readyUrl="");
  166. (isSaveFile===void 0)&& (isSaveFile=false);
  167. (isAutoClear===void 0)&& (isAutoClear=true);
  168. MiniFileMgr.wxdown({url:fileUrl,success:function (data){
  169. if (data.statusCode===200){
  170. if((MiniAdpter.autoCacheFile || isSaveFile)&& readyUrl.indexOf("qlogo.cn")==-1 && readyUrl.indexOf(".php")==-1)
  171. MiniFileMgr.copyFile(data.tempFilePath,readyUrl,callBack,"",isAutoClear);
  172. else
  173. callBack !=null && callBack.runWith([0,data.tempFilePath]);
  174. }else{
  175. callBack !=null && callBack.runWith([1,data]);
  176. }
  177. },fail:function (data){
  178. callBack !=null && callBack.runWith([1,data]);
  179. }});
  180. }
  181. MiniFileMgr.downLoadFile=function(fileUrl,fileType,callBack,encoding){
  182. (fileType===void 0)&& (fileType="");
  183. (encoding===void 0)&& (encoding="ascii");
  184. if(/*__JS__ */window.navigator.userAgent.indexOf('MiniGame')<0){
  185. Laya.loader.load(fileUrl,callBack);
  186. }else{
  187. if(fileType==/*laya.net.Loader.IMAGE*/"image" || fileType==/*laya.net.Loader.SOUND*/"sound")
  188. MiniFileMgr.downOtherFiles(fileUrl,callBack,fileUrl,true,false);
  189. else
  190. MiniFileMgr.downFiles(fileUrl,encoding,callBack,fileUrl,true,fileType,false);
  191. }
  192. }
  193. MiniFileMgr.copyFile=function(tempFilePath,readyUrl,callBack,encoding,isAutoClear){
  194. (encoding===void 0)&& (encoding="");
  195. (isAutoClear===void 0)&& (isAutoClear=true);
  196. var temp=tempFilePath.split("/");
  197. var tempFileName=temp[temp.length-1];
  198. var fileurlkey=readyUrl;
  199. var fileObj=MiniFileMgr.getFileInfo(readyUrl);
  200. var saveFilePath=MiniFileMgr.getFileNativePath(tempFileName);
  201. var totalSize=50 *1024 *1024;
  202. var chaSize=4 *1024 *1024;
  203. var fileUseSize=MiniFileMgr.getCacheUseSize();
  204. if (fileObj){
  205. if (fileObj.readyUrl !=readyUrl){
  206. MiniFileMgr.fs.getFileInfo({
  207. filePath:tempFilePath,
  208. success:function (data){
  209. if((isAutoClear && (fileUseSize+chaSize+data.size)>=totalSize)){
  210. if(data.size > MiniAdpter.minClearSize)
  211. MiniAdpter.minClearSize=data.size;
  212. MiniFileMgr.onClearCacheRes();
  213. }
  214. MiniFileMgr.deleteFile(tempFileName,readyUrl,callBack,encoding,data.size);
  215. },
  216. fail:function (data){
  217. callBack !=null && callBack.runWith([1,data]);
  218. }
  219. });
  220. }
  221. else
  222. callBack !=null && callBack.runWith([0]);
  223. }else{
  224. MiniFileMgr.fs.getFileInfo({
  225. filePath:tempFilePath,
  226. success:function (data){
  227. if((isAutoClear && (fileUseSize+chaSize+data.size)>=totalSize)){
  228. if(data.size > MiniAdpter.minClearSize)
  229. MiniAdpter.minClearSize=data.size;
  230. MiniFileMgr.onClearCacheRes();
  231. }
  232. MiniFileMgr.fs.copyFile({srcPath:tempFilePath,destPath:saveFilePath,success:function (data2){
  233. MiniFileMgr.onSaveFile(readyUrl,tempFileName,true,encoding,callBack,data.size);
  234. },fail:function (data){
  235. callBack !=null && callBack.runWith([1,data]);
  236. }});
  237. },
  238. fail:function (data){
  239. callBack !=null && callBack.runWith([1,data]);
  240. }
  241. });
  242. }
  243. }
  244. MiniFileMgr.onClearCacheRes=function(){
  245. var memSize=MiniAdpter.minClearSize;
  246. var tempFileListArr=[];
  247. for(var key in MiniFileMgr.filesListObj){
  248. tempFileListArr.push(MiniFileMgr.filesListObj[key]);
  249. }
  250. MiniFileMgr.sortOn(tempFileListArr,"times",16);
  251. var clearSize=0;
  252. for(var i=1,sz=tempFileListArr.length;i<sz;i++){
  253. var fileObj=tempFileListArr[i];
  254. if(clearSize >=memSize)
  255. break ;
  256. clearSize+=fileObj.size;
  257. MiniFileMgr.deleteFile("",fileObj.readyUrl);
  258. }
  259. }
  260. MiniFileMgr.sortOn=function(array,name,options){
  261. (options===void 0)&& (options=0);
  262. if (options==16)return array.sort(function(a,b){return a[name]-b[name];});
  263. if (options==(16 | 2))return array.sort(function(a,b){return b[name]-a[name];});
  264. return array.sort(function(a,b){return a[name]-b[name] });
  265. }
  266. MiniFileMgr.getFileNativePath=function(fileName){
  267. return laya.wx.mini.MiniFileMgr.fileNativeDir+"/"+fileName;
  268. }
  269. MiniFileMgr.deleteFile=function(tempFileName,readyUrl,callBack,encoding,fileSize){
  270. (readyUrl===void 0)&& (readyUrl="");
  271. (encoding===void 0)&& (encoding="");
  272. (fileSize===void 0)&& (fileSize=0);
  273. var fileObj=MiniFileMgr.getFileInfo(readyUrl);
  274. var deleteFileUrl=MiniFileMgr.getFileNativePath(fileObj.md5);
  275. MiniFileMgr.fs.unlink({filePath:deleteFileUrl,success:function (data){
  276. var isAdd=tempFileName !="" ? true :false;
  277. if(tempFileName !=""){
  278. var saveFilePath=MiniFileMgr.getFileNativePath(tempFileName);
  279. MiniFileMgr.fs.copyFile({srcPath:tempFileName,destPath:saveFilePath,success:function (data){
  280. MiniFileMgr.onSaveFile(readyUrl,tempFileName,isAdd,encoding,callBack,data.size);
  281. },fail:function (data){
  282. callBack !=null && callBack.runWith([1,data]);
  283. }});
  284. }else{
  285. MiniFileMgr.onSaveFile(readyUrl,tempFileName,isAdd,encoding,callBack,fileSize);
  286. }
  287. },fail:function (data){
  288. }});
  289. }
  290. MiniFileMgr.deleteAll=function(){
  291. var tempFileListArr=[];
  292. for(var key in MiniFileMgr.filesListObj){
  293. tempFileListArr.push(MiniFileMgr.filesListObj[key]);
  294. }
  295. for(var i=1,sz=tempFileListArr.length;i<sz;i++){
  296. var fileObj=tempFileListArr[i];
  297. MiniFileMgr.deleteFile("",fileObj.readyUrl);
  298. }
  299. if(laya.wx.mini.MiniFileMgr.filesListObj && laya.wx.mini.MiniFileMgr.filesListObj.fileUsedSize){
  300. laya.wx.mini.MiniFileMgr.filesListObj.fileUsedSize=0;
  301. }
  302. laya.wx.mini.MiniFileMgr.writeFilesList("",JSON.stringify({}),false);
  303. }
  304. MiniFileMgr.onSaveFile=function(readyUrl,md5Name,isAdd,encoding,callBack,fileSize){
  305. (isAdd===void 0)&& (isAdd=true);
  306. (encoding===void 0)&& (encoding="");
  307. (fileSize===void 0)&& (fileSize=0);
  308. var fileurlkey=readyUrl;
  309. if(MiniFileMgr.filesListObj['fileUsedSize']==null)
  310. MiniFileMgr.filesListObj['fileUsedSize']=0;
  311. if(isAdd){
  312. var fileNativeName=MiniFileMgr.getFileNativePath(md5Name);
  313. MiniFileMgr.filesListObj[fileurlkey]={md5:md5Name,readyUrl:readyUrl,size:fileSize,times:Browser.now(),encoding:encoding};
  314. MiniFileMgr.filesListObj['fileUsedSize']=parseInt(MiniFileMgr.filesListObj['fileUsedSize'])+fileSize;
  315. MiniFileMgr.writeFilesList(fileurlkey,JSON.stringify(MiniFileMgr.filesListObj),true);
  316. callBack !=null && callBack.runWith([0]);
  317. }else{
  318. if(MiniFileMgr.filesListObj[fileurlkey]){
  319. var deletefileSize=parseInt(MiniFileMgr.filesListObj[fileurlkey].size);
  320. MiniFileMgr.filesListObj['fileUsedSize']=parseInt(MiniFileMgr.filesListObj['fileUsedSize'])-deletefileSize;
  321. delete MiniFileMgr.filesListObj[fileurlkey];
  322. MiniFileMgr.writeFilesList(fileurlkey,JSON.stringify(MiniFileMgr.filesListObj),false);
  323. callBack !=null && callBack.runWith([0]);
  324. }
  325. }
  326. }
  327. MiniFileMgr.writeFilesList=function(fileurlkey,filesListStr,isAdd){
  328. var listFilesPath=MiniFileMgr.fileNativeDir+"/"+MiniFileMgr.fileListName;
  329. MiniFileMgr.fs.writeFile({filePath:listFilesPath,encoding:'utf8',data:filesListStr,success:function (data){
  330. },fail:function (data){
  331. }});
  332. if(!MiniAdpter.isZiYu &&MiniAdpter.isPosMsgYu){
  333. /*__JS__ */wx.postMessage({url:fileurlkey,data:MiniFileMgr.filesListObj[fileurlkey],isLoad:"filenative",isAdd:isAdd});
  334. }
  335. }
  336. MiniFileMgr.getCacheUseSize=function(){
  337. if(MiniFileMgr.filesListObj && MiniFileMgr.filesListObj['fileUsedSize'])
  338. return MiniFileMgr.filesListObj['fileUsedSize'];
  339. return 0;
  340. }
  341. MiniFileMgr.existDir=function(dirPath,callBack){
  342. MiniFileMgr.fs.mkdir({dirPath:dirPath,success:function (data){
  343. callBack !=null && callBack.runWith([0,{data:JSON.stringify({})}]);
  344. },fail:function (data){
  345. if (data.errMsg.indexOf("file already exists")!=-1)
  346. MiniFileMgr.readSync(MiniFileMgr.fileListName,"utf8",callBack);
  347. else
  348. callBack !=null && callBack.runWith([1,data]);
  349. }});
  350. }
  351. MiniFileMgr.readSync=function(filePath,encoding,callBack,readyUrl){
  352. (encoding===void 0)&& (encoding="ascill");
  353. (readyUrl===void 0)&& (readyUrl="");
  354. var fileUrl=MiniFileMgr.getFileNativePath(filePath);
  355. var filesListStr
  356. try{
  357. filesListStr=MiniFileMgr.fs.readFileSync(fileUrl,encoding);
  358. callBack !=null && callBack.runWith([0,{data:filesListStr}]);
  359. }
  360. catch(error){
  361. callBack !=null && callBack.runWith([1]);
  362. }
  363. }
  364. MiniFileMgr.setNativeFileDir=function(value){
  365. MiniFileMgr.fileNativeDir=/*__JS__ */wx.env.USER_DATA_PATH+value;
  366. }
  367. MiniFileMgr.filesListObj={};
  368. MiniFileMgr.fileNativeDir=null;
  369. MiniFileMgr.fileListName="layaairfiles.txt";
  370. MiniFileMgr.ziyuFileData={};
  371. MiniFileMgr.ziyuFileTextureData={};
  372. MiniFileMgr.loadPath="";
  373. MiniFileMgr.DESCENDING=2;
  374. MiniFileMgr.NUMERIC=16;
  375. __static(MiniFileMgr,
  376. ['fs',function(){return this.fs=/*__JS__ */wx.getFileSystemManager();},'wxdown',function(){return this.wxdown=/*__JS__ */wx.downloadFile;}
  377. ]);
  378. return MiniFileMgr;
  379. })()
  380. /**@private **/
  381. //class laya.wx.mini.MiniLocalStorage
  382. var MiniLocalStorage=(function(){
  383. function MiniLocalStorage(){}
  384. __class(MiniLocalStorage,'laya.wx.mini.MiniLocalStorage');
  385. MiniLocalStorage.__init__=function(){
  386. MiniLocalStorage.items=MiniLocalStorage;
  387. }
  388. MiniLocalStorage.setItem=function(key,value){
  389. try{
  390. /*__JS__ */wx.setStorageSync(key,value);
  391. }
  392. catch(error){
  393. /*__JS__ */wx.setStorage({
  394. key:key,
  395. data:value
  396. });
  397. }
  398. }
  399. MiniLocalStorage.getItem=function(key){
  400. return /*__JS__ */wx.getStorageSync(key);
  401. }
  402. MiniLocalStorage.setJSON=function(key,value){
  403. MiniLocalStorage.setItem(key,value);
  404. }
  405. MiniLocalStorage.getJSON=function(key){
  406. return MiniLocalStorage.getItem(key);
  407. }
  408. MiniLocalStorage.removeItem=function(key){
  409. /*__JS__ */wx.removeStorageSync(key);
  410. }
  411. MiniLocalStorage.clear=function(){
  412. /*__JS__ */wx.clearStorageSync();
  413. }
  414. MiniLocalStorage.getStorageInfoSync=function(){
  415. try {
  416. var res=/*__JS__ */wx.getStorageInfoSync()
  417. console.log(res.keys)
  418. console.log(res.currentSize)
  419. console.log(res.limitSize)
  420. return res;
  421. }catch (e){}
  422. return null;
  423. }
  424. MiniLocalStorage.support=true;
  425. MiniLocalStorage.items=null;
  426. return MiniLocalStorage;
  427. })()
  428. /**
  429. *视频类
  430. *@author xiaosong
  431. *@date-2019-04-22
  432. */
  433. //class laya.wx.mini.MiniVideo
  434. var MiniVideo=(function(){
  435. function MiniVideo(width,height){
  436. /**视频是否播放结束**/
  437. this.videoend=false;
  438. this.videourl="";
  439. this.videoElement=null;
  440. this.onPlayFunc=null;
  441. this.onEndedFunC=null;
  442. /**视频的总时⻓长,单位为秒**/
  443. this._duration=NaN;
  444. /**视频播放的当前位置**/
  445. this.position=NaN;
  446. (width===void 0)&& (width=320);
  447. (height===void 0)&& (height=240);
  448. this.videoElement=MiniAdpter.window.wx.createVideo({width:width,height:height,autoplay:true});
  449. }
  450. __class(MiniVideo,'laya.wx.mini.MiniVideo');
  451. var __proto=MiniVideo.prototype;
  452. __proto.on=function(eventType,ths,callBack){
  453. if(eventType=="loadedmetadata"){
  454. this.onPlayFunc=callBack.bind(ths);
  455. this.videoElement.onPlay=this.onPlayFunction.bind(this);
  456. }else if(eventType=="ended"){
  457. this.onEndedFunC=callBack.bind(ths);
  458. this.videoElement.onEnded=this.onEndedFunction.bind(this);
  459. }
  460. this.videoElement.onTimeUpdate=this.onTimeUpdateFunc.bind(this);
  461. }
  462. __proto.onTimeUpdateFunc=function(data){
  463. this.position=data.position;
  464. this._duration=data.duration;
  465. }
  466. __proto.onPlayFunction=function(){
  467. if(this.videoElement)
  468. this.videoElement.readyState=200;
  469. console.log("=====视频加载完成========");
  470. this.onPlayFunc !=null && this.onPlayFunc();
  471. }
  472. __proto.onEndedFunction=function(){
  473. if(!this.videoElement)
  474. return;
  475. this.videoend=true;
  476. console.log("=====视频播放完毕========");
  477. this.onEndedFunC !=null && this.onEndedFunC();
  478. }
  479. __proto.off=function(eventType,ths,callBack){
  480. if(eventType=="loadedmetadata"){
  481. this.onPlayFunc=callBack.bind(ths);
  482. this.videoElement.offPlay=this.onPlayFunction.bind(this);
  483. }else if(eventType=="ended"){
  484. this.onEndedFunC=callBack.bind(ths);
  485. this.videoElement.offEnded=this.onEndedFunction.bind(this);
  486. }
  487. }
  488. /**
  489. *设置播放源。
  490. *@param url 播放源路径。
  491. */
  492. __proto.load=function(url){
  493. if(!this.videoElement)
  494. return;
  495. this.videoElement.src=url;
  496. }
  497. /**
  498. *开始播放视频。
  499. */
  500. __proto.play=function(){
  501. if(!this.videoElement)
  502. return;
  503. this.videoend=false;
  504. this.videoElement.play();
  505. }
  506. /**
  507. *暂停视频播放。
  508. */
  509. __proto.pause=function(){
  510. if(!this.videoElement)
  511. return;
  512. this.videoend=true;
  513. this.videoElement.pause();
  514. }
  515. /**
  516. *设置大小
  517. *@param width
  518. *@param height
  519. */
  520. __proto.size=function(width,height){
  521. if(!this.videoElement)
  522. return;
  523. this.videoElement.width=width;
  524. this.videoElement.height=height;
  525. }
  526. __proto.destroy=function(){
  527. if(this.videoElement)
  528. this.videoElement.destroy();
  529. this.videoElement=null;
  530. this.onEndedFunC=null;
  531. this.onPlayFunc=null;
  532. this.videoend=false;
  533. this.videourl=null;
  534. }
  535. /**
  536. *重新加载视频。
  537. */
  538. __proto.reload=function(){
  539. if(!this.videoElement)
  540. return;
  541. this.videoElement.src=this.videourl;
  542. }
  543. /**
  544. *获取视频长度(秒)。ready事件触发后可用。
  545. */
  546. __getset(0,__proto,'duration',function(){
  547. return this._duration;
  548. });
  549. /**
  550. *返回视频是否暂停
  551. */
  552. __getset(0,__proto,'paused',function(){
  553. if(!this.videoElement)
  554. return false;
  555. return this.videoElement.paused;
  556. });
  557. /**
  558. *设置或返回音频/视频是否应在结束时重新播放。
  559. */
  560. __getset(0,__proto,'loop',function(){
  561. if(!this.videoElement)
  562. return false;
  563. return this.videoElement.loop;
  564. },function(value){
  565. if(!this.videoElement)
  566. return;
  567. this.videoElement.loop=value;
  568. });
  569. /**
  570. *设置和获取当前播放头位置。
  571. */
  572. __getset(0,__proto,'currentTime',function(){
  573. if(!this.videoElement)
  574. return 0;
  575. return this.videoElement.initialTime;
  576. },function(value){
  577. if(!this.videoElement)
  578. return;
  579. this.videoElement.initialTime=value;
  580. });
  581. /**
  582. *返回音频/视频的播放是否已结束
  583. */
  584. __getset(0,__proto,'ended',function(){
  585. return this.videoend;
  586. });
  587. /**
  588. *获取和设置静音状态。
  589. */
  590. __getset(0,__proto,'muted',function(){
  591. if(!this.videoElement)
  592. return false;
  593. return this.videoElement.muted;
  594. },function(value){
  595. if(!this.videoElement)
  596. return;
  597. this.videoElement.muted=value;
  598. });
  599. /**
  600. *获取视频源尺寸。ready事件触发后可用。
  601. */
  602. __getset(0,__proto,'videoWidth',function(){
  603. if(!this.videoElement)
  604. return 0;
  605. return this.videoElement.width;
  606. });
  607. __getset(0,__proto,'videoHeight',function(){
  608. if(!this.videoElement)
  609. return 0;
  610. return this.videoElement.height;
  611. });
  612. /**
  613. *playbackRate 属性设置或返回音频/视频的当前播放速度。如:
  614. *<ul>
  615. *<li>1.0 正常速度</li>
  616. *<li>0.5 半速(更慢)</li>
  617. *<li>2.0 倍速(更快)</li>
  618. *<li>-1.0 向后,正常速度</li>
  619. *<li>-0.5 向后,半速</li>
  620. *</ul>
  621. *<p>只有 Google Chrome 和 Safari 支持 playbackRate 属性。</p>
  622. */
  623. __getset(0,__proto,'playbackRate',function(){
  624. if(!this.videoElement)
  625. return 0;
  626. return this.videoElement.playbackRate;
  627. },function(value){
  628. if(!this.videoElement)
  629. return;
  630. this.videoElement.playbackRate=value;
  631. });
  632. __getset(0,__proto,'x',function(){
  633. if(!this.videoElement)
  634. return 0;
  635. return this.videoElement.x;
  636. },function(value){
  637. if(!this.videoElement)
  638. return;
  639. this.videoElement.x=value;
  640. });
  641. __getset(0,__proto,'y',function(){
  642. if(!this.videoElement)
  643. return 0;
  644. return this.videoElement.y;
  645. },function(value){
  646. if(!this.videoElement)
  647. return;
  648. this.videoElement.y=value;
  649. });
  650. /**
  651. *获取当前播放源路径。
  652. */
  653. __getset(0,__proto,'currentSrc',function(){
  654. return this.videoElement.src;
  655. });
  656. MiniVideo.__init__=function(){
  657. /*__JS__ */laya.device.media.Video=MiniVideo;
  658. }
  659. return MiniVideo;
  660. })()
  661. /**@private **/
  662. //class laya.wx.mini.MiniImage
  663. var MiniImage=(function(){
  664. function MiniImage(){}
  665. __class(MiniImage,'laya.wx.mini.MiniImage');
  666. var __proto=MiniImage.prototype;
  667. /**@private **/
  668. __proto._loadImage=function(url){
  669. var thisLoader=this;
  670. if (MiniAdpter.isZiYu){
  671. MiniImage.onCreateImage(url,thisLoader,true);
  672. return;
  673. };
  674. var isTransformUrl=false;
  675. if (!MiniFileMgr.isLocalNativeFile(url)){
  676. isTransformUrl=true;
  677. url=URL.formatURL(url);
  678. }else{
  679. if (url.indexOf("http://usr/")==-1&&(url.indexOf("http://")!=-1 || url.indexOf("https://")!=-1)){
  680. if(MiniFileMgr.loadPath !=""){
  681. url=url.split(MiniFileMgr.loadPath)[1];
  682. }else{
  683. var tempStr=URL.rootPath !="" ? URL.rootPath :URL._basePath;
  684. var tempUrl=url;
  685. if(tempStr !="")
  686. url=url.split(tempStr)[1];
  687. if(!url){
  688. url=tempUrl;
  689. }
  690. }
  691. }
  692. if (MiniAdpter.subNativeFiles && MiniAdpter.subNativeheads.length==0){
  693. for (var key in MiniAdpter.subNativeFiles){
  694. var tempArr=MiniAdpter.subNativeFiles[key];
  695. MiniAdpter.subNativeheads=MiniAdpter.subNativeheads.concat(tempArr);
  696. for (var aa=0;aa < tempArr.length;aa++){
  697. MiniAdpter.subMaps[tempArr[aa]]=key+"/"+tempArr[aa];
  698. }
  699. }
  700. }
  701. if(MiniAdpter.subNativeFiles && url.indexOf("/")!=-1){
  702. var curfileHead=url.split("/")[0]+"/";
  703. if(curfileHead && MiniAdpter.subNativeheads.indexOf(curfileHead)!=-1){
  704. var newfileHead=MiniAdpter.subMaps[curfileHead];
  705. url=url.replace(curfileHead,newfileHead);
  706. }
  707. }
  708. }
  709. if (!MiniFileMgr.getFileInfo(url)){
  710. if (url.indexOf('http://usr/')==-1&&(url.indexOf("http://")!=-1 || url.indexOf("https://")!=-1)){
  711. if(MiniAdpter.isZiYu){
  712. MiniImage.onCreateImage(url,thisLoader,true);
  713. }else{
  714. MiniFileMgr.downOtherFiles(url,new Handler(MiniImage,MiniImage.onDownImgCallBack,[url,thisLoader]),url);
  715. }
  716. }
  717. else
  718. MiniImage.onCreateImage(url,thisLoader,true);
  719. }else {
  720. MiniImage.onCreateImage(url,thisLoader,!isTransformUrl);
  721. }
  722. }
  723. MiniImage.onDownImgCallBack=function(sourceUrl,thisLoader,errorCode,tempFilePath){
  724. (tempFilePath===void 0)&& (tempFilePath="");
  725. if (!errorCode)
  726. MiniImage.onCreateImage(sourceUrl,thisLoader,false,tempFilePath);
  727. else {
  728. thisLoader.onError(null);
  729. }
  730. }
  731. MiniImage.onCreateImage=function(sourceUrl,thisLoader,isLocal,tempFilePath){
  732. (isLocal===void 0)&& (isLocal=false);
  733. (tempFilePath===void 0)&& (tempFilePath="");
  734. var fileNativeUrl;
  735. if(MiniAdpter.autoCacheFile){
  736. if (!isLocal){
  737. if(tempFilePath !=""){
  738. fileNativeUrl=tempFilePath;
  739. }else{
  740. var fileObj=MiniFileMgr.getFileInfo(sourceUrl);
  741. var fileMd5Name=fileObj.md5;
  742. fileNativeUrl=MiniFileMgr.getFileNativePath(fileMd5Name);
  743. }
  744. }else
  745. if(MiniAdpter.isZiYu){
  746. var tempUrl=URL.formatURL(sourceUrl);
  747. if(MiniFileMgr.ziyuFileTextureData[tempUrl]){
  748. fileNativeUrl=MiniFileMgr.ziyuFileTextureData[tempUrl];
  749. }else
  750. fileNativeUrl=sourceUrl;
  751. }else
  752. fileNativeUrl=sourceUrl;
  753. }else{
  754. if(!isLocal)
  755. fileNativeUrl=tempFilePath;
  756. else
  757. fileNativeUrl=sourceUrl;
  758. }
  759. if (thisLoader._imgCache==null)
  760. thisLoader._imgCache={};
  761. var image;
  762. function clear (){
  763. var img=thisLoader._imgCache[fileNativeUrl];
  764. if (img){
  765. img.onload=null;
  766. img.onerror=null;
  767. delete thisLoader._imgCache[fileNativeUrl];
  768. }
  769. };
  770. var onerror=function (){
  771. clear();
  772. thisLoader.event(/*laya.events.Event.ERROR*/"error","Load image failed");
  773. }
  774. if (thisLoader._type=="nativeimage"){
  775. var onload=function (){
  776. clear();
  777. thisLoader.onLoaded(image);
  778. };
  779. image=new Browser.window.Image();
  780. image.crossOrigin="";
  781. image.onload=onload;
  782. image.onerror=onerror;
  783. image.src=fileNativeUrl;
  784. thisLoader._imgCache[fileNativeUrl]=image;
  785. }else {
  786. var imageSource=new Browser.window.Image();
  787. onload=function (){
  788. image=HTMLImage.create(imageSource.width,imageSource.height);
  789. image.loadImageSource(imageSource,true);
  790. image._setCreateURL(fileNativeUrl);
  791. clear();
  792. thisLoader.onLoaded(image);
  793. };
  794. imageSource.crossOrigin="";
  795. imageSource.onload=onload;
  796. imageSource.onerror=onerror;
  797. imageSource.src=fileNativeUrl;
  798. thisLoader._imgCache[fileNativeUrl]=imageSource;
  799. }
  800. }
  801. return MiniImage;
  802. })()
  803. /**@private **/
  804. //class laya.wx.mini.MiniInput
  805. var MiniInput=(function(){
  806. function MiniInput(){}
  807. __class(MiniInput,'laya.wx.mini.MiniInput');
  808. MiniInput._createInputElement=function(){
  809. Input['_initInput'](Input['area']=Browser.createElement("textarea"));
  810. Input['_initInput'](Input['input']=Browser.createElement("input"));
  811. Input['inputContainer']=Browser.createElement("div");
  812. Input['inputContainer'].style.position="absolute";
  813. Input['inputContainer'].style.zIndex=1E5;
  814. Browser.container.appendChild(Input['inputContainer']);
  815. Input['inputContainer'].setPos=function (x,y){Input['inputContainer'].style.left=x+'px';Input['inputContainer'].style.top=y+'px';};
  816. Laya.stage.on("resize",null,MiniInput._onStageResize);
  817. /*__JS__ */wx.onWindowResize && /*__JS__ */wx.onWindowResize(function(res){
  818. /*__JS__ */window.dispatchEvent && /*__JS__ */window.dispatchEvent("resize");
  819. });
  820. SoundManager._soundClass=MiniSound;
  821. SoundManager._musicClass=MiniSound;
  822. var model=MiniAdpter.systemInfo.model;
  823. var system=MiniAdpter.systemInfo.system;
  824. if(model.indexOf("iPhone")!=-1){
  825. Browser.onIPhone=true;
  826. Browser.onIOS=true;
  827. Browser.onIPad=true;
  828. Browser.onAndroid=false;
  829. }
  830. if(system.indexOf("Android")!=-1 || system.indexOf("Adr")!=-1){
  831. Browser.onAndroid=true;
  832. Browser.onIPhone=false;
  833. Browser.onIOS=false;
  834. Browser.onIPad=false;
  835. }
  836. }
  837. MiniInput._onStageResize=function(){
  838. var ts=Laya.stage._canvasTransform.identity();
  839. ts.scale((Browser.width / Render.canvas.width / Browser.pixelRatio),Browser.height / Render.canvas.height / Browser.pixelRatio);
  840. }
  841. MiniInput.wxinputFocus=function(e){
  842. var _inputTarget=Input['inputElement'].target;
  843. if (_inputTarget && !_inputTarget.editable){
  844. return;
  845. }
  846. MiniAdpter.window.wx.offKeyboardConfirm();
  847. MiniAdpter.window.wx.offKeyboardInput();
  848. MiniAdpter.window.wx.showKeyboard({defaultValue:_inputTarget.text,maxLength:_inputTarget.maxChars,multiple:_inputTarget.multiline,confirmHold:true,confirmType:_inputTarget["confirmType"]||'done',success:function (res){
  849. },fail:function (res){
  850. }});
  851. MiniAdpter.window.wx.onKeyboardConfirm(function(res){
  852. var str=res ? res.value :"";
  853. if (_inputTarget._restrictPattern){
  854. str=str.replace(/\u2006|\x27/g,"");
  855. if (_inputTarget._restrictPattern.test(str)){
  856. str=str.replace(_inputTarget._restrictPattern,"");
  857. }
  858. }
  859. _inputTarget.text=str;
  860. _inputTarget.event(/*laya.events.Event.INPUT*/"input");
  861. laya.wx.mini.MiniInput.inputEnter();
  862. _inputTarget.event("confirm");
  863. })
  864. MiniAdpter.window.wx.onKeyboardInput(function(res){
  865. var str=res ? res.value :"";
  866. if (!_inputTarget.multiline){
  867. if (str.indexOf("\n")!=-1){
  868. laya.wx.mini.MiniInput.inputEnter();
  869. return;
  870. }
  871. }
  872. if (_inputTarget._restrictPattern){
  873. str=str.replace(/\u2006|\x27/g,"");
  874. if (_inputTarget._restrictPattern.test(str)){
  875. str=str.replace(_inputTarget._restrictPattern,"");
  876. }
  877. }
  878. _inputTarget.text=str;
  879. _inputTarget.event(/*laya.events.Event.INPUT*/"input");
  880. });
  881. }
  882. MiniInput.inputEnter=function(){
  883. Input['inputElement'].target.focus=false;
  884. }
  885. MiniInput.wxinputblur=function(){
  886. MiniInput.hideKeyboard();
  887. }
  888. MiniInput.hideKeyboard=function(){
  889. MiniAdpter.window.wx.offKeyboardConfirm();
  890. MiniAdpter.window.wx.offKeyboardInput();
  891. MiniAdpter.window.wx.hideKeyboard({success:function (res){
  892. console.log('隐藏键盘')
  893. },fail:function (res){
  894. console.log("隐藏键盘出错:"+(res ? res.errMsg :""));
  895. }});
  896. }
  897. return MiniInput;
  898. })()
  899. //class laya.wx.mini.MiniAdpter
  900. var MiniAdpter=(function(){
  901. function MiniAdpter(){}
  902. __class(MiniAdpter,'laya.wx.mini.MiniAdpter');
  903. MiniAdpter.getJson=function(data){
  904. return JSON.parse(data);
  905. }
  906. MiniAdpter.enable=function(){
  907. MiniAdpter.init(Laya.isWXPosMsg,Laya.isWXOpenDataContext);
  908. }
  909. MiniAdpter.init=function(isPosMsg,isSon){
  910. (isPosMsg===void 0)&& (isPosMsg=false);
  911. (isSon===void 0)&& (isSon=false);
  912. if (MiniAdpter._inited)return;
  913. MiniAdpter._inited=true;
  914. MiniAdpter.window=/*__JS__ */window;
  915. if(!MiniAdpter.window.hasOwnProperty("wx"))
  916. return;
  917. if(MiniAdpter.window.navigator.userAgent.indexOf('MiniGame')<0)return;
  918. MiniAdpter.isZiYu=isSon;
  919. MiniAdpter.isPosMsgYu=isPosMsg;
  920. MiniAdpter.EnvConfig={};
  921. if (!MiniAdpter.isZiYu){
  922. MiniFileMgr.setNativeFileDir("/layaairGame");
  923. MiniFileMgr.existDir(MiniFileMgr.fileNativeDir,Handler.create(MiniAdpter,MiniAdpter.onMkdirCallBack));
  924. }
  925. MiniAdpter.systemInfo=/*__JS__ */wx.getSystemInfoSync();
  926. MiniAdpter.window.focus=function (){
  927. };
  928. Laya['_getUrlPath']=function (){
  929. return "";
  930. };
  931. MiniAdpter.window.logtime=function (str){
  932. };
  933. MiniAdpter.window.alertTimeLog=function (str){
  934. };
  935. MiniAdpter.window.resetShareInfo=function (){
  936. };
  937. MiniAdpter.window.CanvasRenderingContext2D=function (){
  938. };
  939. MiniAdpter.window.CanvasRenderingContext2D.prototype=MiniAdpter.window.wx.createCanvas().getContext('2d').__proto__;
  940. MiniAdpter.window.document.body.appendChild=function (){
  941. };
  942. MiniAdpter.EnvConfig.pixelRatioInt=0;
  943. Browser["_pixelRatio"]=MiniAdpter.pixelRatio();
  944. MiniAdpter._preCreateElement=Browser.createElement;
  945. Browser["createElement"]=MiniAdpter.createElement;
  946. RunDriver.createShaderCondition=MiniAdpter.createShaderCondition;
  947. Utils['parseXMLFromString']=MiniAdpter.parseXMLFromString;
  948. Input['_createInputElement']=MiniInput['_createInputElement'];
  949. MiniAdpter.EnvConfig.load=Loader.prototype.load;
  950. Loader.prototype.load=MiniLoader.prototype.load;
  951. Loader.prototype._loadImage=MiniImage.prototype._loadImage;
  952. LocalStorage._baseClass=MiniLocalStorage;
  953. MiniLocalStorage.__init__();
  954. MiniAdpter.window.wx.onMessage(MiniAdpter._onMessage);
  955. }
  956. MiniAdpter._onMessage=function(data){
  957. switch (data.type){
  958. case "changeMatrix":
  959. Laya.stage.transform.identity();
  960. Laya.stage._width=data.w;
  961. Laya.stage._height=data.h;
  962. Laya.stage._canvasTransform=new Matrix(data.a,data.b,data.c,data.d,data.tx,data.ty);
  963. break ;
  964. case "display":
  965. Laya.stage.frameRate=data.rate || /*laya.display.Stage.FRAME_FAST*/"fast";
  966. break ;
  967. case "undisplay":
  968. Laya.stage.frameRate=/*laya.display.Stage.FRAME_SLEEP*/"sleep";
  969. break ;
  970. }
  971. if (data['isLoad']=="opendatacontext"){
  972. if (data.url){
  973. MiniFileMgr.ziyuFileData[data.url]=data.atlasdata;
  974. MiniFileMgr.ziyuFileTextureData[data.imgReadyUrl]=data.imgNativeUrl;
  975. }
  976. }else if (data['isLoad']=="openJsondatacontext"){
  977. if (data.url){
  978. MiniFileMgr.ziyuFileData[data.url]=data.atlasdata;
  979. }
  980. }else if (data['isLoad']=="openJsondatacontextPic"){
  981. MiniFileMgr.ziyuFileTextureData[data.imgReadyUrl]=data.imgNativeUrl;
  982. }
  983. }
  984. MiniAdpter.getUrlEncode=function(url,type){
  985. if (type=="arraybuffer")
  986. return "";
  987. return "utf8";
  988. }
  989. MiniAdpter.downLoadFile=function(fileUrl,fileType,callBack,encoding){
  990. (fileType===void 0)&& (fileType="");
  991. (encoding===void 0)&& (encoding="utf8");
  992. var fileObj=MiniFileMgr.getFileInfo(fileUrl);
  993. if (!fileObj)
  994. MiniFileMgr.downLoadFile(fileUrl,fileType,callBack,encoding);
  995. else {
  996. callBack !=null && callBack.runWith([0]);
  997. }
  998. }
  999. MiniAdpter.remove=function(fileUrl,callBack){
  1000. MiniFileMgr.deleteFile("",fileUrl,callBack,"",0);
  1001. }
  1002. MiniAdpter.removeAll=function(){
  1003. MiniFileMgr.deleteAll();
  1004. }
  1005. MiniAdpter.hasNativeFile=function(fileUrl){
  1006. return MiniFileMgr.isLocalNativeFile(fileUrl);
  1007. }
  1008. MiniAdpter.getFileInfo=function(fileUrl){
  1009. return MiniFileMgr.getFileInfo(fileUrl);
  1010. }
  1011. MiniAdpter.getFileList=function(){
  1012. return MiniFileMgr.filesListObj;
  1013. }
  1014. MiniAdpter.exitMiniProgram=function(){
  1015. MiniAdpter.window["wx"].exitMiniProgram();
  1016. }
  1017. MiniAdpter.onMkdirCallBack=function(errorCode,data){
  1018. if (!errorCode)
  1019. MiniFileMgr.filesListObj=JSON.parse(data.data);
  1020. }
  1021. MiniAdpter.pixelRatio=function(){
  1022. if (!MiniAdpter.EnvConfig.pixelRatioInt){
  1023. try {
  1024. MiniAdpter.EnvConfig.pixelRatioInt=MiniAdpter.systemInfo.pixelRatio;
  1025. return MiniAdpter.systemInfo.pixelRatio;
  1026. }catch (error){}
  1027. }
  1028. return MiniAdpter.EnvConfig.pixelRatioInt;
  1029. }
  1030. MiniAdpter.createElement=function(type){
  1031. if (type=="canvas"){
  1032. var _source;
  1033. if (MiniAdpter.idx==1){
  1034. if (MiniAdpter.isZiYu){
  1035. _source=/*__JS__ */sharedCanvas;
  1036. _source.style={};
  1037. }else {
  1038. _source=/*__JS__ */window.canvas;
  1039. }
  1040. }else {
  1041. _source=/*__JS__ */window.wx.createCanvas();
  1042. }
  1043. MiniAdpter.idx++;
  1044. return _source;
  1045. }else if (type=="textarea" || type=="input"){
  1046. return MiniAdpter.onCreateInput(type);
  1047. }else if (type=="div"){
  1048. var node=MiniAdpter._preCreateElement(type);
  1049. node.contains=function (value){
  1050. return null
  1051. };
  1052. node.removeChild=function (value){
  1053. };
  1054. return node;
  1055. }
  1056. else {
  1057. return MiniAdpter._preCreateElement(type);
  1058. }
  1059. }
  1060. MiniAdpter.onCreateInput=function(type){
  1061. var node=MiniAdpter._preCreateElement(type);
  1062. node.focus=MiniInput.wxinputFocus;
  1063. node.blur=MiniInput.wxinputblur;
  1064. node.style={};
  1065. node.value=0;
  1066. node.parentElement={};
  1067. node.placeholder={};
  1068. node.type={};
  1069. node.setColor=function (value){
  1070. };
  1071. node.setType=function (value){
  1072. };
  1073. node.setFontFace=function (value){
  1074. };
  1075. node.addEventListener=function (value){
  1076. };
  1077. node.contains=function (value){
  1078. return null
  1079. };
  1080. node.removeChild=function (value){
  1081. };
  1082. return node;
  1083. }
  1084. MiniAdpter.createShaderCondition=function(conditionScript){
  1085. var _$this=this;
  1086. var func=function (){
  1087. var abc=conditionScript;
  1088. return _$this[conditionScript.replace("this.","")];
  1089. }
  1090. return func;
  1091. }
  1092. MiniAdpter.sendAtlasToOpenDataContext=function(url){
  1093. if (!laya.wx.mini.MiniAdpter.isZiYu){
  1094. var atlasJson=Loader.getRes(URL.formatURL(url));
  1095. if (atlasJson){
  1096. var textureArr=(atlasJson.meta.image).split(",");
  1097. if (atlasJson.meta && atlasJson.meta.image){
  1098. var toloadPics=atlasJson.meta.image.split(",");
  1099. var split=url.indexOf("/")>=0 ? "/" :"\\";
  1100. var idx=url.lastIndexOf(split);
  1101. var folderPath=idx >=0 ? url.substr(0,idx+1):"";
  1102. for (var i=0,len=toloadPics.length;i < len;i++){
  1103. toloadPics[i]=folderPath+toloadPics[i];
  1104. }
  1105. }else {
  1106. toloadPics=[url.replace(".json",".png")];
  1107. }
  1108. for (i=0;i < toloadPics.length;i++){
  1109. var tempAtlasPngUrl=toloadPics[i];
  1110. MiniAdpter.postInfoToContext(url,tempAtlasPngUrl,atlasJson);
  1111. }
  1112. }else {
  1113. throw "传递的url没有获取到对应的图集数据信息,请确保图集已经过!";
  1114. }
  1115. }
  1116. }
  1117. MiniAdpter.postInfoToContext=function(url,atlaspngUrl,atlasJson){
  1118. var postData={"frames":atlasJson.frames,"meta":atlasJson.meta};
  1119. var textureUrl=atlaspngUrl;
  1120. var fileObj=MiniFileMgr.getFileInfo(URL.formatURL(atlaspngUrl));
  1121. if (fileObj){
  1122. var fileMd5Name=fileObj.md5;
  1123. var fileNativeUrl=MiniFileMgr.getFileNativePath(fileMd5Name);
  1124. }else {
  1125. fileNativeUrl=textureUrl;
  1126. }
  1127. if (fileNativeUrl){
  1128. /*__JS__ */wx.postMessage({url:url,atlasdata:postData,imgNativeUrl:fileNativeUrl,imgReadyUrl:textureUrl,isLoad:"opendatacontext"});
  1129. }else {
  1130. throw "获取图集的磁盘url路径不存在!";
  1131. }
  1132. }
  1133. MiniAdpter.sendSinglePicToOpenDataContext=function(url){
  1134. var tempTextureUrl=URL.formatURL(url);
  1135. var fileObj=MiniFileMgr.getFileInfo(tempTextureUrl);
  1136. if (fileObj){
  1137. var fileMd5Name=fileObj.md5;
  1138. var fileNativeUrl=MiniFileMgr.getFileNativePath(fileMd5Name);
  1139. url=tempTextureUrl;
  1140. }else {
  1141. fileNativeUrl=url;
  1142. }
  1143. if (fileNativeUrl){
  1144. /*__JS__ */wx.postMessage({url:url,imgNativeUrl:fileNativeUrl,imgReadyUrl:url,isLoad:"openJsondatacontextPic"});
  1145. }else {
  1146. throw "获取图集的磁盘url路径不存在!";
  1147. }
  1148. }
  1149. MiniAdpter.sendJsonDataToDataContext=function(url){
  1150. if (!laya.wx.mini.MiniAdpter.isZiYu){
  1151. var atlasJson=Loader.getRes(url);
  1152. if (atlasJson){
  1153. /*__JS__ */wx.postMessage({url:url,atlasdata:atlasJson,isLoad:"openJsondatacontext"});
  1154. }else {
  1155. throw "传递的url没有获取到对应的图集数据信息,请确保图集已经过!";
  1156. }
  1157. }
  1158. }
  1159. MiniAdpter.EnvConfig=null;
  1160. MiniAdpter.window=null;
  1161. MiniAdpter._preCreateElement=null;
  1162. MiniAdpter._inited=false;
  1163. MiniAdpter.systemInfo=null;
  1164. MiniAdpter.isZiYu=false;
  1165. MiniAdpter.isPosMsgYu=false;
  1166. MiniAdpter.autoCacheFile=true;
  1167. MiniAdpter.minClearSize=(5 *1024 *1024);
  1168. MiniAdpter.subNativeFiles=null;
  1169. MiniAdpter.subNativeheads=[];
  1170. MiniAdpter.subMaps=[];
  1171. MiniAdpter.AutoCacheDownFile=false;
  1172. MiniAdpter.parseXMLFromString=function(value){
  1173. var rst;
  1174. var Parser;
  1175. value=value.replace(/>\s+</g,'><');
  1176. try {
  1177. /*__JS__ */rst=(new window.Parser.DOMParser()).parseFromString(value,'text/xml');
  1178. }catch (error){
  1179. throw "需要引入xml解析库文件";
  1180. }
  1181. return rst;
  1182. }
  1183. MiniAdpter.idx=1;
  1184. __static(MiniAdpter,
  1185. ['nativefiles',function(){return this.nativefiles=["layaNativeDir","wxlocal"];}
  1186. ]);
  1187. return MiniAdpter;
  1188. })()
  1189. /**@private **/
  1190. //class laya.wx.mini.MiniLoader extends laya.events.EventDispatcher
  1191. var MiniLoader=(function(_super){
  1192. function MiniLoader(){
  1193. MiniLoader.__super.call(this);
  1194. }
  1195. __class(MiniLoader,'laya.wx.mini.MiniLoader',_super);
  1196. var __proto=MiniLoader.prototype;
  1197. /**
  1198. *@private
  1199. *@param url
  1200. *@param type
  1201. *@param cache
  1202. *@param group
  1203. *@param ignoreCache
  1204. */
  1205. __proto.load=function(url,type,cache,group,ignoreCache){
  1206. (cache===void 0)&& (cache=true);
  1207. (ignoreCache===void 0)&& (ignoreCache=false);
  1208. var thisLoader=this;
  1209. thisLoader._url=url;
  1210. if (!url){
  1211. thisLoader.onLoaded(null);
  1212. return;
  1213. }
  1214. url=URL.customFormat(url);
  1215. if (url.indexOf("data:image")===0)thisLoader._type=type=/*laya.net.Loader.IMAGE*/"image";
  1216. else {
  1217. thisLoader._type=type || (type=Loader.getTypeFromUrl(thisLoader._url));
  1218. }
  1219. thisLoader._cache=cache;
  1220. thisLoader._data=null;
  1221. if (!ignoreCache && Loader.loadedMap[URL.formatURL(url)]){
  1222. thisLoader._data=Loader.loadedMap[URL.formatURL(url)];
  1223. this.event(/*laya.events.Event.PROGRESS*/"progress",1);
  1224. this.event(/*laya.events.Event.COMPLETE*/"complete",thisLoader._data);
  1225. return;
  1226. }
  1227. if (Loader.parserMap[type] !=null){
  1228. thisLoader._customParse=true;
  1229. if (((Loader.parserMap[type])instanceof laya.utils.Handler ))Loader.parserMap[type].runWith(this);
  1230. else Loader.parserMap[type].call(null,this);
  1231. return;
  1232. };
  1233. var contentType;
  1234. switch (type){
  1235. case /*laya.net.Loader.ATLAS*/"atlas":
  1236. case /*laya.net.Loader.PREFAB*/"prefab":
  1237. case /*laya.net.Loader.PLF*/"plf":
  1238. contentType=/*laya.net.Loader.JSON*/"json";
  1239. break ;
  1240. case /*laya.net.Loader.FONT*/"font":
  1241. contentType=/*laya.net.Loader.XML*/"xml";
  1242. break ;
  1243. case /*laya.net.Loader.PLFB*/"plfb":
  1244. contentType=/*laya.net.Loader.BUFFER*/"arraybuffer";
  1245. break ;
  1246. default :
  1247. contentType=type;
  1248. }
  1249. if (Loader.preLoadedMap[URL.formatURL(url)]){
  1250. thisLoader.onLoaded(Loader.preLoadedMap[URL.formatURL(url)]);
  1251. return;
  1252. };
  1253. var encoding=MiniAdpter.getUrlEncode(url,contentType);
  1254. var urlType=Utils.getFileExtension(url);
  1255. if ((MiniLoader._fileTypeArr.indexOf(urlType)!=-1)){
  1256. MiniAdpter.EnvConfig.load.call(this,url,type,cache,group,ignoreCache);
  1257. }else {
  1258. if(MiniAdpter.isZiYu && !MiniFileMgr.ziyuFileData[url]){
  1259. url=URL.formatURL(url);
  1260. }
  1261. if(MiniAdpter.isZiYu && MiniFileMgr.ziyuFileData[url]){
  1262. var tempData=MiniFileMgr.ziyuFileData[url];
  1263. thisLoader.onLoaded(tempData);
  1264. return;
  1265. }
  1266. if (!MiniFileMgr.getFileInfo(url)){
  1267. if (MiniFileMgr.isLocalNativeFile(url)){
  1268. if (MiniAdpter.subNativeFiles && MiniAdpter.subNativeheads.length==0){
  1269. for (var key in MiniAdpter.subNativeFiles){
  1270. var tempArr=MiniAdpter.subNativeFiles[key];
  1271. MiniAdpter.subNativeheads=MiniAdpter.subNativeheads.concat(tempArr);
  1272. for (var aa=0;aa < tempArr.length;aa++){
  1273. MiniAdpter.subMaps[tempArr[aa]]=key+"/"+tempArr[aa];
  1274. }
  1275. }
  1276. }
  1277. if(MiniAdpter.subNativeFiles && url.indexOf("/")!=-1){
  1278. var curfileHead=url.split("/")[0]+"/";
  1279. if(curfileHead && MiniAdpter.subNativeheads.indexOf(curfileHead)!=-1){
  1280. var newfileHead=MiniAdpter.subMaps[curfileHead];
  1281. url=url.replace(curfileHead,newfileHead);
  1282. }
  1283. };
  1284. var tempStr=URL.rootPath !="" ? URL.rootPath :URL._basePath;
  1285. var tempUrl=url;
  1286. if (tempStr !="")
  1287. url=url.split(tempStr)[1];
  1288. if (!url){
  1289. url=tempUrl;
  1290. }
  1291. MiniFileMgr.read(url,encoding,new Handler(MiniLoader,MiniLoader.onReadNativeCallBack,[encoding,url,type,cache,group,ignoreCache,thisLoader]));
  1292. return;
  1293. };
  1294. var tempurl=URL.formatURL(url);
  1295. if (tempurl.indexOf("http://usr/")==-1&& (tempurl.indexOf("http://")!=-1 || tempurl.indexOf("https://")!=-1)&& !MiniAdpter.AutoCacheDownFile){
  1296. MiniAdpter.EnvConfig.load.call(thisLoader,url,type,cache,group,ignoreCache);
  1297. }else {
  1298. MiniFileMgr.readFile(url,encoding,new Handler(MiniLoader,MiniLoader.onReadNativeCallBack,[encoding,url,type,cache,group,ignoreCache,thisLoader]),url);
  1299. }
  1300. }else {
  1301. var fileObj=MiniFileMgr.getFileInfo(url);
  1302. fileObj.encoding=fileObj.encoding==null ? "utf8" :fileObj.encoding;
  1303. MiniFileMgr.readFile(url,fileObj.encoding,new Handler(MiniLoader,MiniLoader.onReadNativeCallBack,[encoding,url,type,cache,group,ignoreCache,thisLoader]),url);
  1304. }
  1305. }
  1306. }
  1307. MiniLoader.onReadNativeCallBack=function(encoding,url,type,cache,group,ignoreCache,thisLoader,errorCode,data){
  1308. (cache===void 0)&& (cache=true);
  1309. (ignoreCache===void 0)&& (ignoreCache=false);
  1310. (errorCode===void 0)&& (errorCode=0);
  1311. if (!errorCode){
  1312. var tempData;
  1313. if (type==/*laya.net.Loader.JSON*/"json" || type==/*laya.net.Loader.ATLAS*/"atlas" || type==/*laya.net.Loader.PREFAB*/"prefab" || type==/*laya.net.Loader.PLF*/"plf"){
  1314. tempData=MiniAdpter.getJson(data.data);
  1315. }else if (type==/*laya.net.Loader.XML*/"xml"){
  1316. tempData=Utils.parseXMLFromString(data.data);
  1317. }else {
  1318. tempData=data.data;
  1319. }
  1320. if(!MiniAdpter.isZiYu &&MiniAdpter.isPosMsgYu && type !=/*laya.net.Loader.BUFFER*/"arraybuffer"){
  1321. /*__JS__ */wx.postMessage({url:url,data:tempData,isLoad:"filedata"});
  1322. }
  1323. thisLoader.onLoaded(tempData);
  1324. }else if (errorCode==1){
  1325. MiniAdpter.EnvConfig.load.call(thisLoader,url,type,cache,group,ignoreCache);
  1326. }
  1327. }
  1328. __static(MiniLoader,
  1329. ['_fileTypeArr',function(){return this._fileTypeArr=['png','jpg','bmp','jpeg','gif'];}
  1330. ]);
  1331. return MiniLoader;
  1332. })(EventDispatcher)
  1333. /**@private **/
  1334. //class laya.wx.mini.MiniSound extends laya.events.EventDispatcher
  1335. var MiniSound=(function(_super){
  1336. function MiniSound(){
  1337. /**@private **/
  1338. this._sound=null;
  1339. /**
  1340. *@private
  1341. *声音URL
  1342. */
  1343. this.url=null;
  1344. /**
  1345. *@private
  1346. *是否已加载完成
  1347. */
  1348. this.loaded=false;
  1349. /**@private **/
  1350. this.readyUrl=null;
  1351. MiniSound.__super.call(this);
  1352. }
  1353. __class(MiniSound,'laya.wx.mini.MiniSound',_super);
  1354. var __proto=MiniSound.prototype;
  1355. /**
  1356. *@private
  1357. *加载声音。
  1358. *@param url 地址。
  1359. *
  1360. */
  1361. __proto.load=function(url){
  1362. if (!MiniFileMgr.isLocalNativeFile(url)){
  1363. url=URL.formatURL(url);
  1364. }else{
  1365. if (url.indexOf("http://")!=-1 || url.indexOf("https://")!=-1){
  1366. if(MiniFileMgr.loadPath !=""){
  1367. url=url.split(MiniFileMgr.loadPath)[1];
  1368. }else{
  1369. var tempStr=URL.rootPath !="" ? URL.rootPath :URL._basePath;
  1370. if(tempStr !="")
  1371. url=url.split(tempStr)[1];
  1372. }
  1373. }
  1374. }
  1375. this.url=url;
  1376. this.readyUrl=url;
  1377. if (MiniSound._audioCache[this.readyUrl]){
  1378. this.event(/*laya.events.Event.COMPLETE*/"complete");
  1379. return;
  1380. }
  1381. if(MiniAdpter.autoCacheFile&&MiniFileMgr.getFileInfo(url)){
  1382. this.onDownLoadCallBack(url,0);
  1383. }else{
  1384. if(!MiniAdpter.autoCacheFile){
  1385. this.onDownLoadCallBack(url,0);
  1386. }else{
  1387. if (MiniFileMgr.isLocalNativeFile(url)){
  1388. tempStr=URL.rootPath !="" ? URL.rootPath :URL._basePath;
  1389. var tempUrl=url;
  1390. if(tempStr !="")
  1391. url=url.split(tempStr)[1];
  1392. if (!url){
  1393. url=tempUrl;
  1394. }
  1395. if (MiniAdpter.subNativeFiles && MiniAdpter.subNativeheads.length==0){
  1396. for (var key in MiniAdpter.subNativeFiles){
  1397. var tempArr=MiniAdpter.subNativeFiles[key];
  1398. MiniAdpter.subNativeheads=MiniAdpter.subNativeheads.concat(tempArr);
  1399. for (var aa=0;aa < tempArr.length;aa++){
  1400. MiniAdpter.subMaps[tempArr[aa]]=key+"/"+tempArr[aa];
  1401. }
  1402. }
  1403. }
  1404. if(MiniAdpter.subNativeFiles && url.indexOf("/")!=-1){
  1405. var curfileHead=url.split("/")[0]+"/";
  1406. if(curfileHead && MiniAdpter.subNativeheads.indexOf(curfileHead)!=-1){
  1407. var newfileHead=MiniAdpter.subMaps[curfileHead];
  1408. url=url.replace(curfileHead,newfileHead);
  1409. }
  1410. }
  1411. this.onDownLoadCallBack(url,0);
  1412. }else{
  1413. if (!MiniFileMgr.isLocalNativeFile(url)&& (url.indexOf("http://")==-1 && url.indexOf("https://")==-1)|| (url.indexOf("http://usr/")!=-1)){
  1414. this.onDownLoadCallBack(url,0);
  1415. }else{
  1416. MiniFileMgr.downOtherFiles(url,Handler.create(this,this.onDownLoadCallBack,[url]),url);
  1417. }
  1418. }
  1419. }
  1420. }
  1421. }
  1422. /**@private **/
  1423. __proto.onDownLoadCallBack=function(sourceUrl,errorCode){
  1424. if (!errorCode){
  1425. var fileNativeUrl;
  1426. if(MiniAdpter.autoCacheFile){
  1427. if (MiniFileMgr.isLocalNativeFile(sourceUrl)){
  1428. var tempStr=URL.rootPath !="" ? URL.rootPath :URL._basePath;
  1429. var tempUrl=sourceUrl;
  1430. if(tempStr !="" && (sourceUrl.indexOf("http://")!=-1 || sourceUrl.indexOf("https://")!=-1))
  1431. fileNativeUrl=sourceUrl.split(tempStr)[1];
  1432. if(!fileNativeUrl){
  1433. fileNativeUrl=tempUrl;
  1434. }
  1435. }else{
  1436. var fileObj=MiniFileMgr.getFileInfo(sourceUrl);
  1437. if(fileObj && fileObj.md5){
  1438. var fileMd5Name=fileObj.md5;
  1439. fileNativeUrl=MiniFileMgr.getFileNativePath(fileMd5Name);
  1440. }else{
  1441. fileNativeUrl=sourceUrl;
  1442. }
  1443. }
  1444. this._sound=MiniSound._createSound();
  1445. this._sound.src=this.url=fileNativeUrl;
  1446. }else{
  1447. this._sound=MiniSound._createSound();
  1448. this._sound.src=sourceUrl;
  1449. }
  1450. this._sound.onCanplay(MiniSound.bindToThis(this.onCanPlay,this));
  1451. this._sound.onError(MiniSound.bindToThis(this.onError,this));
  1452. }else{
  1453. this.event(/*laya.events.Event.ERROR*/"error");
  1454. }
  1455. }
  1456. /**@private **/
  1457. __proto.onError=function(error){
  1458. try{
  1459. console.log("-----1---------------minisound-----id:"+MiniSound._id);
  1460. console.log(error);
  1461. }
  1462. catch(error){
  1463. console.log("-----2---------------minisound-----id:"+MiniSound._id);
  1464. console.log(error);
  1465. }
  1466. this.event(/*laya.events.Event.ERROR*/"error");
  1467. this._sound.offError(null);
  1468. }
  1469. /**@private **/
  1470. __proto.onCanPlay=function(){
  1471. this.loaded=true;
  1472. this.event(/*laya.events.Event.COMPLETE*/"complete");
  1473. this._sound.offCanplay(null);
  1474. }
  1475. /**
  1476. *@private
  1477. *播放声音。
  1478. *@param startTime 开始时间,单位秒
  1479. *@param loops 循环次数,0表示一直循环
  1480. *@return 声道 SoundChannel 对象。
  1481. *
  1482. */
  1483. __proto.play=function(startTime,loops){
  1484. (startTime===void 0)&& (startTime=0);
  1485. (loops===void 0)&& (loops=0);
  1486. var tSound;
  1487. if (this.url==SoundManager._bgMusic){
  1488. if (!MiniSound._musicAudio)MiniSound._musicAudio=MiniSound._createSound();
  1489. tSound=MiniSound._musicAudio;
  1490. }else {
  1491. if(MiniSound._audioCache[this.readyUrl]){
  1492. tSound=MiniSound._audioCache[this.readyUrl]._sound;
  1493. }else{
  1494. tSound=MiniSound._createSound();
  1495. }
  1496. }
  1497. if(!tSound)
  1498. return null;
  1499. if(MiniAdpter.autoCacheFile&&MiniFileMgr.getFileInfo(this.url)){
  1500. var fileNativeUrl;
  1501. var fileObj=MiniFileMgr.getFileInfo(this.url);
  1502. var fileMd5Name=fileObj.md5;
  1503. tSound.src=this.url=MiniFileMgr.getFileNativePath(fileMd5Name);
  1504. }else{
  1505. tSound.src=this.url;
  1506. };
  1507. var channel=new MiniSoundChannel(tSound,this);
  1508. channel.url=this.url;
  1509. channel.loops=loops;
  1510. channel.loop=(loops===0 ? true :false);
  1511. channel.startTime=startTime;
  1512. channel.play();
  1513. SoundManager.addChannel(channel);
  1514. return channel;
  1515. }
  1516. /**
  1517. *@private
  1518. *释放声音资源。
  1519. *
  1520. */
  1521. __proto.dispose=function(){
  1522. var ad=MiniSound._audioCache[this.readyUrl];
  1523. if (ad){
  1524. ad.src="";
  1525. if(ad._sound){
  1526. ad._sound.destroy();
  1527. ad._sound=null;
  1528. ad=null;
  1529. }
  1530. delete MiniSound._audioCache[this.readyUrl];
  1531. }
  1532. }
  1533. /**
  1534. *@private
  1535. *获取总时间。
  1536. */
  1537. __getset(0,__proto,'duration',function(){
  1538. return this._sound.duration;
  1539. });
  1540. MiniSound._createSound=function(){
  1541. MiniSound._id++;
  1542. return MiniAdpter.window.wx.createInnerAudioContext();
  1543. }
  1544. MiniSound.bindToThis=function(fun,scope){
  1545. var rst=fun;
  1546. /*__JS__ */rst=fun.bind(scope);;
  1547. return rst;
  1548. }
  1549. MiniSound._musicAudio=null;
  1550. MiniSound._id=0;
  1551. MiniSound._audioCache={};
  1552. return MiniSound;
  1553. })(EventDispatcher)
  1554. /**@private **/
  1555. //class laya.wx.mini.MiniAccelerator extends laya.events.EventDispatcher
  1556. var MiniAccelerator=(function(_super){
  1557. function MiniAccelerator(){
  1558. MiniAccelerator.__super.call(this);
  1559. }
  1560. __class(MiniAccelerator,'laya.wx.mini.MiniAccelerator',_super);
  1561. var __proto=MiniAccelerator.prototype;
  1562. /**
  1563. *侦听加速器运动。
  1564. *@param observer 回调函数接受4个参数,见类说明。
  1565. */
  1566. __proto.on=function(type,caller,listener,args){
  1567. _super.prototype.on.call(this,type,caller,listener,args);
  1568. MiniAccelerator.startListen(this["onDeviceOrientationChange"]);
  1569. return this;
  1570. }
  1571. /**
  1572. *取消侦听加速器。
  1573. *@param handle 侦听加速器所用处理器。
  1574. */
  1575. __proto.off=function(type,caller,listener,onceOnly){
  1576. (onceOnly===void 0)&& (onceOnly=false);
  1577. if (!this.hasListener(type))
  1578. MiniAccelerator.stopListen();
  1579. return _super.prototype.off.call(this,type,caller,listener,onceOnly);
  1580. }
  1581. MiniAccelerator.__init__=function(){
  1582. try{
  1583. var Acc;
  1584. Acc=/*__JS__ */laya.device.motion.Accelerator;
  1585. if (!Acc)return;
  1586. Acc["prototype"]["on"]=MiniAccelerator["prototype"]["on"];
  1587. Acc["prototype"]["off"]=MiniAccelerator["prototype"]["off"];
  1588. }catch (e){
  1589. }
  1590. }
  1591. MiniAccelerator.startListen=function(callBack){
  1592. MiniAccelerator._callBack=callBack;
  1593. if (MiniAccelerator._isListening)return;
  1594. MiniAccelerator._isListening=true;
  1595. try{
  1596. /*__JS__ */wx.onAccelerometerChange(MiniAccelerator.onAccelerometerChange);
  1597. }catch(e){}
  1598. }
  1599. MiniAccelerator.stopListen=function(){
  1600. MiniAccelerator._isListening=false;
  1601. try{
  1602. /*__JS__ */wx.stopAccelerometer({});
  1603. }catch(e){}
  1604. }
  1605. MiniAccelerator.onAccelerometerChange=function(res){
  1606. var e;
  1607. e={};
  1608. e.acceleration=res;
  1609. e.accelerationIncludingGravity=res;
  1610. e.rotationRate={};
  1611. if (MiniAccelerator._callBack !=null){
  1612. MiniAccelerator._callBack(e);
  1613. }
  1614. }
  1615. MiniAccelerator._isListening=false;
  1616. MiniAccelerator._callBack=null;
  1617. return MiniAccelerator;
  1618. })(EventDispatcher)
  1619. /**@private **/
  1620. //class laya.wx.mini.MiniSoundChannel extends laya.media.SoundChannel
  1621. var MiniSoundChannel=(function(_super){
  1622. function MiniSoundChannel(audio,miniSound){
  1623. /**@private **/
  1624. this._audio=null;
  1625. /**@private **/
  1626. this._onEnd=null;
  1627. /**@private **/
  1628. this._miniSound=null;
  1629. MiniSoundChannel.__super.call(this);
  1630. this._audio=audio;
  1631. this._miniSound=miniSound;
  1632. this._onEnd=MiniSoundChannel.bindToThis(this.__onEnd,this);
  1633. audio.onEnded(this._onEnd);
  1634. }
  1635. __class(MiniSoundChannel,'laya.wx.mini.MiniSoundChannel',_super);
  1636. var __proto=MiniSoundChannel.prototype;
  1637. /**@private **/
  1638. __proto.__onEnd=function(){
  1639. MiniSound._audioCache[this.url]=this._miniSound;
  1640. if (this.loops==1){
  1641. if (this.completeHandler){
  1642. Laya.systemTimer.once(10,this,this.__runComplete,[this.completeHandler],false);
  1643. this.completeHandler=null;
  1644. }
  1645. this.stop();
  1646. this.event(/*laya.events.Event.COMPLETE*/"complete");
  1647. return;
  1648. }
  1649. if (this.loops > 0){
  1650. this.loops--;
  1651. }
  1652. this.startTime=0;
  1653. this.play();
  1654. }
  1655. /**
  1656. *@private
  1657. *播放
  1658. */
  1659. __proto.play=function(){
  1660. this.isStopped=false;
  1661. SoundManager.addChannel(this);
  1662. this._audio.play();
  1663. }
  1664. /**
  1665. *@private
  1666. *停止播放
  1667. *
  1668. */
  1669. __proto.stop=function(){
  1670. this.isStopped=true;
  1671. SoundManager.removeChannel(this);
  1672. this.completeHandler=null;
  1673. if (!this._audio)
  1674. return;
  1675. this._audio.stop();
  1676. this._audio.offEnded(null);
  1677. this._miniSound.dispose();
  1678. this._audio=null;
  1679. this._miniSound=null;
  1680. this._onEnd=null;
  1681. }
  1682. /**@private **/
  1683. __proto.pause=function(){
  1684. this.isStopped=true;
  1685. this._audio.pause();
  1686. }
  1687. /**@private **/
  1688. __proto.resume=function(){
  1689. if (!this._audio)
  1690. return;
  1691. this.isStopped=false;
  1692. SoundManager.addChannel(this);
  1693. this._audio.play();
  1694. }
  1695. /**
  1696. *设置开始时间
  1697. *@param time
  1698. */
  1699. __getset(0,__proto,'startTime',null,function(time){
  1700. if(this._audio){
  1701. this._audio.startTime=time;
  1702. }
  1703. });
  1704. /**@private **/
  1705. /**
  1706. *@private
  1707. *自动播放
  1708. *@param value
  1709. */
  1710. __getset(0,__proto,'autoplay',function(){
  1711. return this._audio.autoplay;
  1712. },function(value){
  1713. this._audio.autoplay=value;
  1714. });
  1715. /**
  1716. *@private
  1717. *当前播放到的位置
  1718. *@return
  1719. *
  1720. */
  1721. __getset(0,__proto,'position',function(){
  1722. if (!this._audio)
  1723. return 0;
  1724. return this._audio.currentTime;
  1725. });
  1726. /**
  1727. *@private
  1728. *获取总时间。
  1729. */
  1730. __getset(0,__proto,'duration',function(){
  1731. if (!this._audio)
  1732. return 0;
  1733. return this._audio.duration;
  1734. });
  1735. /**@private **/
  1736. /**@private **/
  1737. __getset(0,__proto,'loop',function(){
  1738. return this._audio.loop;
  1739. },function(value){
  1740. this._audio.loop=value;
  1741. });
  1742. /**
  1743. *@private
  1744. *设置音量
  1745. *@param v
  1746. *
  1747. */
  1748. /**
  1749. *@private
  1750. *获取音量
  1751. *@return
  1752. */
  1753. __getset(0,__proto,'volume',function(){
  1754. if (!this._audio)return 1;
  1755. return this._audio.volume;
  1756. },function(v){
  1757. if (!this._audio)return;
  1758. this._audio.volume=v;
  1759. });
  1760. MiniSoundChannel.bindToThis=function(fun,scope){
  1761. var rst=fun;
  1762. /*__JS__ */rst=fun.bind(scope);;
  1763. return rst;
  1764. }
  1765. return MiniSoundChannel;
  1766. })(SoundChannel)
  1767. },1000);