laya.qqmini.js 66 KB

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