laya.vvmini.js 65 KB

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