laya.qqmini.js 66 KB

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