ThirdParty.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739
  1. //ThirdParty.js
  2. //回调相关
  3. function CallLoginFunc(func, para) {
  4. if (window.LOG_NET_DATA) console.log("CallLoginFunc ", func, " : ", para)
  5. if (g_Login) {
  6. if (g_Login[func]) g_Login[func](para);
  7. } else {
  8. if (window.LOG_NET_DATA) console.log("g_Login is null");
  9. }
  10. }
  11. function CallLobbyFunc(func, para) {
  12. if (window.LOG_NET_DATA) console.log("CallLobbyFunc ", func, " : ", para)
  13. if (g_Lobby != null) {
  14. if (g_Lobby[func]) g_Lobby[func](para);
  15. }
  16. }
  17. function CallTableFunc(func, para) {
  18. if (window.LOG_NET_DATA) console.log("CallTableFunc ", func, " : ", para)
  19. if (g_Table != null) {
  20. if (g_Table[func]) g_Table[func](para);
  21. }
  22. }
  23. function CallUploadSuccess() {
  24. if (g_CurScene && g_CurScene.OnUpload_Success) g_CurScene.OnUpload_Success();
  25. }
  26. function CallUploadFaild() {
  27. if (g_CurScene && g_CurScene.OnUpload_Faild) g_CurScene.OnUpload_Faild();
  28. }
  29. function CallUpdateProgress(progress) {
  30. if(g_UpdateManager) g_UpdateManager.OnUpdateProgress(progress);
  31. }
  32. //
  33. bShowEndGame = false;
  34. function CallSystemBack() {
  35. if (bShowEndGame) return
  36. bShowEndGame = true;
  37. if (g_CurScene) {
  38. g_CurScene.ShowAlert('确定退出游戏?', Alert_YesNo, function (Res) {
  39. bShowEndGame = false;
  40. if (Res) ThirdPartyExitGame();
  41. });
  42. }
  43. }
  44. function CallOpenGPS(Param) {
  45. if (g_CurScene && g_CurScene.m_bTipGPS) {
  46. g_CurScene.ShowAlert('请开启手机GPS功能,不开启GPS无法显示GPS地址!', Alert_Yes, function (Res) {
  47. //ThirdPartyGetAddress(Number(Param) == 1 ? true : false);
  48. });
  49. }
  50. }
  51. //原生功能
  52. function ThirdPartyGetBattery() {
  53. var pLv = 1;
  54. if (cc.sys.isNative) {
  55. if (cc.sys.OS_IOS == cc.sys.os) {
  56. pLv = jsb.reflection.callStaticMethod('AppController', "GetBatteryLv");
  57. } else {
  58. pLv = jsb.reflection.callStaticMethod('org/cocos2dx/javascript/AppActivity', "GetBatteryLv", "()Ljava/lang/String;");
  59. }
  60. }
  61. return pLv;
  62. }
  63. function ThirdPartyGetAddress(bInLobby) {
  64. // if (bInLobby) {
  65. // if (cc.sys.OS_IOS == cc.sys.os) {
  66. // jsb.reflection.callStaticMethod("AppController", "getAddressInLobby");
  67. // } else {
  68. // jsb.reflection.callStaticMethod('org/cocos2dx/javascript/AppActivity', 'getAddressInLobby', "()V");
  69. // }
  70. // } else {
  71. // if (cc.sys.OS_IOS == cc.sys.os) {
  72. // jsb.reflection.callStaticMethod("AppController", "getAddress");
  73. // } else {
  74. // jsb.reflection.callStaticMethod('org/cocos2dx/javascript/AppActivity', 'getAddress', "()V");
  75. // }
  76. // }
  77. }
  78. function ThirdPartyOpenUrl(address) {
  79. if(cc.sys.isBrowser) {
  80. window.location.href = address;
  81. } else {
  82. if (cc.sys.OS_IOS == cc.sys.os) {
  83. jsb.reflection.callStaticMethod("AppController", "OpenUrl:", address);
  84. } else if (cc.sys.OS_ANDROID == cc.sys.os) {
  85. jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity",
  86. "OpenUrl",
  87. "(Ljava/lang/String;)V",
  88. address);
  89. }
  90. }
  91. }
  92. function ThirdPartyOpenApp(address) {
  93. if (cc.sys.OS_IOS == cc.sys.os) {
  94. jsb.reflection.callStaticMethod("AppController", "OpenApp:", address);
  95. } else if (cc.sys.OS_ANDROID == cc.sys.os) {
  96. jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity",
  97. "OpenApp",
  98. "(Ljava/lang/String;)V",
  99. address);
  100. }
  101. }
  102. function ThirdPartyCopyClipper(address) {
  103. if (cc.sys.isNative) {
  104. if (cc.sys.OS_IOS == cc.sys.os) {
  105. jsb.reflection.callStaticMethod("AppController", "CopyClipper:", address);
  106. } else if (cc.sys.OS_ANDROID == cc.sys.os) {
  107. jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity",
  108. "CopyClipper",
  109. "(Ljava/lang/String;)V",
  110. address);
  111. }
  112. } else {
  113. var input = address + '';
  114. var el = document.createElement('textarea');
  115. el.value = input;
  116. el.setAttribute('readonly', '');
  117. el.style.contain = 'strict';
  118. el.style.position = 'absolute';
  119. el.style.left = '-9999px';
  120. el.style.fontSize = '12pt'; // Prevent zooming on iOS
  121. var selection = getSelection();
  122. var originalRange = false;
  123. if (selection.rangeCount > 0) originalRange = selection.getRangeAt(0);
  124. document.body.appendChild(el);
  125. el.select();
  126. el.selectionStart = 0;
  127. el.selectionEnd = input.length;
  128. try {
  129. document.execCommand('copy');
  130. } catch (err) {}
  131. document.body.removeChild(el);
  132. if (originalRange) {
  133. selection.removeAllRanges();
  134. selection.addRange(originalRange);
  135. }
  136. }
  137. }
  138. function ThirdPartyExitGame() {
  139. if (cc.sys.isNative) {
  140. if (cc.sys.OS_IOS == cc.sys.os) {
  141. jsb.reflection.callStaticMethod("AppController", "GameClose", "()V");
  142. } else {
  143. jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "GameClose", "()V");
  144. }
  145. } else {
  146. if (cc.share.IsH5_WX()) {
  147. WeixinJSBridge.invoke('closeWindow', {}, function (res) {});
  148. }
  149. }
  150. }
  151. function ThirdPartyUpdateGame(url,apkName,ver) {
  152. if (cc.sys.OS_ANDROID == cc.sys.os) {
  153. jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "updateVerion", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V", url,apkName,ver);
  154. }
  155. }
  156. //#region google相关
  157. function ThirdPartyGoogleLogin() {
  158. if (cc.sys.isNative) {
  159. if (cc.sys.OS_IOS == cc.sys.os) {
  160. jsb.reflection.callStaticMethod("AppController", "sendGoogleLogin");
  161. } else if (cc.sys.OS_ANDROID == cc.sys.os) {
  162. jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "sendGoogleLogin", "()V");
  163. }
  164. }
  165. }
  166. //#endregion
  167. //#region line相关
  168. function ThirdPartyLINELogin() {
  169. if (cc.sys.isNative) {
  170. if (cc.sys.OS_IOS == cc.sys.os) {
  171. jsb.reflection.callStaticMethod("AppController", "sendLINELogin");
  172. } else if (cc.sys.OS_ANDROID == cc.sys.os) {
  173. jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "sendLINELogin", "()V");
  174. }
  175. }
  176. }
  177. //#endregion
  178. //#region apple相关
  179. function ThirdPartyIOSLogin() {
  180. if (cc.sys.isNative) {
  181. if (cc.sys.OS_IOS == cc.sys.os) {
  182. jsb.reflection.callStaticMethod("AppController", "sendAppleLogin");
  183. }
  184. }
  185. }
  186. //#endregion
  187. //微信相关
  188. function ThirdPartyWXLogin() {
  189. if (cc.sys.isNative) {
  190. if (cc.sys.OS_IOS == cc.sys.os) {
  191. jsb.reflection.callStaticMethod("AppController", "sendWXLogin");
  192. } else if (cc.sys.OS_ANDROID == cc.sys.os) {
  193. jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "sendWXLogin", "()V");
  194. }
  195. }
  196. }
  197. function ThirdPartyShareMessage(ShareInfo, isLine) {
  198. if (window.LOG_NET_DATA) console.log("WXShare ", isLine, " ", ShareInfo)
  199. if (cc.sys.isNative) {
  200. if (cc.sys.OS_IOS == cc.sys.os) {
  201. jsb.reflection.callStaticMethod("AppController", "WXSharetitle:description:url:IsTimeLine:", ShareInfo.title, ShareInfo.desc,
  202. ShareInfo.link, isLine);
  203. } else {
  204. jsb.reflection.callStaticMethod('org/cocos2dx/javascript/AppActivity', 'WXShare',
  205. "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V",
  206. ShareInfo.title, ShareInfo.desc,
  207. ShareInfo.link, isLine);
  208. }
  209. } else {
  210. if (cc.share.IsH5_WX()) {
  211. if (isLine == 1)
  212. wx.updateTimelineShareData(ShareInfo);
  213. else
  214. wx.updateAppMessageShareData(ShareInfo);
  215. } else {
  216. return false;
  217. }
  218. }
  219. return true
  220. }
  221. function ThirdPartyShareImg(Path, isLine) {
  222. if (window.LOG_NET_DATA) console.log("WXShareTex ", Path)
  223. isLine = isLine?isLine:'';
  224. if (cc.sys.isNative) {
  225. if (cc.sys.OS_IOS == cc.sys.os) {
  226. jsb.reflection.callStaticMethod("AppController", "WXShareTex:IsTimeLine:", Path, isLine);
  227. } else {
  228. jsb.reflection.callStaticMethod('org/cocos2dx/javascript/AppActivity', 'WXShareTex',
  229. "(Ljava/lang/String;Ljava/lang/String;)V",
  230. Path, isLine);
  231. }
  232. }
  233. }
  234. function ThirdPartyWXPay(Info) {
  235. if (window.LOG_NET_DATA) console.log("ThirdPartyWXPay " + Info)
  236. if (cc.sys.isNative) {
  237. if (cc.sys.OS_IOS == cc.sys.os) {
  238. jsb.reflection.callStaticMethod("AppController", "WXPay:", Info);
  239. } else {
  240. jsb.reflection.callStaticMethod('org/cocos2dx/javascript/AppActivity', "WXPay",
  241. "(Ljava/lang/String;)V", Info);
  242. }
  243. }
  244. }
  245. function ThirdPartyGVoiceOnRecord() {
  246. if (cc.sys.OS_IOS == cc.sys.os) {
  247. return jsb.reflection.callStaticMethod("AppController", "onRecord");
  248. } else {
  249. return jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "onRecord", "()Ljava/lang/String;");
  250. }
  251. }
  252. function ThirdPartyGVoicePlayVoice(Path) {
  253. if (cc.sys.OS_IOS == cc.sys.os) {
  254. jsb.reflection.callStaticMethod("AppController", "onPlay:", Path);
  255. } else {
  256. jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "onPlay", "(Ljava/lang/String;)V", Path);
  257. }
  258. }
  259. ///////////////////////////////////////////////////////////////////////////
  260. //全平台语音
  261. function ThirdPartyVoiceInit(Hook) {
  262. if(cc.share.IsH5_WX()) {
  263. return (typeof wx != 'undefined');
  264. } else {
  265. if (cc.sys.isNative) return true;
  266. }
  267. }
  268. //开始录制
  269. function ThirdPartyVoiceOnRecord(Hook) {
  270. if (cc.sys.isNative) {
  271. if (cc.sys.OS_IOS == cc.sys.os) {
  272. return jsb.reflection.callStaticMethod("AppController", "onRecord");
  273. } else {
  274. return jsb.reflection.callStaticMethod("org/cocos2dx/javascript/VoiceCtrl", "startRecord", "()Ljava/lang/String;");
  275. }
  276. } else {
  277. if (typeof wx == 'undefined') {
  278. } else {
  279. wx.startRecord({
  280. success: function () {
  281. Hook.ShowRecording(true);
  282. },
  283. });
  284. }
  285. return '';
  286. }
  287. }
  288. //结束录制
  289. function ThirdPartyVoiceStopRecord(Hook) {
  290. if (cc.sys.isNative) {
  291. if (cc.sys.OS_IOS == cc.sys.os) {
  292. jsb.reflection.callStaticMethod("AppController", "onStopRecord:", "()V");
  293. } else {
  294. jsb.reflection.callStaticMethod("org/cocos2dx/javascript/VoiceCtrl", "onStopRecord", "()V");
  295. }
  296. } else {
  297. if (typeof wx == 'undefined') {
  298. } else {
  299. var voice = {
  300. localId: '',
  301. serverId: '',
  302. viewID: 65535,
  303. };
  304. wx.stopRecord({
  305. success: function (res1) {
  306. voice.localId = res1.localId;
  307. wx.uploadVoice({
  308. localId: voice.localId,
  309. success: function (res2) {
  310. voice.serverId = res2.serverId;
  311. Hook.OnRecordOver(voice);
  312. }
  313. });
  314. }
  315. });
  316. }
  317. }
  318. }
  319. //上传结果
  320. function ThirdPartyVoiceOnUpload(Hook, Path) {
  321. if (cc.sys.isNative) {
  322. if (cc.sys.OS_IOS == cc.sys.os) {
  323. jsb.reflection.callStaticMethod("AppController", "onDownLoad:", VID);
  324. } else {
  325. jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "onDownLoad", "(Ljava/lang/String;)V", VID);
  326. }
  327. } else {
  328. if (typeof wx == 'undefined') {
  329. return false;
  330. } else {
  331. return true;
  332. }
  333. }
  334. }
  335. function ThirdPartyGVoiceLoadVoice(VID) {
  336. if (cc.sys.OS_IOS == cc.sys.os) {
  337. jsb.reflection.callStaticMethod("AppController", "onDownLoad:", VID);
  338. } else {
  339. jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "onDownLoad", "(Ljava/lang/String;)V", VID);
  340. }
  341. }
  342. /////////////////
  343. cc.voice = {
  344. MaxRecordTime: 59000,
  345. _startTime: 0,
  346. IsPlaying: false,
  347. IsRecording: false,
  348. _voiceH5: {},
  349. _queue: [],
  350. _ctrl: null,
  351. _engine: null,
  352. Type: cc.Enum({
  353. NULL: 0,
  354. RECORD_START: 1,
  355. RECORD_STOP: 2,
  356. PLAY: 3,
  357. PLAY_ALL_FINISH: 4
  358. }),
  359. Init: function (VoiceCtrl, GameEngine) {
  360. this._ctrl = VoiceCtrl;
  361. this._engine = GameEngine;
  362. if (cc.share.IsH5_WX()) {
  363. return (typeof wx != 'undefined');
  364. } else {
  365. if (cc.sys.isNative) return true;
  366. }
  367. },
  368. GetRecordTime: function () {
  369. if (!this._startTime) return null;
  370. return new Date().getTime() - this._startTime;
  371. },
  372. startRecord: function () {
  373. try {
  374. if (cc.share.IsH5_WX()) {
  375. if (typeof wx == 'undefined') {
  376. this._ctrl.onDispose(false, this.Type.RECORD_START);
  377. } else {
  378. wx.startRecord({
  379. success: function () {
  380. this.IsRecording = true;
  381. this._startTime = new Date().getTime();
  382. this._ctrl.onDispose(true, this.Type.RECORD_START);
  383. }.bind(this),
  384. fail: function () {
  385. this._ctrl.onDispose(false, this.Type.RECORD_START);
  386. }.bind(this),
  387. });
  388. }
  389. } else if (cc.sys.isNative) {
  390. this.IsRecording = true;
  391. this._startTime = new Date().getTime();
  392. this._ctrl.onDispose(true, this.Type.RECORD_START);
  393. if (cc.sys.OS_IOS == cc.sys.os) {
  394. jsb.reflection.callStaticMethod("AppController", "startRecord");
  395. } else {
  396. jsb.reflection.callStaticMethod("org/cocos2dx/javascript/VoiceCtrl", "startRecord", "()V");
  397. }
  398. }
  399. } catch (e) {
  400. if (window.LOG_DEBUG) console.log(e);
  401. }
  402. },
  403. stopRecord: function () {
  404. try {
  405. if (this._startTime == null) return;
  406. this.IsRecording = false;
  407. var recordTime = new Date().getTime() - this._startTime;
  408. var str = (recordTime < 1000 ? '0' : '1');
  409. this._startTime = null;
  410. if (cc.share.IsH5_WX()) {
  411. if (typeof wx == 'undefined') {
  412. return this._ctrl.onDispose(false, this.Type.RECORD_STOP);
  413. } else if (str == '0' || typeof wx == 'undefined') {
  414. wx.stopRecord({
  415. success: function () {
  416. this._ctrl.onDispose(true, this.Type.RECORD_STOP);
  417. }.bind(this)
  418. });
  419. return this._ctrl.onDispose(false, this.Type.RECORD_STOP);
  420. } else {
  421. wx.stopRecord({
  422. success: function (res1) {
  423. this._ctrl.onDispose(true, this.Type.RECORD_STOP);
  424. wx.uploadVoice({
  425. localId: res1.localId,
  426. success: function (res2) {
  427. this._voiceH5[res2.serverId] = res1.localId;
  428. this.send(1, res2.serverId);
  429. }.bind(this)
  430. });
  431. }.bind(this)
  432. });
  433. }
  434. } else if (cc.sys.isNative) {
  435. var res = '';
  436. if (cc.sys.OS_IOS == cc.sys.os) { // IOS端需要走回调完成结束
  437. res = jsb.reflection.callStaticMethod("AppController", "stopRecord:", str);
  438. this._ctrl.onDispose(true, this.Type.RECORD_STOP);
  439. } else {
  440. res = jsb.reflection.callStaticMethod("org/cocos2dx/javascript/VoiceCtrl", "stopRecord", "(Ljava/lang/String;)Ljava/lang/String;", str);
  441. if (str == '0') {
  442. return this._ctrl.onDispose(false, this.Type.RECORD_STOP);
  443. } else {
  444. this._ctrl.onDispose(true, this.Type.RECORD_STOP);
  445. this.send(0, res);
  446. }
  447. }
  448. }
  449. } catch (e) {
  450. if (window.LOG_DEBUG) console.log(e);
  451. }
  452. },
  453. onRecordFinish: function (res) { // IOS 回调
  454. if (res == '') {
  455. return this._ctrl.onDispose(false, this.Type.RECORD_STOP);
  456. }
  457. this.send(0, res);
  458. },
  459. receive: function (pVoice) {
  460. try {
  461. if (!!!this._queue) this._queue = [];
  462. // 原生
  463. if (pVoice.cbPlatform == 0) {
  464. if (!cc.share.IsH5_WX()) {
  465. if (!!!this._voice) this._voice = [];
  466. if (!!!this._voice[pVoice.dwSendUserID]) this._voice[pVoice.dwSendUserID] = '';
  467. this._voice[pVoice.dwSendUserID] += (pVoice.szVID.replace(/\n/g, ''));
  468. if (pVoice.bFinish) {
  469. this._pushVoice(pVoice.cbPlatform, pVoice.dwSendUserID, pVoice.dwTargetUserID, this._voice[pVoice.dwSendUserID]);
  470. this._voice[pVoice.dwSendUserID] = '';
  471. this._next();
  472. }
  473. }
  474. } else { // 微信H5
  475. if (cc.share.IsH5_WX()) {
  476. if (!!this._voiceH5[pVoice.szVID]) {
  477. this._pushVoice(pVoice.cbPlatform, pVoice.dwSendUserID, pVoice.dwTargetUserID, this._voiceH5[pVoice.szVID]);
  478. this._next();
  479. } else {
  480. wx.downloadVoice({
  481. serverId: pVoice.szVID,
  482. success: function (res) {
  483. this._voiceH5[pVoice.szVID] = res.localId;
  484. this._pushVoice(pVoice.cbPlatform, pVoice.dwSendUserID, pVoice.dwTargetUserID, this._voiceH5[pVoice.szVID]);
  485. this._next();
  486. }.bind(this)
  487. });
  488. }
  489. }
  490. }
  491. } catch (e) {
  492. if (window.LOG_DEBUG) console.log(e);
  493. }
  494. },
  495. _pushVoice: function (cbPlatform, dwSendUserID, dwTargetUserID, szVID) {
  496. this._queue.push({
  497. cbPlatform: cbPlatform,
  498. dwSendUserID: dwSendUserID,
  499. dwTargetUserID: dwTargetUserID,
  500. szVID: szVID,
  501. });
  502. },
  503. send: function (platform, str) {
  504. try {
  505. if (platform == 0) { // 原生
  506. while (str.length != 0) {
  507. if (str.length > 255) {
  508. this._engine.OnSendUserVoice(platform, str.slice(0, 255), false);
  509. str = str.slice(255);
  510. } else {
  511. this._engine.OnSendUserVoice(platform, str.slice(0), true);
  512. str = '';
  513. }
  514. }
  515. } else {
  516. this._engine.OnSendUserVoice(platform, str, true);
  517. }
  518. } catch (e) {
  519. if (window.LOG_DEBUG) console.log(e);
  520. }
  521. },
  522. _next: function () {
  523. if (this._queue.length > 0) {
  524. this.IsPlaying = true;
  525. return this.playVoice(this._queue.shift());
  526. } else {
  527. this.IsPlaying = false;
  528. // this._ctrl.onFinish();
  529. this._ctrl.onDispose(true, this.Type.PLAY_ALL_FINISH);
  530. }
  531. },
  532. // platform 0原生 1微信H5
  533. playVoice: function (data) {
  534. try {
  535. var platform = data.cbPlatform;
  536. var content = data.szVID;
  537. if (window.LOG_DEBUG) console.log(data);
  538. if (platform == 0) { // 原生
  539. if (cc.share.IsH5_WX()) return this.onPlayFinish();
  540. if (cc.sys.isNative) { // 原生播放
  541. // this._ctrl.onPlay(data);
  542. this._ctrl.onDispose(true, this.Type.PLAY, data);
  543. if (cc.sys.OS_IOS == cc.sys.os) {
  544. jsb.reflection.callStaticMethod("AppController", "playVoice:", content);
  545. } else {
  546. jsb.reflection.callStaticMethod("org/cocos2dx/javascript/VoiceCtrl", "playVoice", "(Ljava/lang/String;)V", content);
  547. }
  548. } else { // 浏览器播放
  549. var video = document.createElement('video');
  550. video.src = 'data:audio/mp4;base64,' + content;
  551. video.autoplay = true;
  552. // this._ctrl.onPlay(data);
  553. this._ctrl.onDispose(true, this.Type.PLAY, data);
  554. video.addEventListener("ended", function () {
  555. video.remove();
  556. this.onPlayFinish();
  557. }.bind(this), false);
  558. }
  559. } else { // 微信H5
  560. if (!cc.share.IsH5_WX()) return this.onPlayFinish();
  561. if (typeof wx == 'undefined') {
  562. if (!!finishFunc) finishFunc();
  563. } else { // 微信播放
  564. wx.playVoice({
  565. localId: data.szVID,
  566. success: function () {
  567. // this._ctrl.onPlay(data);
  568. this._ctrl.onDispose(true, this.Type.PLAY, data);
  569. }.bind(this)
  570. });
  571. wx.onVoicePlayEnd({
  572. complete: function (res) {
  573. this.onPlayFinish();
  574. }.bind(this)
  575. });
  576. }
  577. }
  578. } catch (e) {
  579. if (window.LOG_DEBUG) console.log(e);
  580. }
  581. },
  582. onPlayFinish: function () { // 原生回调
  583. this._next();
  584. },
  585. }
  586. // 语音base64
  587. function ThirdPartyStartRecord(success, fail) {
  588. if(cc.share.IsH5_WX()) {
  589. if (typeof wx == 'undefined') {
  590. } else {
  591. wx.startRecord({
  592. success: function () {
  593. if(success) success();
  594. },
  595. fail: function() {
  596. if(fail) fail();
  597. },
  598. });
  599. }
  600. } else if (cc.sys.isNative) {
  601. if (cc.sys.OS_IOS == cc.sys.os) {
  602. jsb.reflection.callStaticMethod("AppController", "startRecord");
  603. } else {
  604. jsb.reflection.callStaticMethod("org/cocos2dx/javascript/VoiceCtrl", "startRecord", "()V");
  605. }
  606. }
  607. }
  608. function ThirdPartyStopRecord(str) {
  609. var res = '';
  610. if (cc.sys.isNative) {
  611. if (cc.sys.OS_IOS == cc.sys.os) {
  612. res = jsb.reflection.callStaticMethod("AppController", "stopRecord:", str);
  613. } else {
  614. res = jsb.reflection.callStaticMethod("org/cocos2dx/javascript/VoiceCtrl", "stopRecord", "(Ljava/lang/String;)Ljava/lang/String;", str);
  615. }
  616. }
  617. return res;
  618. }
  619. function ThirdPartyPlayVoice(str) {
  620. if (window.LOG_NET_DATA) console.log(str);
  621. if (cc.sys.isNative) {
  622. if (cc.sys.OS_IOS == cc.sys.os) {
  623. jsb.reflection.callStaticMethod("AppController", "playVoice:", str);
  624. } else {
  625. jsb.reflection.callStaticMethod("org/cocos2dx/javascript/VoiceCtrl", "playVoice", "(Ljava/lang/String;)V", str);
  626. }
  627. } else {
  628. var video = document.createElement('video');
  629. video.src = 'data:audio/mp4;base64,' + str;
  630. video.autoplay = true;
  631. video.addEventListener("ended", function () {
  632. video.remove();
  633. g_Table.OnPlayFinish();
  634. }, false)
  635. if (typeof wx == 'undefined') {
  636. } else {
  637. }
  638. }
  639. }
  640. function ThirdPartyPickImg(JsonObj, szNeedChip) {
  641. JsonObj.URL = window.PHP_UPLOAD_URL;
  642. JsonObj.PickEndCallback = 'OnPhotoPickEnd';
  643. if (cc.sys.isNative) {
  644. if (cc.sys.OS_IOS == cc.sys.os) {
  645. // jsb.reflection.callStaticMethod("AppController","WXSharetitle:description:url:IsTimeLine:",ShareInfo.title,ShareInfo.desc,ShareInfo.link, isLine);
  646. jsb.reflection.callStaticMethod("RootViewController", "pickImg:description:", JSON.stringify(JsonObj), szNeedChip);
  647. console.log(' ### ios ThirdPartyPickImg ' + JSON.stringify(JsonObj));
  648. } else {
  649. jsb.reflection.callStaticMethod(
  650. 'org/cocos2dx/javascript/AppActivity', 'pickImg', "(Ljava/lang/String;Ljava/lang/String;)V", JSON.stringify(JsonObj), szNeedChip
  651. );
  652. }
  653. } else {
  654. if (cc.share.IsH5_WX()) {
  655. //
  656. } else {
  657. return false;
  658. }
  659. }
  660. return true
  661. }
  662. function Restart (e) {
  663. if(window.LOG_DEBUG && e) console.log(e);
  664. cc.game.restart();
  665. }