You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

190 line
5.3 KiB

  1. local PluginBase = require("luaScript.Plugins.PluginBase")
  2. local PluginIosGVoice = class("PluginIosGVoice" , PluginBase)
  3. function PluginIosGVoice:ctor()
  4. PluginIosGVoice.super.ctor(self);
  5. self.PluginGVoice = nil
  6. end
  7. -- 启动插件
  8. function PluginIosGVoice:start()
  9. log("PluginIosGVoice::start()")
  10. local pathRecording = cc.FileUtils:getInstance():getWritablePath().."recording.dat";
  11. local pathDownload = cc.FileUtils:getInstance():getWritablePath().."download.dat";
  12. self.PluginGVoice = cc.PluginManager:getInstance():createPlugin("IOSPluginGVoice" , "IOSPluginGVoice");
  13. if self.PluginGVoice then
  14. log("PluginIosGVoice::start() uid = "..table.tostring(app.user.loginInfo))
  15. local developerInfo =
  16. {
  17. gameId = "478434646",
  18. userId = app.user.loginInfo.uid,
  19. gameKey = "5b7aab45c3f56d2816fa48a8273dae3c",
  20. pathRecording = pathRecording,
  21. pathDownload = pathDownload,
  22. callback = handler(self, self.onResult), -- 回调函数
  23. };
  24. log("PluginIosGVoice::start() developerInfo = ", table.tostring(developerInfo))
  25. self.PluginGVoice:callVoid("initPlugin", developerInfo);
  26. else
  27. log("PluginIosGVoice::start() failed")
  28. end
  29. end
  30. -- 停止插件
  31. function PluginIosGVoice:stop()
  32. log("PluginIosGVoice::stop() 1")
  33. if self.PluginGVoice then
  34. log("PluginIosGVoice::stop() 2")
  35. cc.PluginManager:getInstance():removePlugin(self.PluginGVoice);
  36. self.PluginGVoice = nil;
  37. end
  38. end
  39. --
  40. function PluginIosGVoice:Update()
  41. if self.PluginGVoice then
  42. self.PluginGVoice:callVoid("Update");
  43. end
  44. end
  45. -- 开始录音
  46. function PluginIosGVoice:ApplyMessageKey()
  47. if self.PluginGVoice then
  48. -- self.PluginGVoice:callVoid("ApplyMessageKey");
  49. end
  50. end
  51. -- 开始录音
  52. function PluginIosGVoice:startRecord()
  53. if self.PluginGVoice then
  54. self.PluginGVoice:callVoid("startRecord");
  55. end
  56. end
  57. -- 取消录音
  58. function PluginIosGVoice:cancelRecord()
  59. if self.PluginGVoice then
  60. self.PluginGVoice:callVoid("cancelRecord");
  61. end
  62. end
  63. -- 结束录音
  64. function PluginIosGVoice:stopRecord()
  65. if self.PluginGVoice then
  66. self.PluginGVoice:callVoid("stopRecord");
  67. end
  68. end
  69. -- 播放录音
  70. function PluginIosGVoice:playRecord(filePath)
  71. log("PluginIosGVoice:playRecord() filePath = ", filePath);
  72. -- 记录回调
  73. if self.PluginGVoice then
  74. local data =
  75. {
  76. filePath = tostring(filePath)
  77. }
  78. log("PluginIosGVoice:playRecord() data = ", table.tostring(data))
  79. self.PluginGVoice:callVoid("playRecord", data);
  80. end
  81. end
  82. -- 停止播放录音
  83. function PluginIosGVoice:stopPlayRecord()
  84. log("PluginIosGVoice:stopPlayRecord() ");
  85. if self.PluginGVoice then
  86. self.PluginGVoice:callVoid("stopPlayRecord");
  87. end
  88. end
  89. -- 下载录音
  90. -- function PluginIosGVoice:downloadRecord(nfileID, nUserId, filePath, downloadCallback)
  91. function PluginIosGVoice:downloadRecord(nUserId, nfileID, downloadCallback)
  92. self.downloadCallback = downloadCallback
  93. if self.PluginGVoice then
  94. local data =
  95. {
  96. recordFileID = tostring(nfileID),
  97. recordTag = tostring(nUserId),
  98. -- filePath = tostring(filePath),
  99. play = true,
  100. }
  101. log("PluginIosGVoice:downloadRecord() data = ", table.tostring(data))
  102. self.PluginGVoice:callVoid("downloadRecord", data);
  103. end
  104. end
  105. -- 回调函数
  106. function PluginIosGVoice:onResult(result)
  107. log("PluginIosGVoice:onResult() result = ", result)
  108. local resultJson = json.decode(result);
  109. log("PluginIosGVoice:onResult() resultJson = ", table.tostring(resultJson))
  110. local code = resultJson.code;
  111. local msg = resultJson.message;
  112. -- if code == 7001 then -- 初始化成功
  113. if code == 1001 then -- 初始化成功
  114. --showTooltip("呀呀语音 初始化成功")
  115. local info = json.decode(msg)
  116. print("录音成功", "info = ", table.tostring(info))
  117. -- todol
  118. -- app:dispatchEvent({name = "recordGCallback", fileId = info.fileId, filePath = info.filePath, recordTime = info.recordTime });
  119. -- elseif code == 7002 then -- 初始化失败
  120. elseif code == 1002 then -- 初始化失败
  121. --showTooltip("呀呀语音 初始化失败")
  122. local info = json.decode(msg)
  123. print("录音失败", "info = ", table.tostring(info))
  124. -- elseif code == 7003 then -- 录音成功
  125. elseif code == 7001 then -- 录音成功
  126. --showTooltip("呀呀语音 录音成功")
  127. local info = json.decode(msg)
  128. print("录音成功", "info = ", table.tostring(info))
  129. -- app:dispatchEvent({name = "recordCallback", fileID = info.fileID, filePath = info.filePath, recordTime = info.recordTime });
  130. app:dispatchEvent({name = "recordGCallback", fileId = info.fileId, filePath = info.filePath, recordTime = info.recordTime });
  131. -- elseif code == 7004 then -- 录音失败
  132. elseif code == 7002 then -- 录音失败
  133. --showTooltip("呀呀语音 录音失败")
  134. local info = json.decode(msg)
  135. print("录音失败", "info = ", table.tostring(info))
  136. -- elseif code == 7005 then -- 录音下载成功
  137. elseif code == 7003 then -- 录音下载成功
  138. --showTooltip("呀呀语音 录音下载成功")
  139. local info = json.decode(msg)
  140. print("录音下载成功", "info = ", table.tostring(info))
  141. if self.downloadCallback then
  142. self.downloadCallback(info.recordTag, info.filePath);
  143. end
  144. -- elseif code == 7006 then -- 录音下载失败
  145. elseif code == 7004 then -- 录音下载失败
  146. --showTooltip("呀呀语音 录音下载失败")
  147. local info = json.decode(msg)
  148. print("录音下载失败", "info = ", table.tostring(info))
  149. end
  150. end
  151. return PluginIosGVoice