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