local PluginBase = require("luaScript.Plugins.PluginBase") local PluginIosGVoice = class("PluginIosGVoice" , PluginBase) function PluginIosGVoice:ctor() PluginIosGVoice.super.ctor(self); self.PluginGVoice = nil end -- 启动插件 function PluginIosGVoice:start() log("PluginIosGVoice::start()") local pathRecording = cc.FileUtils:getInstance():getWritablePath().."recording.dat"; local pathDownload = cc.FileUtils:getInstance():getWritablePath().."download.dat"; self.PluginGVoice = cc.PluginManager:getInstance():createPlugin("IOSPluginGVoice" , "IOSPluginGVoice"); if self.PluginGVoice then log("PluginIosGVoice::start() uid = "..table.tostring(app.user.loginInfo)) local developerInfo = { gameId = "478434646", userId = app.user.loginInfo.uid, gameKey = "5b7aab45c3f56d2816fa48a8273dae3c", pathRecording = pathRecording, pathDownload = pathDownload, callback = handler(self, self.onResult), -- 回调函数 }; log("PluginIosGVoice::start() developerInfo = ", table.tostring(developerInfo)) self.PluginGVoice:callVoid("initPlugin", developerInfo); else log("PluginIosGVoice::start() failed") end end -- 停止插件 function PluginIosGVoice:stop() log("PluginIosGVoice::stop() 1") if self.PluginGVoice then log("PluginIosGVoice::stop() 2") cc.PluginManager:getInstance():removePlugin(self.PluginGVoice); self.PluginGVoice = nil; end end -- function PluginIosGVoice:Update() if self.PluginGVoice then self.PluginGVoice:callVoid("Update"); end end -- 开始录音 function PluginIosGVoice:ApplyMessageKey() if self.PluginGVoice then -- self.PluginGVoice:callVoid("ApplyMessageKey"); end end -- 开始录音 function PluginIosGVoice:startRecord() if self.PluginGVoice then self.PluginGVoice:callVoid("startRecord"); end end -- 取消录音 function PluginIosGVoice:cancelRecord() if self.PluginGVoice then self.PluginGVoice:callVoid("cancelRecord"); end end -- 结束录音 function PluginIosGVoice:stopRecord() if self.PluginGVoice then self.PluginGVoice:callVoid("stopRecord"); end end -- 播放录音 function PluginIosGVoice:playRecord(filePath) log("PluginIosGVoice:playRecord() filePath = ", filePath); -- 记录回调 if self.PluginGVoice then local data = { filePath = tostring(filePath) } log("PluginIosGVoice:playRecord() data = ", table.tostring(data)) self.PluginGVoice:callVoid("playRecord", data); end end -- 停止播放录音 function PluginIosGVoice:stopPlayRecord() log("PluginIosGVoice:stopPlayRecord() "); if self.PluginGVoice then self.PluginGVoice:callVoid("stopPlayRecord"); end end -- 下载录音 -- function PluginIosGVoice:downloadRecord(nfileID, nUserId, filePath, downloadCallback) function PluginIosGVoice:downloadRecord(nUserId, nfileID, downloadCallback) self.downloadCallback = downloadCallback if self.PluginGVoice then local data = { recordFileID = tostring(nfileID), recordTag = tostring(nUserId), -- filePath = tostring(filePath), play = true, } log("PluginIosGVoice:downloadRecord() data = ", table.tostring(data)) self.PluginGVoice:callVoid("downloadRecord", data); end end -- 回调函数 function PluginIosGVoice:onResult(result) log("PluginIosGVoice:onResult() result = ", result) local resultJson = json.decode(result); log("PluginIosGVoice:onResult() resultJson = ", table.tostring(resultJson)) local code = resultJson.code; local msg = resultJson.message; -- if code == 7001 then -- 初始化成功 if code == 1001 then -- 初始化成功 --showTooltip("呀呀语音 初始化成功") local info = json.decode(msg) print("录音成功", "info = ", table.tostring(info)) -- todol -- app:dispatchEvent({name = "recordGCallback", fileId = info.fileId, filePath = info.filePath, recordTime = info.recordTime }); -- elseif code == 7002 then -- 初始化失败 elseif code == 1002 then -- 初始化失败 --showTooltip("呀呀语音 初始化失败") local info = json.decode(msg) print("录音失败", "info = ", table.tostring(info)) -- elseif code == 7003 then -- 录音成功 elseif code == 7001 then -- 录音成功 --showTooltip("呀呀语音 录音成功") local info = json.decode(msg) print("录音成功", "info = ", table.tostring(info)) -- app:dispatchEvent({name = "recordCallback", fileID = info.fileID, filePath = info.filePath, recordTime = info.recordTime }); app:dispatchEvent({name = "recordGCallback", fileId = info.fileId, filePath = info.filePath, recordTime = info.recordTime }); -- elseif code == 7004 then -- 录音失败 elseif code == 7002 then -- 录音失败 --showTooltip("呀呀语音 录音失败") local info = json.decode(msg) print("录音失败", "info = ", table.tostring(info)) -- elseif code == 7005 then -- 录音下载成功 elseif code == 7003 then -- 录音下载成功 --showTooltip("呀呀语音 录音下载成功") local info = json.decode(msg) print("录音下载成功", "info = ", table.tostring(info)) if self.downloadCallback then self.downloadCallback(info.recordTag, info.filePath); end -- elseif code == 7006 then -- 录音下载失败 elseif code == 7004 then -- 录音下载失败 --showTooltip("呀呀语音 录音下载失败") local info = json.decode(msg) print("录音下载失败", "info = ", table.tostring(info)) end end return PluginIosGVoice