laya.bdmini.js 65 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683
  1. window.bdMiniGame = function (exports, Laya) {
  2. 'use strict';
  3. class MiniFileMgr {
  4. static isLocalNativeFile(url) {
  5. for (var i = 0, sz = BMiniAdapter.nativefiles.length; i < sz; i++) {
  6. if (url.indexOf(BMiniAdapter.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(BMiniAdapter.window.swan.env.USER_DATA_PATH) == -1 && (filePath.indexOf("http://") != -1 || filePath.indexOf("https://") != -1)) {
  59. if (BMiniAdapter.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 ((BMiniAdapter.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('SwanGame') < 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 > BMiniAdapter.minClearSize)
  118. BMiniAdapter.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 > BMiniAdapter.minClearSize)
  137. BMiniAdapter.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 = BMiniAdapter.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 (!BMiniAdapter.isZiYu && BMiniAdapter.isPosMsgYu) {
  237. BMiniAdapter.window.swan.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 = BMiniAdapter.window.swan.env.USER_DATA_PATH + value;
  268. }
  269. }
  270. MiniFileMgr.fs = window.swan.getFileSystemManager();
  271. MiniFileMgr.wxdown = window.swan.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 BMiniAdapter.window.swan.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 (BMiniAdapter.autoCacheFile && MiniFileMgr.getFileInfo(url)) {
  410. this.onDownLoadCallBack(url, 0);
  411. }
  412. else {
  413. if (!BMiniAdapter.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 (BMiniAdapter.subNativeFiles && BMiniAdapter.subNativeheads.length == 0) {
  426. for (var key in BMiniAdapter.subNativeFiles) {
  427. var tempArr = BMiniAdapter.subNativeFiles[key];
  428. BMiniAdapter.subNativeheads = BMiniAdapter.subNativeheads.concat(tempArr);
  429. for (var aa = 0; aa < tempArr.length; aa++) {
  430. BMiniAdapter.subMaps[tempArr[aa]] = key + "/" + tempArr[aa];
  431. }
  432. }
  433. }
  434. if (BMiniAdapter.subNativeFiles && url.indexOf("/") != -1) {
  435. var curfileHead = url.split("/")[0] + "/";
  436. if (curfileHead && BMiniAdapter.subNativeheads.indexOf(curfileHead) != -1) {
  437. var newfileHead = BMiniAdapter.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(BMiniAdapter.window.swan.env.USER_DATA_PATH) != -1)) {
  445. this.onDownLoadCallBack(url, 0);
  446. }
  447. else {
  448. MiniFileMgr.downOtherFiles(encodeURI(url), Laya.Handler.create(this, this.onDownLoadCallBack, [url]), url);
  449. }
  450. }
  451. }
  452. }
  453. }
  454. onDownLoadCallBack(sourceUrl, errorCode) {
  455. if (!errorCode) {
  456. var fileNativeUrl;
  457. if (BMiniAdapter.autoCacheFile) {
  458. if (MiniFileMgr.isLocalNativeFile(sourceUrl)) {
  459. var tempStr = Laya.URL.rootPath != "" ? Laya.URL.rootPath : Laya.URL._basePath;
  460. var tempUrl = sourceUrl;
  461. if (tempStr != "" && (sourceUrl.indexOf("http://") != -1 || sourceUrl.indexOf("https://") != -1))
  462. fileNativeUrl = sourceUrl.split(tempStr)[1];
  463. if (!fileNativeUrl) {
  464. fileNativeUrl = tempUrl;
  465. }
  466. }
  467. else {
  468. var fileObj = MiniFileMgr.getFileInfo(sourceUrl);
  469. if (fileObj && fileObj.md5) {
  470. var fileMd5Name = fileObj.md5;
  471. fileNativeUrl = MiniFileMgr.getFileNativePath(fileMd5Name);
  472. }
  473. else {
  474. fileNativeUrl = sourceUrl;
  475. }
  476. }
  477. this._sound = MiniSound._createSound();
  478. this._sound.src = this.url = fileNativeUrl;
  479. }
  480. else {
  481. this._sound = MiniSound._createSound();
  482. this._sound.src = this.url = encodeURI(sourceUrl);
  483. }
  484. this._sound.onCanplay(MiniSound.bindToThis(this.onCanPlay, this));
  485. this._sound.onError(MiniSound.bindToThis(this.onError, this));
  486. }
  487. else {
  488. this.event(Laya.Event.ERROR);
  489. }
  490. }
  491. onError(error) {
  492. try {
  493. console.log("-----1---------------minisound-----id:" + MiniSound._id);
  494. console.log(error);
  495. }
  496. catch (error) {
  497. console.log("-----2---------------minisound-----id:" + MiniSound._id);
  498. console.log(error);
  499. }
  500. this.event(Laya.Event.ERROR);
  501. this._sound.offError(null);
  502. }
  503. onCanPlay() {
  504. this.loaded = true;
  505. this.event(Laya.Event.COMPLETE);
  506. this._sound.offCanplay(null);
  507. }
  508. static bindToThis(fun, scope) {
  509. var rst = fun;
  510. rst = fun.bind(scope);
  511. return rst;
  512. }
  513. play(startTime = 0, loops = 0) {
  514. var tSound;
  515. if (this.url == Laya.SoundManager._bgMusic) {
  516. if (!MiniSound._musicAudio)
  517. MiniSound._musicAudio = MiniSound._createSound();
  518. tSound = MiniSound._musicAudio;
  519. }
  520. else {
  521. if (MiniSound._audioCache[this.readyUrl]) {
  522. tSound = MiniSound._audioCache[this.readyUrl]._sound;
  523. }
  524. else {
  525. tSound = MiniSound._createSound();
  526. }
  527. }
  528. if (!tSound)
  529. return null;
  530. if (BMiniAdapter.autoCacheFile && MiniFileMgr.getFileInfo(this.url)) {
  531. var fileObj = MiniFileMgr.getFileInfo(this.url);
  532. var fileMd5Name = fileObj.md5;
  533. tSound.src = this.url = MiniFileMgr.getFileNativePath(fileMd5Name);
  534. }
  535. else {
  536. tSound.src = encodeURI(this.url);
  537. }
  538. var channel = new MiniSoundChannel(tSound, this);
  539. channel.url = this.url;
  540. channel.loops = loops;
  541. channel.loop = (loops === 0 ? true : false);
  542. channel.startTime = startTime;
  543. channel.play();
  544. Laya.SoundManager.addChannel(channel);
  545. return channel;
  546. }
  547. get duration() {
  548. return this._sound.duration;
  549. }
  550. dispose() {
  551. var ad = MiniSound._audioCache[this.readyUrl];
  552. if (ad) {
  553. ad.src = "";
  554. if (ad._sound) {
  555. ad._sound.destroy();
  556. ad._sound = null;
  557. ad = null;
  558. }
  559. delete MiniSound._audioCache[this.readyUrl];
  560. }
  561. if (this._sound) {
  562. this._sound.destroy();
  563. this._sound = null;
  564. this.readyUrl = this.url = null;
  565. }
  566. }
  567. }
  568. MiniSound._id = 0;
  569. MiniSound._audioCache = {};
  570. class MiniInput {
  571. constructor() {
  572. }
  573. static _createInputElement() {
  574. Laya.Input['_initInput'](Laya.Input['area'] = Laya.Browser.createElement("textarea"));
  575. Laya.Input['_initInput'](Laya.Input['input'] = Laya.Browser.createElement("input"));
  576. Laya.Input['inputContainer'] = Laya.Browser.createElement("div");
  577. Laya.Input['inputContainer'].style.position = "absolute";
  578. Laya.Input['inputContainer'].style.zIndex = 1E5;
  579. Laya.Browser.container.appendChild(Laya.Input['inputContainer']);
  580. Laya.Laya.stage.on("resize", null, MiniInput._onStageResize);
  581. BMiniAdapter.window.swan.onWindowResize && BMiniAdapter.window.swan.onWindowResize(function (res) {
  582. });
  583. Laya.SoundManager._soundClass = MiniSound;
  584. Laya.SoundManager._musicClass = MiniSound;
  585. var model = BMiniAdapter.systemInfo.model;
  586. var system = BMiniAdapter.systemInfo.system;
  587. if (model.indexOf("iPhone") != -1) {
  588. Laya.Browser.onIPhone = true;
  589. Laya.Browser.onIOS = true;
  590. Laya.Browser.onIPad = true;
  591. Laya.Browser.onAndroid = false;
  592. }
  593. if (system.indexOf("Android") != -1 || system.indexOf("Adr") != -1) {
  594. Laya.Browser.onAndroid = true;
  595. Laya.Browser.onIPhone = false;
  596. Laya.Browser.onIOS = false;
  597. Laya.Browser.onIPad = false;
  598. }
  599. }
  600. static _onStageResize() {
  601. var ts = Laya.Laya.stage._canvasTransform.identity();
  602. ts.scale((Laya.Browser.width / Laya.Render.canvas.width / Laya.Browser.pixelRatio), Laya.Browser.height / Laya.Render.canvas.height / Laya.Browser.pixelRatio);
  603. }
  604. static wxinputFocus(e) {
  605. var _inputTarget = Laya.Input['inputElement'].target;
  606. if (_inputTarget && !_inputTarget.editable) {
  607. return;
  608. }
  609. BMiniAdapter.window.swan.offKeyboardConfirm();
  610. BMiniAdapter.window.swan.offKeyboardInput();
  611. BMiniAdapter.window.swan.showKeyboard({ defaultValue: _inputTarget.text, maxLength: _inputTarget.maxChars, multiple: _inputTarget.multiline, confirmHold: true, confirmType: _inputTarget["confirmType"] || 'done', success: function (res) {
  612. }, fail: function (res) {
  613. } });
  614. BMiniAdapter.window.swan.onKeyboardConfirm(function (res) {
  615. var str = res ? res.value : "";
  616. if (_inputTarget._restrictPattern) {
  617. str = str.replace(/\u2006|\x27/g, "");
  618. if (_inputTarget._restrictPattern.test(str)) {
  619. str = str.replace(_inputTarget._restrictPattern, "");
  620. }
  621. }
  622. _inputTarget.text = str;
  623. _inputTarget.event(Laya.Event.INPUT);
  624. MiniInput.inputEnter();
  625. _inputTarget.event("confirm");
  626. });
  627. BMiniAdapter.window.swan.onKeyboardInput(function (res) {
  628. var str = res ? res.value : "";
  629. if (!_inputTarget.multiline) {
  630. if (str.indexOf("\n") != -1) {
  631. MiniInput.inputEnter();
  632. return;
  633. }
  634. }
  635. if (_inputTarget._restrictPattern) {
  636. str = str.replace(/\u2006|\x27/g, "");
  637. if (_inputTarget._restrictPattern.test(str)) {
  638. str = str.replace(_inputTarget._restrictPattern, "");
  639. }
  640. }
  641. _inputTarget.text = str;
  642. _inputTarget.event(Laya.Event.INPUT);
  643. });
  644. }
  645. static inputEnter() {
  646. Laya.Input['inputElement'].target.focus = false;
  647. }
  648. static wxinputblur() {
  649. MiniInput.hideKeyboard();
  650. }
  651. static hideKeyboard() {
  652. BMiniAdapter.window.swan.offKeyboardConfirm();
  653. BMiniAdapter.window.swan.offKeyboardInput();
  654. BMiniAdapter.window.swan.hideKeyboard({ success: function (res) {
  655. console.log('隐藏键盘');
  656. }, fail: function (res) {
  657. console.log("隐藏键盘出错:" + (res ? res.errMsg : ""));
  658. } });
  659. }
  660. }
  661. class MiniLoader extends Laya.EventDispatcher {
  662. constructor() {
  663. super();
  664. }
  665. _loadResourceFilter(type, url) {
  666. var thisLoader = this;
  667. if (url.indexOf(BMiniAdapter.window.swan.env.USER_DATA_PATH) == -1 && (url.indexOf("http://") != -1 || url.indexOf("https://") != -1)) {
  668. if (MiniFileMgr.loadPath != "") {
  669. url = url.split(MiniFileMgr.loadPath)[1];
  670. }
  671. else {
  672. var tempStr = Laya.URL.rootPath != "" ? Laya.URL.rootPath : Laya.URL._basePath;
  673. var tempUrl = url;
  674. if (tempStr != "")
  675. url = url.split(tempStr)[1];
  676. if (!url) {
  677. url = tempUrl;
  678. }
  679. }
  680. }
  681. if (BMiniAdapter.subNativeFiles && BMiniAdapter.subNativeheads.length == 0) {
  682. for (var key in BMiniAdapter.subNativeFiles) {
  683. var tempArr = BMiniAdapter.subNativeFiles[key];
  684. BMiniAdapter.subNativeheads = BMiniAdapter.subNativeheads.concat(tempArr);
  685. for (var aa = 0; aa < tempArr.length; aa++) {
  686. BMiniAdapter.subMaps[tempArr[aa]] = key + "/" + tempArr[aa];
  687. }
  688. }
  689. }
  690. if (BMiniAdapter.subNativeFiles && url.indexOf("/") != -1) {
  691. var curfileHead = url.split("/")[0] + "/";
  692. if (curfileHead && BMiniAdapter.subNativeheads.indexOf(curfileHead) != -1) {
  693. var newfileHead = BMiniAdapter.subMaps[curfileHead];
  694. url = url.replace(curfileHead, newfileHead);
  695. }
  696. }
  697. switch (type) {
  698. case Laya.Loader.IMAGE:
  699. case "htmlimage":
  700. case "nativeimage":
  701. MiniLoader._transformImgUrl(url, type, thisLoader);
  702. break;
  703. case Laya.Loader.SOUND:
  704. thisLoader._loadSound(url);
  705. break;
  706. default:
  707. thisLoader._loadResource(type, url);
  708. }
  709. }
  710. _loadSound(url) {
  711. var thisLoader = this;
  712. var fileNativeUrl;
  713. if (MiniFileMgr.isLocalNativeFile(url)) {
  714. var tempStr = Laya.URL.rootPath != "" ? Laya.URL.rootPath : Laya.URL._basePath;
  715. var tempUrl = url;
  716. if (tempStr != "" && (url.indexOf("http://") != -1 || url.indexOf("https://") != -1))
  717. fileNativeUrl = url.split(tempStr)[1];
  718. if (!fileNativeUrl) {
  719. fileNativeUrl = tempUrl;
  720. }
  721. MiniLoader.onDownLoadCallBack(url, thisLoader, 0);
  722. }
  723. else {
  724. var tempurl = Laya.URL.formatURL(url);
  725. if (!MiniFileMgr.isLocalNativeFile(url) && (tempurl.indexOf("http://") == -1 && tempurl.indexOf("https://") == -1) || (tempurl.indexOf("http://usr/") != -1)) {
  726. MiniLoader.onDownLoadCallBack(url, thisLoader, 0);
  727. }
  728. else {
  729. MiniFileMgr.downOtherFiles(encodeURI(tempurl), Laya.Handler.create(MiniLoader, MiniLoader.onDownLoadCallBack, [tempurl, thisLoader]), tempurl);
  730. }
  731. }
  732. }
  733. static onDownLoadCallBack(sourceUrl, thisLoader, errorCode, tempFilePath = null) {
  734. if (!errorCode) {
  735. var fileNativeUrl;
  736. if (BMiniAdapter.autoCacheFile) {
  737. if (!tempFilePath) {
  738. if (MiniFileMgr.isLocalNativeFile(sourceUrl)) {
  739. var tempStr = Laya.URL.rootPath != "" ? Laya.URL.rootPath : Laya.URL._basePath;
  740. var tempUrl = sourceUrl;
  741. if (tempStr != "" && (sourceUrl.indexOf("http://") != -1 || sourceUrl.indexOf("https://") != -1))
  742. fileNativeUrl = sourceUrl.split(tempStr)[1];
  743. if (!fileNativeUrl) {
  744. fileNativeUrl = tempUrl;
  745. }
  746. }
  747. else {
  748. var fileObj = MiniFileMgr.getFileInfo(sourceUrl);
  749. if (fileObj && fileObj.md5) {
  750. var fileMd5Name = fileObj.md5;
  751. fileNativeUrl = MiniFileMgr.getFileNativePath(fileMd5Name);
  752. }
  753. else {
  754. fileNativeUrl = sourceUrl;
  755. }
  756. }
  757. }
  758. else {
  759. fileNativeUrl = tempFilePath;
  760. }
  761. }
  762. sourceUrl = fileNativeUrl;
  763. var sound = (new Laya.SoundManager._soundClass());
  764. sound.load(sourceUrl);
  765. thisLoader.onLoaded(sound);
  766. }
  767. else {
  768. thisLoader.event(Laya.Event.ERROR, "Load sound failed");
  769. }
  770. }
  771. static bindToThis(fun, scope) {
  772. var rst = fun;
  773. rst = fun.bind(scope);
  774. return rst;
  775. }
  776. _loadHttpRequestWhat(url, contentType) {
  777. var thisLoader = this;
  778. var encoding = BMiniAdapter.getUrlEncode(url, contentType);
  779. if (Laya.Loader.preLoadedMap[url])
  780. thisLoader.onLoaded(Laya.Loader.preLoadedMap[url]);
  781. else {
  782. var tempurl = Laya.URL.formatURL(url);
  783. if (url.indexOf(BMiniAdapter.window.swan.env.USER_DATA_PATH) == -1 && (tempurl.indexOf("http://") != -1 || tempurl.indexOf("https://") != -1) && !BMiniAdapter.AutoCacheDownFile) {
  784. thisLoader._loadHttpRequest(tempurl, contentType, thisLoader, thisLoader.onLoaded, thisLoader, thisLoader.onProgress, thisLoader, thisLoader.onError);
  785. }
  786. else {
  787. var fileObj = MiniFileMgr.getFileInfo(Laya.URL.formatURL(url));
  788. if (fileObj) {
  789. fileObj.encoding = fileObj.encoding == null ? "utf8" : fileObj.encoding;
  790. MiniFileMgr.readFile(fileObj.url, encoding, new Laya.Handler(MiniLoader, MiniLoader.onReadNativeCallBack, [url, contentType, thisLoader]), url);
  791. }
  792. else if (thisLoader.type == "image" || thisLoader.type == "htmlimage") {
  793. thisLoader._transformUrl(url, contentType);
  794. }
  795. else {
  796. if (contentType != Laya.Loader.IMAGE && ((tempurl.indexOf("http://") == -1 && tempurl.indexOf("https://") == -1) || MiniFileMgr.isLocalNativeFile(url))) {
  797. MiniFileMgr.readFile(url, encoding, new Laya.Handler(MiniLoader, MiniLoader.onReadNativeCallBack, [url, contentType, thisLoader]), url);
  798. }
  799. else {
  800. MiniFileMgr.downFiles(tempurl, encoding, new Laya.Handler(MiniLoader, MiniLoader.onReadNativeCallBack, [url, contentType, thisLoader]), tempurl, true);
  801. }
  802. }
  803. }
  804. }
  805. }
  806. static onReadNativeCallBack(url, type = null, thisLoader = null, errorCode = 0, data = null) {
  807. if (!errorCode) {
  808. var tempData;
  809. if (type == Laya.Loader.JSON || type == Laya.Loader.ATLAS || type == Laya.Loader.PREFAB || type == Laya.Loader.PLF) {
  810. tempData = BMiniAdapter.getJson(data.data);
  811. }
  812. else if (type == Laya.Loader.XML) {
  813. tempData = Laya.Utils.parseXMLFromString(data.data);
  814. }
  815. else {
  816. tempData = data.data;
  817. }
  818. if (!BMiniAdapter.isZiYu && BMiniAdapter.isPosMsgYu && type != Laya.Loader.BUFFER && BMiniAdapter.window.swan) {
  819. BMiniAdapter.window.swan.postMessage({ url: url, data: tempData, isLoad: "filedata" });
  820. }
  821. thisLoader.onLoaded(tempData);
  822. }
  823. else if (errorCode == 1) {
  824. thisLoader._loadHttpRequest(url, type, thisLoader, thisLoader.onLoaded, thisLoader, thisLoader.onProgress, thisLoader, thisLoader.onError);
  825. }
  826. }
  827. static _transformImgUrl(url, type, thisLoader) {
  828. if (BMiniAdapter.isZiYu) {
  829. thisLoader._loadImage(url);
  830. return;
  831. }
  832. if (!MiniFileMgr.getFileInfo(url)) {
  833. var tempUrl = Laya.URL.formatURL(url);
  834. if (url.indexOf(BMiniAdapter.window.swan.env.USER_DATA_PATH) == -1 && (tempUrl.indexOf("http://") != -1 || tempUrl.indexOf("https://") != -1)) {
  835. if (BMiniAdapter.isZiYu) {
  836. thisLoader._loadImage(url);
  837. }
  838. else {
  839. MiniFileMgr.downOtherFiles(tempUrl, new Laya.Handler(MiniLoader, MiniLoader.onDownImgCallBack, [url, thisLoader]), tempUrl);
  840. }
  841. }
  842. else
  843. thisLoader._loadImage(url);
  844. }
  845. else {
  846. thisLoader._loadImage(url);
  847. }
  848. }
  849. static onDownImgCallBack(sourceUrl, thisLoader, errorCode, tempFilePath = "") {
  850. if (!errorCode)
  851. MiniLoader.onCreateImage(sourceUrl, thisLoader, false, tempFilePath);
  852. else {
  853. thisLoader.onError(null);
  854. }
  855. }
  856. static onCreateImage(sourceUrl, thisLoader, isLocal = false, tempFilePath = "") {
  857. var fileNativeUrl;
  858. if (BMiniAdapter.autoCacheFile) {
  859. if (!isLocal) {
  860. if (tempFilePath != "") {
  861. fileNativeUrl = tempFilePath;
  862. }
  863. else {
  864. var fileObj = MiniFileMgr.getFileInfo(sourceUrl);
  865. var fileMd5Name = fileObj.md5;
  866. fileNativeUrl = MiniFileMgr.getFileNativePath(fileMd5Name);
  867. }
  868. }
  869. else if (BMiniAdapter.isZiYu) {
  870. var tempUrl = Laya.URL.formatURL(sourceUrl);
  871. if (MiniFileMgr.ziyuFileTextureData[tempUrl]) {
  872. fileNativeUrl = MiniFileMgr.ziyuFileTextureData[tempUrl];
  873. }
  874. else
  875. fileNativeUrl = sourceUrl;
  876. }
  877. else
  878. fileNativeUrl = sourceUrl;
  879. }
  880. else {
  881. if (!isLocal)
  882. fileNativeUrl = tempFilePath;
  883. else
  884. fileNativeUrl = sourceUrl;
  885. }
  886. thisLoader._loadImage(fileNativeUrl);
  887. }
  888. }
  889. class MiniLocalStorage {
  890. constructor() {
  891. }
  892. static __init__() {
  893. MiniLocalStorage.items = MiniLocalStorage;
  894. }
  895. static setItem(key, value) {
  896. try {
  897. BMiniAdapter.window.swan.setStorageSync(key, value);
  898. }
  899. catch (error) {
  900. BMiniAdapter.window.swan.setStorage({
  901. key: key,
  902. data: value
  903. });
  904. }
  905. }
  906. static getItem(key) {
  907. return BMiniAdapter.window.swan.getStorageSync(key);
  908. }
  909. static setJSON(key, value) {
  910. MiniLocalStorage.setItem(key, value);
  911. }
  912. static getJSON(key) {
  913. return MiniLocalStorage.getItem(key);
  914. }
  915. static removeItem(key) {
  916. BMiniAdapter.window.swan.removeStorageSync(key);
  917. }
  918. static clear() {
  919. BMiniAdapter.window.swan.clearStorageSync();
  920. }
  921. static getStorageInfoSync() {
  922. try {
  923. var res = BMiniAdapter.window.swan.getStorageInfoSync();
  924. console.log(res.keys);
  925. console.log(res.currentSize);
  926. console.log(res.limitSize);
  927. return res;
  928. }
  929. catch (e) {
  930. }
  931. return null;
  932. }
  933. }
  934. MiniLocalStorage.support = true;
  935. class BMiniAdapter {
  936. static getJson(data) {
  937. return JSON.parse(data);
  938. }
  939. static enable() {
  940. BMiniAdapter.init(Laya.Laya.isWXPosMsg, Laya.Laya.isWXOpenDataContext);
  941. }
  942. static init(isPosMsg = false, isSon = false) {
  943. if (BMiniAdapter._inited)
  944. return;
  945. BMiniAdapter._inited = true;
  946. BMiniAdapter.window = window;
  947. if (!BMiniAdapter.window.hasOwnProperty("swan"))
  948. return;
  949. if (BMiniAdapter.window.navigator.userAgent.indexOf('SwanGame') < 0)
  950. return;
  951. BMiniAdapter.isZiYu = isSon;
  952. BMiniAdapter.isPosMsgYu = isPosMsg;
  953. BMiniAdapter.EnvConfig = {};
  954. if (!BMiniAdapter.isZiYu) {
  955. MiniFileMgr.setNativeFileDir("/layaairGame");
  956. MiniFileMgr.existDir(MiniFileMgr.fileNativeDir, Laya.Handler.create(BMiniAdapter, BMiniAdapter.onMkdirCallBack));
  957. }
  958. BMiniAdapter.systemInfo = BMiniAdapter.window.swan.getSystemInfoSync();
  959. BMiniAdapter.window.focus = function () {
  960. };
  961. Laya.Laya['_getUrlPath'] = function () {
  962. return "";
  963. };
  964. BMiniAdapter.window.logtime = function (str) {
  965. };
  966. BMiniAdapter.window.alertTimeLog = function (str) {
  967. };
  968. BMiniAdapter.window.resetShareInfo = function () {
  969. };
  970. BMiniAdapter.window.CanvasRenderingContext2D = function () {
  971. };
  972. BMiniAdapter.window.CanvasRenderingContext2D.prototype = BMiniAdapter.window.swan.createCanvas().getContext('2d').__proto__;
  973. BMiniAdapter.window.document.body.appendChild = function () {
  974. };
  975. BMiniAdapter.EnvConfig.pixelRatioInt = 0;
  976. Laya.Browser["_pixelRatio"] = BMiniAdapter.pixelRatio();
  977. BMiniAdapter._preCreateElement = Laya.Browser.createElement;
  978. Laya.Browser["createElement"] = BMiniAdapter.createElement;
  979. Laya.RunDriver.createShaderCondition = BMiniAdapter.createShaderCondition;
  980. Laya.Utils['parseXMLFromString'] = BMiniAdapter.parseXMLFromString;
  981. Laya.Input['_createInputElement'] = MiniInput['_createInputElement'];
  982. Laya.Loader.prototype._loadResourceFilter = MiniLoader.prototype._loadResourceFilter;
  983. Laya.Loader.prototype._loadSound = MiniLoader.prototype._loadSound;
  984. Laya.Loader.prototype._loadHttpRequestWhat = MiniLoader.prototype._loadHttpRequestWhat;
  985. Laya.LocalStorage._baseClass = MiniLocalStorage;
  986. MiniLocalStorage.__init__();
  987. BMiniAdapter.window.swan.onMessage && BMiniAdapter.window.swan.onMessage(BMiniAdapter._onMessage);
  988. }
  989. static _onMessage(data) {
  990. switch (data.type) {
  991. case "changeMatrix":
  992. Laya.Laya.stage.transform.identity();
  993. Laya.Laya.stage._width = data.w;
  994. Laya.Laya.stage._height = data.h;
  995. Laya.Laya.stage._canvasTransform = new Laya.Matrix(data.a, data.b, data.c, data.d, data.tx, data.ty);
  996. break;
  997. case "display":
  998. Laya.Laya.stage.frameRate = data.rate || Laya.Stage.FRAME_FAST;
  999. break;
  1000. case "undisplay":
  1001. Laya.Laya.stage.frameRate = Laya.Stage.FRAME_SLEEP;
  1002. break;
  1003. }
  1004. if (data['isLoad'] == "opendatacontext") {
  1005. if (data.url) {
  1006. MiniFileMgr.ziyuFileData[data.url] = data.atlasdata;
  1007. MiniFileMgr.ziyuFileTextureData[data.imgReadyUrl] = data.imgNativeUrl;
  1008. }
  1009. }
  1010. else if (data['isLoad'] == "openJsondatacontext") {
  1011. if (data.url) {
  1012. MiniFileMgr.ziyuFileData[data.url] = data.atlasdata;
  1013. }
  1014. }
  1015. else if (data['isLoad'] == "openJsondatacontextPic") {
  1016. MiniFileMgr.ziyuFileTextureData[data.imgReadyUrl] = data.imgNativeUrl;
  1017. }
  1018. }
  1019. static getUrlEncode(url, type) {
  1020. if (type == "arraybuffer")
  1021. return "";
  1022. return "utf8";
  1023. }
  1024. static downLoadFile(fileUrl, fileType = "", callBack = null, encoding = "utf8") {
  1025. var fileObj = MiniFileMgr.getFileInfo(fileUrl);
  1026. if (!fileObj)
  1027. MiniFileMgr.downLoadFile(fileUrl, fileType, callBack, encoding);
  1028. else {
  1029. callBack != null && callBack.runWith([0]);
  1030. }
  1031. }
  1032. static remove(fileUrl, callBack = null) {
  1033. MiniFileMgr.deleteFile("", fileUrl, callBack, "", 0);
  1034. }
  1035. static removeAll() {
  1036. MiniFileMgr.deleteAll();
  1037. }
  1038. static hasNativeFile(fileUrl) {
  1039. return MiniFileMgr.isLocalNativeFile(fileUrl);
  1040. }
  1041. static getFileInfo(fileUrl) {
  1042. return MiniFileMgr.getFileInfo(fileUrl);
  1043. }
  1044. static getFileList() {
  1045. return MiniFileMgr.filesListObj;
  1046. }
  1047. static onMkdirCallBack(errorCode, data) {
  1048. if (!errorCode)
  1049. MiniFileMgr.filesListObj = JSON.parse(data.data);
  1050. MiniFileMgr.fakeObj = MiniFileMgr.filesListObj;
  1051. }
  1052. static pixelRatio() {
  1053. if (!BMiniAdapter.EnvConfig.pixelRatioInt) {
  1054. try {
  1055. BMiniAdapter.EnvConfig.pixelRatioInt = BMiniAdapter.systemInfo.pixelRatio;
  1056. return BMiniAdapter.systemInfo.pixelRatio;
  1057. }
  1058. catch (error) {
  1059. }
  1060. }
  1061. return BMiniAdapter.EnvConfig.pixelRatioInt;
  1062. }
  1063. static createElement(type) {
  1064. if (type == "canvas") {
  1065. var _source;
  1066. if (BMiniAdapter.idx == 1) {
  1067. if (BMiniAdapter.isZiYu) {
  1068. _source = BMiniAdapter.window.sharedCanvas;
  1069. _source.style = {};
  1070. }
  1071. else {
  1072. _source = BMiniAdapter.window.canvas;
  1073. }
  1074. }
  1075. else {
  1076. _source = BMiniAdapter.window.swan.createCanvas();
  1077. }
  1078. BMiniAdapter.idx++;
  1079. return _source;
  1080. }
  1081. else if (type == "textarea" || type == "input") {
  1082. return BMiniAdapter.onCreateInput(type);
  1083. }
  1084. else if (type == "div") {
  1085. var node = BMiniAdapter._preCreateElement(type);
  1086. node.contains = function (value) {
  1087. return null;
  1088. };
  1089. node.removeChild = function (value) {
  1090. };
  1091. return node;
  1092. }
  1093. else {
  1094. return BMiniAdapter._preCreateElement(type);
  1095. }
  1096. }
  1097. static onCreateInput(type) {
  1098. var node = BMiniAdapter._preCreateElement(type);
  1099. node.focus = MiniInput.wxinputFocus;
  1100. node.blur = MiniInput.wxinputblur;
  1101. node.style = {};
  1102. node.value = 0;
  1103. if (!node.parentElement)
  1104. node.parentElement = {};
  1105. node.placeholder = {};
  1106. node.type = {};
  1107. node.setColor = function (value) {
  1108. };
  1109. node.setType = function (value) {
  1110. };
  1111. node.setFontFace = function (value) {
  1112. };
  1113. node.addEventListener = function (value) {
  1114. };
  1115. node.contains = function (value) {
  1116. return null;
  1117. };
  1118. node.removeChild = function (value) {
  1119. };
  1120. return node;
  1121. }
  1122. static createShaderCondition(conditionScript) {
  1123. var func = function () {
  1124. return this[conditionScript.replace("this.", "")];
  1125. };
  1126. return func;
  1127. }
  1128. static sendAtlasToOpenDataContext(url) {
  1129. if (!BMiniAdapter.isZiYu) {
  1130. var atlasJson = Laya.Loader.getRes(Laya.URL.formatURL(url));
  1131. if (atlasJson) {
  1132. var textureArr = atlasJson.meta.image.split(",");
  1133. if (atlasJson.meta && atlasJson.meta.image) {
  1134. var toloadPics = atlasJson.meta.image.split(",");
  1135. var split = url.indexOf("/") >= 0 ? "/" : "\\";
  1136. var idx = url.lastIndexOf(split);
  1137. var folderPath = idx >= 0 ? url.substr(0, idx + 1) : "";
  1138. for (var i = 0, len = toloadPics.length; i < len; i++) {
  1139. toloadPics[i] = folderPath + toloadPics[i];
  1140. }
  1141. }
  1142. else {
  1143. toloadPics = [url.replace(".json", ".png")];
  1144. }
  1145. for (i = 0; i < toloadPics.length; i++) {
  1146. var tempAtlasPngUrl = toloadPics[i];
  1147. BMiniAdapter.postInfoToContext(url, tempAtlasPngUrl, atlasJson);
  1148. }
  1149. }
  1150. else {
  1151. throw "传递的url没有获取到对应的图集数据信息,请确保图集已经过!";
  1152. }
  1153. }
  1154. }
  1155. static postInfoToContext(url, atlaspngUrl, atlasJson) {
  1156. var postData = { "frames": atlasJson.frames, "meta": atlasJson.meta };
  1157. var textureUrl = atlaspngUrl;
  1158. var fileObj = MiniFileMgr.getFileInfo(Laya.URL.formatURL(atlaspngUrl));
  1159. if (fileObj) {
  1160. var fileMd5Name = fileObj.md5;
  1161. var fileNativeUrl = MiniFileMgr.getFileNativePath(fileMd5Name);
  1162. }
  1163. else {
  1164. fileNativeUrl = textureUrl;
  1165. }
  1166. if (fileNativeUrl) {
  1167. BMiniAdapter.window.swan.postMessage({ url: url, atlasdata: postData, imgNativeUrl: fileNativeUrl, imgReadyUrl: textureUrl, isLoad: "opendatacontext" });
  1168. }
  1169. else {
  1170. throw "获取图集的磁盘url路径不存在!";
  1171. }
  1172. }
  1173. static sendSinglePicToOpenDataContext(url) {
  1174. var tempTextureUrl = Laya.URL.formatURL(url);
  1175. var fileObj = MiniFileMgr.getFileInfo(tempTextureUrl);
  1176. if (fileObj) {
  1177. var fileMd5Name = fileObj.md5;
  1178. var fileNativeUrl = MiniFileMgr.getFileNativePath(fileMd5Name);
  1179. url = tempTextureUrl;
  1180. }
  1181. else {
  1182. fileNativeUrl = url;
  1183. }
  1184. if (fileNativeUrl) {
  1185. BMiniAdapter.window.swan.postMessage({ url: url, imgNativeUrl: fileNativeUrl, imgReadyUrl: url, isLoad: "openJsondatacontextPic" });
  1186. }
  1187. else {
  1188. throw "获取图集的磁盘url路径不存在!";
  1189. }
  1190. }
  1191. static sendJsonDataToDataContext(url) {
  1192. if (!BMiniAdapter.isZiYu) {
  1193. var atlasJson = Laya.Loader.getRes(url);
  1194. if (atlasJson) {
  1195. BMiniAdapter.window.swan.postMessage({ url: url, atlasdata: atlasJson, isLoad: "openJsondatacontext" });
  1196. }
  1197. else {
  1198. throw "传递的url没有获取到对应的图集数据信息,请确保图集已经过!";
  1199. }
  1200. }
  1201. }
  1202. }
  1203. BMiniAdapter._inited = false;
  1204. BMiniAdapter.autoCacheFile = true;
  1205. BMiniAdapter.minClearSize = (5 * 1024 * 1024);
  1206. BMiniAdapter.nativefiles = ["layaNativeDir", "wxlocal"];
  1207. BMiniAdapter.subNativeFiles = [];
  1208. BMiniAdapter.subNativeheads = [];
  1209. BMiniAdapter.subMaps = [];
  1210. BMiniAdapter.AutoCacheDownFile = false;
  1211. BMiniAdapter.parseXMLFromString = function (value) {
  1212. var rst;
  1213. value = value.replace(/>\s+</g, '><');
  1214. try {
  1215. rst = (new BMiniAdapter.window.Parser.DOMParser()).parseFromString(value, 'text/xml');
  1216. }
  1217. catch (error) {
  1218. throw "需要引入xml解析库文件";
  1219. }
  1220. return rst;
  1221. };
  1222. BMiniAdapter.idx = 1;
  1223. class MiniAccelerator extends Laya.EventDispatcher {
  1224. constructor() {
  1225. super();
  1226. }
  1227. static __init__() {
  1228. try {
  1229. var Acc;
  1230. Acc = Laya.Accelerator;
  1231. if (!Acc)
  1232. return;
  1233. Acc["prototype"]["on"] = MiniAccelerator["prototype"]["on"];
  1234. Acc["prototype"]["off"] = MiniAccelerator["prototype"]["off"];
  1235. }
  1236. catch (e) {
  1237. }
  1238. }
  1239. static startListen(callBack) {
  1240. MiniAccelerator._callBack = callBack;
  1241. if (MiniAccelerator._isListening)
  1242. return;
  1243. MiniAccelerator._isListening = true;
  1244. try {
  1245. BMiniAdapter.window.swan.onAccelerometerChange(MiniAccelerator.onAccelerometerChange);
  1246. }
  1247. catch (e) { }
  1248. }
  1249. static stopListen() {
  1250. MiniAccelerator._isListening = false;
  1251. try {
  1252. BMiniAdapter.window.swan.stopAccelerometer({});
  1253. }
  1254. catch (e) { }
  1255. }
  1256. static onAccelerometerChange(res) {
  1257. var e;
  1258. e = {};
  1259. e.acceleration = res;
  1260. e.accelerationIncludingGravity = res;
  1261. e.rotationRate = {};
  1262. if (MiniAccelerator._callBack != null) {
  1263. MiniAccelerator._callBack(e);
  1264. }
  1265. }
  1266. on(type, caller, listener, args = null) {
  1267. super.on(type, caller, listener, args);
  1268. MiniAccelerator.startListen(this["onDeviceOrientationChange"]);
  1269. return this;
  1270. }
  1271. off(type, caller, listener, onceOnly = false) {
  1272. if (!this.hasListener(type))
  1273. MiniAccelerator.stopListen();
  1274. return super.off(type, caller, listener, onceOnly);
  1275. }
  1276. }
  1277. MiniAccelerator._isListening = false;
  1278. class MiniImage {
  1279. _loadImage(url) {
  1280. var thisLoader = this;
  1281. if (BMiniAdapter.isZiYu) {
  1282. MiniImage.onCreateImage(url, thisLoader, true);
  1283. return;
  1284. }
  1285. var isTransformUrl;
  1286. if (!MiniFileMgr.isLocalNativeFile(url)) {
  1287. isTransformUrl = true;
  1288. url = Laya.URL.formatURL(url);
  1289. }
  1290. else {
  1291. if (url.indexOf("http://usr/") == -1 && (url.indexOf("http://") != -1 || url.indexOf("https://") != -1)) {
  1292. if (MiniFileMgr.loadPath != "") {
  1293. url = url.split(MiniFileMgr.loadPath)[1];
  1294. }
  1295. else {
  1296. var tempStr = Laya.URL.rootPath != "" ? Laya.URL.rootPath : Laya.URL._basePath;
  1297. var tempUrl = url;
  1298. if (tempStr != "")
  1299. url = url.split(tempStr)[1];
  1300. if (!url) {
  1301. url = tempUrl;
  1302. }
  1303. }
  1304. }
  1305. if (BMiniAdapter.subNativeFiles && BMiniAdapter.subNativeheads.length == 0) {
  1306. for (var key in BMiniAdapter.subNativeFiles) {
  1307. var tempArr = BMiniAdapter.subNativeFiles[key];
  1308. BMiniAdapter.subNativeheads = BMiniAdapter.subNativeheads.concat(tempArr);
  1309. for (var aa = 0; aa < tempArr.length; aa++) {
  1310. BMiniAdapter.subMaps[tempArr[aa]] = key + "/" + tempArr[aa];
  1311. }
  1312. }
  1313. }
  1314. if (BMiniAdapter.subNativeFiles && url.indexOf("/") != -1) {
  1315. var curfileHead = url.split("/")[0] + "/";
  1316. if (curfileHead && BMiniAdapter.subNativeheads.indexOf(curfileHead) != -1) {
  1317. var newfileHead = BMiniAdapter.subMaps[curfileHead];
  1318. url = url.replace(curfileHead, newfileHead);
  1319. }
  1320. }
  1321. }
  1322. if (!MiniFileMgr.getFileInfo(url)) {
  1323. if (url.indexOf('http://usr/') == -1 && (url.indexOf("http://") != -1 || url.indexOf("https://") != -1)) {
  1324. if (BMiniAdapter.isZiYu) {
  1325. MiniImage.onCreateImage(url, thisLoader, true);
  1326. }
  1327. else {
  1328. MiniFileMgr.downOtherFiles(url, new Laya.Handler(MiniImage, MiniImage.onDownImgCallBack, [url, thisLoader]), url);
  1329. }
  1330. }
  1331. else
  1332. MiniImage.onCreateImage(url, thisLoader, true);
  1333. }
  1334. else {
  1335. MiniImage.onCreateImage(url, thisLoader, !isTransformUrl);
  1336. }
  1337. }
  1338. static onDownImgCallBack(sourceUrl, thisLoader, errorCode, tempFilePath = "") {
  1339. if (!errorCode)
  1340. MiniImage.onCreateImage(sourceUrl, thisLoader, false, tempFilePath);
  1341. else {
  1342. thisLoader.onError(null);
  1343. }
  1344. }
  1345. static onCreateImage(sourceUrl, thisLoader, isLocal = false, tempFilePath = "") {
  1346. var fileNativeUrl;
  1347. if (BMiniAdapter.autoCacheFile) {
  1348. if (!isLocal) {
  1349. if (tempFilePath != "") {
  1350. fileNativeUrl = tempFilePath;
  1351. }
  1352. else {
  1353. var fileObj = MiniFileMgr.getFileInfo(sourceUrl);
  1354. var fileMd5Name = fileObj.md5;
  1355. fileNativeUrl = MiniFileMgr.getFileNativePath(fileMd5Name);
  1356. }
  1357. }
  1358. else if (BMiniAdapter.isZiYu) {
  1359. var tempUrl = Laya.URL.formatURL(sourceUrl);
  1360. if (MiniFileMgr.ziyuFileTextureData[tempUrl]) {
  1361. fileNativeUrl = MiniFileMgr.ziyuFileTextureData[tempUrl];
  1362. }
  1363. else
  1364. fileNativeUrl = sourceUrl;
  1365. }
  1366. else
  1367. fileNativeUrl = sourceUrl;
  1368. }
  1369. else {
  1370. if (!isLocal)
  1371. fileNativeUrl = tempFilePath;
  1372. else
  1373. fileNativeUrl = sourceUrl;
  1374. }
  1375. if (thisLoader._imgCache == null)
  1376. thisLoader._imgCache = {};
  1377. var image;
  1378. function clear() {
  1379. var img = thisLoader._imgCache[fileNativeUrl];
  1380. if (img) {
  1381. img.onload = null;
  1382. img.onerror = null;
  1383. delete thisLoader._imgCache[fileNativeUrl];
  1384. }
  1385. }
  1386. var onerror = function () {
  1387. clear();
  1388. delete MiniFileMgr.fakeObj[sourceUrl];
  1389. delete MiniFileMgr.filesListObj[sourceUrl];
  1390. thisLoader.event(Laya.Event.ERROR, "Load image failed");
  1391. };
  1392. if (thisLoader._type == "nativeimage") {
  1393. var onload = function () {
  1394. clear();
  1395. thisLoader.onLoaded(image);
  1396. };
  1397. image = new Laya.Browser.window.Image();
  1398. image.crossOrigin = "";
  1399. image.onload = onload;
  1400. image.onerror = onerror;
  1401. image.src = fileNativeUrl;
  1402. thisLoader._imgCache[fileNativeUrl] = image;
  1403. }
  1404. else {
  1405. var imageSource = new Laya.Browser.window.Image();
  1406. onload = function () {
  1407. image = Laya.HTMLImage.create(imageSource.width, imageSource.height);
  1408. image.loadImageSource(imageSource, true);
  1409. image._setCreateURL(fileNativeUrl);
  1410. clear();
  1411. thisLoader.onLoaded(image);
  1412. };
  1413. imageSource.crossOrigin = "";
  1414. imageSource.onload = onload;
  1415. imageSource.onerror = onerror;
  1416. imageSource.src = fileNativeUrl;
  1417. thisLoader._imgCache[fileNativeUrl] = imageSource;
  1418. }
  1419. }
  1420. }
  1421. class MiniLocation {
  1422. constructor() {
  1423. }
  1424. static __init__() {
  1425. BMiniAdapter.window.navigator.geolocation.getCurrentPosition = MiniLocation.getCurrentPosition;
  1426. BMiniAdapter.window.navigator.geolocation.watchPosition = MiniLocation.watchPosition;
  1427. BMiniAdapter.window.navigator.geolocation.clearWatch = MiniLocation.clearWatch;
  1428. }
  1429. static getCurrentPosition(success = null, error = null, options = null) {
  1430. var paramO;
  1431. paramO = {};
  1432. paramO.success = getSuccess;
  1433. paramO.fail = error;
  1434. BMiniAdapter.window.swan.getLocation(paramO);
  1435. function getSuccess(res) {
  1436. if (success != null) {
  1437. success(res);
  1438. }
  1439. }
  1440. }
  1441. static watchPosition(success = null, error = null, options = null) {
  1442. MiniLocation._curID++;
  1443. var curWatchO;
  1444. curWatchO = {};
  1445. curWatchO.success = success;
  1446. curWatchO.error = error;
  1447. MiniLocation._watchDic[MiniLocation._curID] = curWatchO;
  1448. Laya.Laya.systemTimer.loop(1000, null, MiniLocation._myLoop);
  1449. return MiniLocation._curID;
  1450. }
  1451. static clearWatch(id) {
  1452. delete MiniLocation._watchDic[id];
  1453. if (!MiniLocation._hasWatch()) {
  1454. Laya.Laya.systemTimer.clear(null, MiniLocation._myLoop);
  1455. }
  1456. }
  1457. static _hasWatch() {
  1458. var key;
  1459. for (key in MiniLocation._watchDic) {
  1460. if (MiniLocation._watchDic[key])
  1461. return true;
  1462. }
  1463. return false;
  1464. }
  1465. static _myLoop() {
  1466. MiniLocation.getCurrentPosition(MiniLocation._mySuccess, MiniLocation._myError);
  1467. }
  1468. static _mySuccess(res) {
  1469. var rst = {};
  1470. rst.coords = res;
  1471. rst.timestamp = Laya.Browser.now();
  1472. var key;
  1473. for (key in MiniLocation._watchDic) {
  1474. if (MiniLocation._watchDic[key].success) {
  1475. MiniLocation._watchDic[key].success(rst);
  1476. }
  1477. }
  1478. }
  1479. static _myError(res) {
  1480. var key;
  1481. for (key in MiniLocation._watchDic) {
  1482. if (MiniLocation._watchDic[key].error) {
  1483. MiniLocation._watchDic[key].error(res);
  1484. }
  1485. }
  1486. }
  1487. }
  1488. MiniLocation._watchDic = {};
  1489. MiniLocation._curID = 0;
  1490. class MiniVideo {
  1491. constructor(width = 320, height = 240) {
  1492. this.videoend = false;
  1493. this.videourl = "";
  1494. this.videoElement = BMiniAdapter.window.swan.createVideo({ width: width, height: height, autoplay: true });
  1495. }
  1496. static __init__() {
  1497. }
  1498. on(eventType, ths, callBack) {
  1499. if (eventType == "loadedmetadata") {
  1500. this.onPlayFunc = callBack.bind(ths);
  1501. this.videoElement.onPlay = this.onPlayFunction.bind(this);
  1502. }
  1503. else if (eventType == "ended") {
  1504. this.onEndedFunC = callBack.bind(ths);
  1505. this.videoElement.onEnded = this.onEndedFunction.bind(this);
  1506. }
  1507. this.videoElement.onTimeUpdate = this.onTimeUpdateFunc.bind(this);
  1508. }
  1509. onTimeUpdateFunc(data) {
  1510. this.position = data.position;
  1511. this._duration = data.duration;
  1512. }
  1513. get duration() {
  1514. return this._duration;
  1515. }
  1516. onPlayFunction() {
  1517. if (this.videoElement)
  1518. this.videoElement.readyState = 200;
  1519. console.log("=====视频加载完成========");
  1520. this.onPlayFunc != null && this.onPlayFunc();
  1521. }
  1522. onEndedFunction() {
  1523. if (!this.videoElement)
  1524. return;
  1525. this.videoend = true;
  1526. console.log("=====视频播放完毕========");
  1527. this.onEndedFunC != null && this.onEndedFunC();
  1528. }
  1529. off(eventType, ths, callBack) {
  1530. if (eventType == "loadedmetadata") {
  1531. this.onPlayFunc = callBack.bind(ths);
  1532. this.videoElement.offPlay = this.onPlayFunction.bind(this);
  1533. }
  1534. else if (eventType == "ended") {
  1535. this.onEndedFunC = callBack.bind(ths);
  1536. this.videoElement.offEnded = this.onEndedFunction.bind(this);
  1537. }
  1538. }
  1539. load(url) {
  1540. if (!this.videoElement)
  1541. return;
  1542. this.videoElement.src = url;
  1543. }
  1544. play() {
  1545. if (!this.videoElement)
  1546. return;
  1547. this.videoend = false;
  1548. this.videoElement.play();
  1549. }
  1550. pause() {
  1551. if (!this.videoElement)
  1552. return;
  1553. this.videoend = true;
  1554. this.videoElement.pause();
  1555. }
  1556. get currentTime() {
  1557. if (!this.videoElement)
  1558. return 0;
  1559. return this.videoElement.initialTime;
  1560. }
  1561. set currentTime(value) {
  1562. if (!this.videoElement)
  1563. return;
  1564. this.videoElement.initialTime = value;
  1565. }
  1566. get videoWidth() {
  1567. if (!this.videoElement)
  1568. return 0;
  1569. return this.videoElement.width;
  1570. }
  1571. get videoHeight() {
  1572. if (!this.videoElement)
  1573. return 0;
  1574. return this.videoElement.height;
  1575. }
  1576. get ended() {
  1577. return this.videoend;
  1578. }
  1579. get loop() {
  1580. if (!this.videoElement)
  1581. return false;
  1582. return this.videoElement.loop;
  1583. }
  1584. set loop(value) {
  1585. if (!this.videoElement)
  1586. return;
  1587. this.videoElement.loop = value;
  1588. }
  1589. get playbackRate() {
  1590. if (!this.videoElement)
  1591. return 0;
  1592. return this.videoElement.playbackRate;
  1593. }
  1594. set playbackRate(value) {
  1595. if (!this.videoElement)
  1596. return;
  1597. this.videoElement.playbackRate = value;
  1598. }
  1599. get muted() {
  1600. if (!this.videoElement)
  1601. return false;
  1602. return this.videoElement.muted;
  1603. }
  1604. set muted(value) {
  1605. if (!this.videoElement)
  1606. return;
  1607. this.videoElement.muted = value;
  1608. }
  1609. get paused() {
  1610. if (!this.videoElement)
  1611. return false;
  1612. return this.videoElement.paused;
  1613. }
  1614. size(width, height) {
  1615. if (!this.videoElement)
  1616. return;
  1617. this.videoElement.width = width;
  1618. this.videoElement.height = height;
  1619. }
  1620. get x() {
  1621. if (!this.videoElement)
  1622. return 0;
  1623. return this.videoElement.x;
  1624. }
  1625. set x(value) {
  1626. if (!this.videoElement)
  1627. return;
  1628. this.videoElement.x = value;
  1629. }
  1630. get y() {
  1631. if (!this.videoElement)
  1632. return 0;
  1633. return this.videoElement.y;
  1634. }
  1635. set y(value) {
  1636. if (!this.videoElement)
  1637. return;
  1638. this.videoElement.y = value;
  1639. }
  1640. get currentSrc() {
  1641. return this.videoElement.src;
  1642. }
  1643. destroy() {
  1644. if (this.videoElement)
  1645. this.videoElement.destroy();
  1646. this.videoElement = null;
  1647. this.onEndedFunC = null;
  1648. this.onPlayFunc = null;
  1649. this.videoend = false;
  1650. this.videourl = null;
  1651. }
  1652. reload() {
  1653. if (!this.videoElement)
  1654. return;
  1655. this.videoElement.src = this.videourl;
  1656. }
  1657. }
  1658. exports.BMiniAdapter = BMiniAdapter;
  1659. exports.MiniAccelerator = MiniAccelerator;
  1660. exports.MiniFileMgr = MiniFileMgr;
  1661. exports.MiniImage = MiniImage;
  1662. exports.MiniInput = MiniInput;
  1663. exports.MiniLoader = MiniLoader;
  1664. exports.MiniLocalStorage = MiniLocalStorage;
  1665. exports.MiniLocation = MiniLocation;
  1666. exports.MiniSound = MiniSound;
  1667. exports.MiniSoundChannel = MiniSoundChannel;
  1668. exports.MiniVideo = MiniVideo;
  1669. }