Exemplo n.º 1
0
        public void PlayVoice(string urlLocal)
        {
            AudioListener.volume = 0f;
            //找到对应位置的语音动画播放
            PlayerPlayingPanelData pppd = GameData.Instance.PlayerPlayingPanelData;
            //  Debug.LogWarning("玩家index:" + (pppd.GetOtherPlayerShowPos(pppd.GetOtherPlayerPos(voices[0].iUserId)) - 1));
            int index = pppd.GetOtherPlayerShowPos(pppd.GetOtherPlayerPos(voices[0].iUserId)) - 1;

            UIMainView.Instance.PlayerPlayingPanel._playingHead[index].GetChild(4).GetComponent <Animator>().SetBool("isPlayOthers", true);
            //Debug.LogWarning("动画没问题");
            string ext = DateTime.Now.ToFileTime().ToString();

            if (VoiceFlag == 1)
            {
                string[]      pathSplit     = voices[0].szRecordUrlPath.Split('/');
                string        localFilePath = isExistGvoiceFile(MahjongLobby_AH.SDKManager.DataPath) + pathSplit[pathSplit.Length - 1];
                int           downLoadErr   = m_voiceengine.DownloadRecordedFile(ByteArrayToHexString(voices[0].id), localFilePath, 6000);
                ShortTalkData std           = GameData.Instance.ShortTalkData;
                if (!std._DownLoadFilePath.ContainsKey(voices[0].szRecordUrlPath))
                {
                    std._DownLoadFilePath.Add(voices[0].szRecordUrlPath, localFilePath);
                    Debug.LogWarning("下载地址1:" + voices[0].szRecordUrlPath);
                }
                Debug.LogWarning("下载地址2:" + localFilePath);

                m_voiceengine.OnPlayRecordFilComplete += (code, filePath) =>
                {
                    if (code != IGCloudVoice.GCloudVoiceCompleteCode.GV_ON_PLAYFILE_DONE)
                    {
                        Debug.Log("OnPlayRecordFilComplete error" + code);
                    }
                    else
                    {
                        Chenggong = true;
                        StartCoroutine(CompeletPlay());
                    }
                };
                ErroOccur(downLoadErr, () => { StartCoroutine(CompeletPlay()); });
            }
            else
            {
                YunVaImSDK.instance.RecordStartPlayRequest(urlLocal, voices[0].szRecordUrlPath, ext, (data2) =>
                {
                    Debug.LogWarning("data2.result:" + data2.result + "Chenggong:" + Chenggong);
                    if (data2.result == 0)
                    {
                        Chenggong = true;
                        StartCoroutine(CompeletPlay());
                    }
                    else
                    {
                        VoiceInit();
                        // StartCoroutine(CompeletPlay());
                        //Debug.LogWarning("播放失败");//关静音
                        Debug.LogWarning(voices[0].szRecordUrlPath);
                        MahjongCommonMethod.Instance.ShowRemindFrame("语音播放失败", true);
                    }
                });
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 当收到语音消息通知
        /// </summary>
        /// <param name="url"></param>
        /// <param name="time"></param>
        /// <param name="HasRead"></param>
        /// <param name="isSelf"></param>
        /// <param name="szurl">头像地址</param>
        internal void OnReceiveVoice(string url, float time, bool HasRead, bool isSelf, string szurl, byte [] id)
        {
            //  ig2 = _gChildPanel[2].transform.GetChild(0).GetComponent<InfinityGridLayoutGroup>();
            ShortTalkData std = GameData.Instance.ShortTalkData;
            GameObject    obj = Instantiate(Resources.Load <GameObject>("Game/ShortTalk/VoiceMessage"));

            obj.transform.SetParent(_gChildPanel[2].transform.GetChild(0));
            obj.transform.localEulerAngles = Vector3.zero;
            obj.transform.localPosition    = new Vector3(obj.transform.localPosition.x, obj.transform.localPosition.y, 0);
            obj.transform.localScale       = Vector3.one;
            PreVoiceTalkManage pvtm = obj.GetComponent <PreVoiceTalkManage>();

            pvtm._url     = url;
            pvtm._time    = time;
            pvtm._hasRead = HasRead;
            pvtm._isSelf  = isSelf;
            pvtm._headUrl = szurl;
            pvtm._id      = id;
            pvtm.UpdateShow();//更新显示条
            ShortTalkData.VoiceData _pvtm = new ShortTalkData.VoiceData();
            _pvtm._url     = pvtm._url;
            _pvtm._time    = pvtm._time;
            _pvtm._hasRead = pvtm._hasRead;
            _pvtm._isSelf  = pvtm._isSelf;
            _pvtm._headUrl = pvtm._headUrl;
            std.AddVoiceData(_pvtm);
            //  Debug.LogError("count" + std._voiceData.Count);
            //if (std._voiceData.Count>6)
            //{
            //    ig2.SetAmount(std._voiceData.Count);
            //    ig2.updateChildrenCallback = UpdateVoiceCallBack;
            //}
        }
Exemplo n.º 3
0
        public IEnumerator ReadTips()
        {
            for (int isex = 0; isex < 2; isex++)
            {
                string path2 = "";
                if (isex == 1)
                {
                    path2 = "/BShortTalk.txt";
                }
                else
                {
                    path2 = "/GShortTalk.txt";
                }
                string path =
                    // path = Application.streamingAssetsPath + "/ShortTalk.txt";
#if UNITY_ANDROID && !UNITY_EDITOR
                    Application.streamingAssetsPath + path2;
#elif UNITY_IPHONE && !UNITY_EDITOR
                    Application.streamingAssetsPath + path2;
#elif UNITY_STANDALONE_WIN || UNITY_EDITOR
                    Application.dataPath + "/StreamingAssets" + path2;
#else
                    string.Empty;
#endif
                ShortTalkData std = GameData.Instance.ShortTalkData;

                if (path.Contains("://"))
                {
                    WWW www = new WWW(path);

                    while (!www.isDone)
                    {
                        yield return(www);
                    }

                    if (www.error != null)
                    {
                        Debug.LogWarning("读取ShortTalk.txt文件失败:" + www.error);
                    }
                    //获取tips中的所有内容
                    string[] str = www.text.Split('\n');

                    for (int i = 0; i < str.Length; i++)
                    {
                        std.szShortTalk[isex].Add(str[i]);
                    }
                }
                else
                {
                    string[] str = (System.IO.File.ReadAllText(path)).Split('\n');
                    for (int i = 0; i < str.Length; i++)
                    {
                        std.szShortTalk[isex].Add(str[i]);
                    }
                }
            }
            CloneShortTalkPre();
        }
Exemplo n.º 4
0
        //IEnumerator DownLoadVoice()
        //{
        //    yield return new WaitUntil(() =>
        //    {
        //        bool aa = false;
        //        aa = DownVoice();
        //        Debug.LogError("是否下载完" + aa);
        //        return aa;
        //    });
        //    Debug.LogError("----------下载完播放");
        //    PlayRecordVoice();
        //}
        /// <summary>
        /// 播放声音
        /// </summary>
        public void PlayRecordVoice()
        {
            ShortTalkData std = GameData.Instance.ShortTalkData;

            if (!std._DownLoadFilePath.ContainsKey(_url))//如果未下载
            {
                Debug.LogWarning("未下载");
                DownVoice();
                //StartCoroutine(DownLoadVoice());
                return;
            }
            PlayerPlayingPanelData pppd = GameData.Instance.PlayerPlayingPanelData;

            Debug.LogWarning("开播");
            string ext = DateTime.Now.ToFileTime().ToString();

            if (VoiceManegerMethord.Instance.isPlayingState)
            {
                VoiceManegerMethord.Instance.StopPlayingVoice();
            }
            AudioListener.pause = true;
            if (VoiceManegerMethord.VoiceFlag == 1)
            {
                int downLoadErr = VoiceManegerMethord.Instance.m_voiceengine.PlayRecordedFile(std._DownLoadFilePath[_url]);
                VoiceManegerMethord.Instance.ErroOccur(downLoadErr, null);
                VoiceManegerMethord.Instance.m_voiceengine.OnPlayRecordFilComplete += (code, filePath) =>
                {
                    if (code != IGCloudVoice.GCloudVoiceCompleteCode.GV_ON_PLAYFILE_DONE)
                    {
                        Debug.Log("OnPlayRecordFilComplete error" + code);
                    }
                    else
                    {
                        Debug.LogError("播放失败:" + code);//关静音
                        //MahjongCommonMethod.Instance.ShowRemindFrame("语音播放失败");
                    }
                    AudioListener.pause = false;
                };
            }
            else
            {
                YunVaImSDK.instance.RecordStartPlayRequest(std._DownLoadFilePath[_url], "", ext, (data2) =>
                {
                    if (data2.result == 0)
                    {
                        // PanlePlayers[panelNum].FindChild("P" + pwpd.GetOtherPlayerShowPos(pwpd.GetOtherPlayerPos(voices[0].iUserId)).ToString()).FindChild("VoicePic").GetComponent<SpriteRenderer>().enabled = false;
                        Debug.Log("播放成功");
                    }
                    else
                    {
                        Debug.LogError("播放失败");//关静音
                        anhui.MahjongCommonMethod.Instance.ShowRemindFrame("语音播放失败");
                    }
                    // UIMainView.Instance.PlayerPlayingPanel._playingHead[pppd.GetOtherPlayerShowPos(pppd.GetOtherPlayerPos(voices[0].iUserId)) - 1].GetChild(4).GetComponent<Animator>().SetBool("isPlayOthers", false);
                    AudioListener.pause = false;
                });
            }
        }
Exemplo n.º 5
0
        //InfinityGridLayoutGroup ig3;
        void UpdateVoiceCallBack(int index, Transform trans)
        {
            ShortTalkData      std = GameData.Instance.ShortTalkData;
            PreVoiceTalkManage pvt = trans.GetComponent <PreVoiceTalkManage>();

            pvt._url     = std._voiceData[index]._url;
            pvt._time    = std._voiceData[index]._time;
            pvt._hasRead = std._voiceData[index]._hasRead;
            pvt._isSelf  = std._voiceData[index]._isSelf;
            pvt._headUrl = std._voiceData[index]._headUrl;
            // pvt._url = std._voiceData[index]._url;
            pvt.UpdateShow();
        }
Exemplo n.º 6
0
        /// <summary>
        /// 在游戏一开始的时候加载快捷语
        /// </summary>
        public void CloneShortTalkPre()
        {
            int isex = SDKManager.Instance.isex;

            ShortTalkData std = GameData.Instance.ShortTalkData;

            for (int i = 0; i < std.szShortTalk[isex].Count; i++)
            {
                // Debug.LogError(std.szShortTalk[i]);
                GameObject go = Instantiate(Resources.Load <GameObject>("Game/ShortTalk/ShortTalkText"));
                go.transform.SetParent(_gChildPanel[0].transform.GetChild(0));
                go.transform.localEulerAngles = Vector3.zero;
                go.transform.localPosition    = new Vector3(go.transform.localPosition.x, go.transform.localPosition.y, 0);
                go.transform.localScale       = Vector3.one;
                go.GetComponent <PreShortTalkManage>()._text.text = std.szShortTalk[isex][i];
                go.GetComponent <PreShortTalkManage>()._mID       = i;
            }
        }
Exemplo n.º 7
0
        internal void UpdateShow()
        {
            ShortTalkData std = GameData.Instance.ShortTalkData;

            if (std.isShowPanel)
            {
                _gPanelchat.SetActive(true);
                if (std.szShortTalk[0].Count > 6 && _gChildPanel[0].activeInHierarchy)
                {
                    ig1 = _gChildPanel[0].transform.GetChild(0).GetComponent <InfinityGridLayoutGroup>();
                    ig1.SetAmount(std.szShortTalk[0].Count);
                    ig1.updateChildrenCallback = UpdateCallBack;
                }
            }
            else
            {
                _gPanelchat.SetActive(false);
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// 当点击播放记录的时候下载到本地
        /// </summary>
        public void DownVoice()
        {
            //bool bb = false;
            string        DownLoadlocalfilePath = string.Format("{0}{1}.amr", VoiceManegerMethord.Instance.isExistGvoiceFile(MahjongLobby_AH.SDKManager.DataPath), DateTime.Now.ToFileTime());
            ShortTalkData std = GameData.Instance.ShortTalkData;

            if (!std._DownLoadFilePath.ContainsKey(_url))
            {
                std._DownLoadFilePath.Add(_url, DownLoadlocalfilePath);
            }
            string fileid = DateTime.Now.ToFileTime().ToString();

            if (VoiceManegerMethord.VoiceFlag == 1)
            {
                int downLoadErr = VoiceManegerMethord.Instance.m_voiceengine.DownloadRecordedFile(VoiceManegerMethord.ByteArrayToHexString(_id), DownLoadlocalfilePath, 6000);
            }
            else
            {
                YunVaImSDK.instance.DownLoadFileRequest(_url, DownLoadlocalfilePath, fileid, (data4) =>
                {
                    if (data4.result == 0)
                    {
                        Debug.Log("下载成功:" + data4.filename);
                        PlayRecordVoice();
                        // bb = true;
                    }
                    else
                    {
                        Debug.Log("下载失败:" + data4.msg);
                        //bb = false;
                    }
                });
            }

            //return bb;
        }