laya.vvmini.js 65 KB

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