local PluginBase = require("luaScript.Plugins.PluginBase") local PluginGVoice = class("PluginGVoice" , PluginBase) function PluginGVoice:ctor() PluginGVoice.super.ctor(self); self.PluginGVoice = nil end -- 启动插件 function PluginGVoice:start() log("PluginGVoice::start()") local pathRecording = cc.FileUtils:getInstance():getWritablePath().."recording.dat"; local pathDownload = cc.FileUtils:getInstance():getWritablePath().."download.dat"; -- self.PluginGVoice = cc.PluginManager:getInstance():createPlugin("PluginGVoice" , "com/ddgame/plugin/PluginGVoice"); if isAndroidPlatform() then self.PluginGVoice = cc.PluginManager:getInstance():createPlugin("PluginGVoice" , "com/ddgame/plugin/PluginGVoice"); elseif isIOSPlatform() then self.PluginGVoice = cc.PluginManager:getInstance():createPlugin("IOSPluginGVoice" , "IOSPluginGVoice"); end if self.PluginGVoice then -- log("PluginGVoice::start() uid = "..table.tostring(app.user.loginInfo)) local developerInfo = { gameId = "478434646", userId = app.user.loginInfo.uid, gameKey = "5b7aab45c3f56d2816fa48a8273dae3c", callback = handler(self, self.onResult), -- 回调函数 pathRecording = pathRecording, pathDownload = pathDownload, }; log("PluginGVoice::start() developerInfo = ", table.tostring(developerInfo)) self.PluginGVoice:callVoid("initPlugin", developerInfo); else log("PluginGVoice::start() failed") end end -- 停止插件 function PluginGVoice:stop() if self.PluginGVoice then cc.PluginManager:getInstance():removePlugin(self.PluginGVoice); self.PluginGVoice = nil; end end -- 开始录音 function PluginGVoice:ApplyMessageKey() if self.PluginGVoice then self.PluginGVoice:callVoid("ApplyMessageKey"); end end -- 开始录音 function PluginGVoice:startRecord() if self.PluginGVoice then self.PluginGVoice:callVoid("startRecord"); end end -- 取消录音 function PluginGVoice:cancelRecord() if self.PluginGVoice then self.PluginGVoice:callVoid("cancelRecord"); end end -- 结束录音 function PluginGVoice:stopRecord() log("PluginGVoice:stopRecord()"); if self.PluginGVoice then self.PluginGVoice:callVoid("stopRecord"); end end -- 播放录音 function PluginGVoice:playRecord(filePath) log("PluginGVoice:playRecord() fileId = ", filePath); -- 记录回调 if self.PluginGVoice then local data = { filePath = tostring(filePath) } log("PluginGVoice:playRecord() data = ", table.tostring(data)) self.PluginGVoice:callVoid("playRecord", data); end end -- 停止播放录音 function PluginGVoice:stopPlayRecord() log("PluginGVoice:stopPlayRecord() "); if self.PluginGVoice then self.PluginGVoice:callVoid("stopPlayRecord"); end end -- 下载录音 -- function PluginGVoice:downGloadRecord(nfileID, nfileID, filePath, downloadCallback) function PluginGVoice: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("PluginGVoice:downloadRecord() data = ", table.tostring(data)) self.PluginGVoice:callVoid("downloadRecord", data); end end -- 加入房间 function PluginGVoice:JoinRoom(room) if self.PluginGVoice then local data = { room = tostring(room) } log("PluginGVoice:JoinRoom() data = ", table.tostring(data)) self.PluginGVoice:callVoid("JoinRoom", data); end end -- 退出房间 function PluginGVoice:QuitRoom(room) if self.PluginGVoice then local data = { room = tostring(room) } log("PluginGVoice:QuitRoom() data = ", table.tostring(data)) self.PluginGVoice:callVoid("QuitRoom", data); end end -- 开启麦克风 function PluginGVoice:OpenMic() log("PluginGVoice:OpenMic() "); if self.PluginGVoice then self.PluginGVoice:callVoid("OpenMic"); end end -- 关闭麦克风 function PluginGVoice:CloseMic() log("PluginGVoice:CloseMic() "); if self.PluginGVoice then self.PluginGVoice:callVoid("CloseMic"); end end -- 开启扬声器 function PluginGVoice:OpenSpeaker() log("PluginGVoice:OpenSpeaker() "); if self.PluginGVoice then self.PluginGVoice:callVoid("OpenSpeaker"); end end -- 关闭扬声器 function PluginGVoice:CloseSpeaker() log("PluginGVoice:CloseSpeaker() "); if self.PluginGVoice then self.PluginGVoice:callVoid("CloseSpeaker"); end end -- function PluginGVoice:OnApplicationPause() log("PluginGVoice:OnApplicationPause() "); if self.PluginGVoice then self.PluginGVoice:callVoid("OnApplicationPause"); end end -- function PluginGVoice:Update() -- log("PluginGVoice:Update() "); if self.PluginGVoice then self.PluginGVoice:callVoid("Update"); end end -- 回调函数 function PluginGVoice:onResult(result) log("PluginGVoice:onResult() result = ", result) local resultJson = json.decode(result); log("PluginGVoice: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)) -- 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 = "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); self.downloadCallback( info.filePath); end -- elseif code == 7006 then -- 录音下载失败 elseif code == 7004 then -- 录音下载失败 --showTooltip("呀呀语音 录音下载失败") local info = json.decode(msg) print("录音下载失败", "info = ", table.tostring(info)) elseif code == 7011 then -- 加入房间 local info = json.decode(msg) print("加入房间", "info = ", table.tostring(info)) -- self:OpenMic() self:OpenSpeaker() end end return PluginGVoice