|
- local PluginBase = require("luaScript.Plugins.PluginBase")
-
- local PluginYaya = class("PluginYaya" , PluginBase)
-
- function PluginYaya:ctor()
- PluginYaya.super.ctor(self);
-
- self.plugin = nil
-
- self.pluginKey = "PluginYaya";
- end
-
- -- 启动插件
- function PluginYaya:start()
- log("PluginYaya::start()")
-
- if isAndroidPlatform() then
- self.plugin = cc.PluginManager:getInstance():createPlugin("PluginYaya" , "com/ddgame/plugin/PluginYaya");
- elseif isIOSPlatform() then
- self.plugin = cc.PluginManager:getInstance():createPlugin("PluginYaya" , "PluginYaya");
- end
-
- if self.plugin then
-
- local userInfo = json.decode(app.user.userInfo)
- local tName = string.getShortName2(userInfo.nickname, 4) or tostring(app.user.loginInfo.uid)
- local developerInfo =
- {
- appId = "1002779",
- userId = app.user.loginInfo.uid,
- userName = tName,
- serverId = "3",--getGameId(),
- maxRecordTime = 30,
- pluginKey = self.pluginKey,
- callback = handler(self, self.onResult); -- 回调函数
- };
-
- log("PluginYaya::start() developerInfo = ", table.tostring(developerInfo))
-
- self.plugin:callVoid("initPlugin", developerInfo);
- else
- log("PluginYaya::start() failed")
- end
- end
-
- -- 停止插件
- function PluginYaya:stop()
- if self.plugin then
- cc.PluginManager:getInstance():removePlugin(self.plugin);
- self.plugin = nil;
- end
- end
-
- -- 开始录音
- function PluginYaya:startRecord()
- if self.plugin then
- self.plugin:callVoid("startRecord");
- end
- end
-
- -- 取消录音
- function PluginYaya:cancelRecord()
- if self.plugin then
- self.plugin:callVoid("cancelRecord");
- end
- end
-
- -- 结束录音
- function PluginYaya:stopRecord()
- if self.plugin then
- self.plugin:callVoid("stopRecord");
- end
- end
-
- -- 播放录音
- function PluginYaya:playRecord(filePath)
- log("PluginYaya:playRecord() filePath = ", filePath);
-
- -- 记录回调
- if self.plugin then
- local data =
- {
- filePath = tostring(filePath)
- }
- log("PluginYaya:playRecord() data = ", table.tostring(data))
- self.plugin:callVoid("playRecord", data);
- end
- end
-
- -- 停止播放录音
- function PluginYaya:stopPlayRecord()
- log("PluginYaya:stopPlayRecord() ");
- if self.plugin then
- self.plugin:callVoid("stopPlayRecord");
- end
- end
-
- -- 下载录音
- function PluginYaya:downloadRecord(nUserId, recordUrl, downloadCallback)
- self.downloadCallback = downloadCallback
- if self.plugin then
- local data =
- {
- recordTag = tostring(nUserId),
- recordUrl = tostring(recordUrl),
- play = true,
- }
- log("PluginYaya:downloadRecord() data = ", table.tostring(data))
- self.plugin:callVoid("downloadRecord", data);
- end
- end
-
- -- 回调函数
- function PluginYaya:onResult(result)
- log("PluginYaya:onResult() result = ", result)
- local resultJson = json.decode(result);
- if not resultJson then
- return
- end
- local pluginKey = tostring(resultJson.pluginKey)
- if pluginKey ~= self.pluginKey then
- return
- end
-
- local code = tonumber(resultJson.code);
- local info = json.decode(resultJson.message);
-
- if code == self.Code.INIT_SUCCESS then -- 初始化成功
- --showTooltip("呀呀语音 初始化成功")
- print("初始化成功", "info = ", table.tostring(info))
- elseif code == self.Code.INIT_FAIL then -- 初始化失败
- --showTooltip("呀呀语音 初始化失败")
- print("初始化失败", "info = ", table.tostring(info))
- elseif code == self.Code.RECORD_SUCCESS then -- 录音成功
- --showTooltip("呀呀语音 录音成功")
- print("录音成功", "info = ", table.tostring(info))
- app:dispatchEvent({name = "recordCallback", filePath = info.filePath, recordUrl = info.recordUrl, recordTime = info.recordTime });
- elseif code == self.Code.RECORD_FAIL then -- 录音失败
- --showTooltip("呀呀语音 录音失败")
- print("录音失败", "info = ", table.tostring(info))
- elseif code == self.Code.RECORD_DOWNLOAD_SUCCESS then -- 录音下载成功
- --showTooltip("呀呀语音 录音下载成功")
- print("录音下载成功", "info = ", table.tostring(info))
- if self.downloadCallback then
- self.downloadCallback(info.recordTag, info.filePath);
- end
- elseif code == self.Code.RECORD_DOWNLOAD_FAIL then -- 录音下载失败
- --showTooltip("呀呀语音 录音下载失败")
- print("录音下载失败", "info = ", table.tostring(info))
- end
- end
-
- return PluginYaya
|