laya.vvmini.js 66 KB

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