laya.wxmini.js 55 KB

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