laya.wxmini.js 65 KB

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