public static void DownLoadVoice(string url, string fileName, int roleId, string successFuncName, string failFuncName) { GameObject go = new GameObject("WWWPortraitLoader"); WWWPortraitLoader loader = go.AddComponent <WWWPortraitLoader>(); loader.StartCoroutine(loader.DownloadVoicePlus(url, fileName, roleId, successFuncName, failFuncName)); }
public static void UploadVoice(string strURL, string fileName, byte[] data, string successFuncName, string failFuncName) { GameObject go = new GameObject("WWWPortraitLoader"); WWWPortraitLoader loader = go.AddComponent <WWWPortraitLoader>(); loader.StartCoroutine(loader.UploadVoicePlus(strURL, fileName, data, successFuncName, failFuncName)); }
public static void LoadOnLinePhoto(string strURL, string successFuncName, string failFuncName, object tex, string shaderName, string defaultIconPath) { GameObject go = new GameObject("WWWPortraitLoader"); WWWPortraitLoader loader = go.AddComponent <WWWPortraitLoader>(); //判断是否是第一次加载这张图片; string imagePath = generateLocalPath(strURL); bool isLocal = false; if (!File.Exists(imagePath)) { isLocal = false; } else { isLocal = true; strURL = "file:///" + generateLocalPath(strURL); } loader.StartCoroutine(loader.DownloadImage(strURL, successFuncName, failFuncName, tex, shaderName, defaultIconPath, isLocal)); }
public void EndRecord(int roomId, int roleId, string url, string successFuncName, string failFuncName) { if (Microphone.devices.Length == 0) { UnityEngine.Debug.LogError("Microphone.devices is null"); return; } int lastPos = Microphone.GetPosition(Microphone.devices[0]); float length = audioLength; if (Microphone.IsRecording(Microphone.devices[0])) //录音小于20秒 { length = lastPos / SamplingRate; //录音时长 } Microphone.End(Microphone.devices[0]); LuaState lua = LuaInstance.instance.Get(); if (length < 1.0f) //录音小于1秒就不处理了 { lua.LuaFuncCall(PlatformSDKController.mSelf.luaPlatformHanderRef, failFuncName, ""); return; } DateTime now = DateTime.Now; string str = now.ToString("s"); str = str.Replace("-", ""); str = str.Replace(":", ""); str = str.Replace("T", ""); this.mfilename = str + "_" + roleId + "_" + roomId; this.voice.name = this.mfilename; this.data = new float[200000]; this.voice.GetData(this.data, 0); this.data2.Clear(); for (int index = 0; index < this.data.Length; ++index) { if ((double)this.data[index] != 0.0) { this.data2.Add(this.data[index]); } } //UnityEngine.Debug.Log("count: " + data2.Count + ", length: " + length + ", cliplength: " + voice.length); AudioClip clip = AudioClip.Create(this.mfilename, this.data2.Count, 1, 10000, false); clip.SetData(this.data2.ToArray(), 0); string fileName = mfilename + ".wav"; if (RecordVoice.instance.Save(fileName, clip)) { byte[] data = File.ReadAllBytes(Application.persistentDataPath + "/" + fileName); WWWPortraitLoader.UploadVoice(url, fileName, data, successFuncName, failFuncName); } lua.LuaFuncCall(PlatformSDKController.mSelf.luaPlatformHanderRef, successFuncName, fileName, length); if (isPlay) { NGUITools.PlaySound(clip); } }