void playVoice() { VoiceMgr vmr = VoiceMgr.GetInstance(); RoomMgr rm = RoomMgr.GetInstance(); if (_playingSeat < 0 && mVoiceQueue.Count > 0) { ChatItem vm = mVoiceQueue.Dequeue(); string msg = vm.voice.msg; string file = vm.path; int si = rm.getSeatIndexByID(vm.sender); int local = rm.getLocalIndex(si); _playingSeat = local; vmr.writeVoice(file, msg); vmr.play(file); if (playing != null) { playing.SetActive(false); playing = null; } playing = vm.vobj; if (playing != null) { playing.SetActive(true); } _lastPlayTime = PUtils.getMilliSeconds() + vm.voice.time; } }
public void onPress() { bar.width = 0; notice.text = "请按住说话"; voice.SetActive(true); lastTouchTime = PUtils.getMilliSeconds(); Debug.Log("onPress"); VoiceMgr.GetInstance().prepare("record.amr"); }
void playVoiceItem(ChatItem item) { _playingSeat = -1; _lastPlayTime = 0; mVoiceQueue.Clear(); VoiceMgr vm = VoiceMgr.GetInstance(); vm.stop(); mVoiceQueue.Enqueue(item); playVoice(); }
void Awake() { PUtils ut = PUtils.GetInstance(); Loom lm = Loom.Current; mNetMgr = NetMgr.GetInstance(); mNetMgr.Init(); mGameMgr = GameMgr.GetInstance(); mGameMgr.Init(); mRoomMgr = RoomMgr.GetInstance(); mRoomMgr.Init(); mVoiceMgr = VoiceMgr.GetInstance(); mVoiceMgr.Init(); mReplayMgr = ReplayMgr.GetInstance(); mReplayMgr.Init(); }
public void onRelease() { if (lastTouchTime == 0) { return; } if (PUtils.getMilliSeconds() - lastTouchTime < 1000) { VoiceMgr.GetInstance().cancel(); voice.SetActive(true); bar.width = 0; notice.text = "录制时间太短"; voice.SetActive(false); } else { onVoiceOK(); } lastTouchTime = 0; }
void onVoiceOK() { VoiceMgr vm = VoiceMgr.GetInstance(); if (lastTouchTime > 0) { vm.release(); long t = (long)((Time.time - lastTouchTime) * 1000); string msg = vm.getVoiceData("record.amr"); if (msg != null && msg.Length > 0) { JsonObject ob = new JsonObject(); ob ["msg"] = msg; ob ["time"] = t; NetMgr.GetInstance().send("voice_msg", ob); } } voice.SetActive(false); }
void enter(TOUCH_STATE state) { VoiceMgr vm = VoiceMgr.GetInstance(); Debug.Log("enter " + state); switch (state) { case TOUCH_STATE.START: vm.prepare("record.amr"); lastTouchTime = Time.time; voice.SetActive(true); mic.SetActive(true); volume.SetActive(true); cancel.SetActive(false); warning.SetActive(false); time.transform.localScale = new Vector2(0, 1); notice.text = "滑动手指,取消发送"; break; case TOUCH_STATE.MOVE_OUT: if (lastTouchTime > 0) { mic.SetActive(false); volume.SetActive(false); cancel.SetActive(true); warning.SetActive(false); notice.text = "松开手指,取消发送"; } break; case TOUCH_STATE.MOVE_IN: if (lastTouchTime > 0) { mic.SetActive(true); volume.SetActive(true); cancel.SetActive(false); warning.SetActive(false); notice.text = "滑动手指,取消发送"; } break; case TOUCH_STATE.CANCEL: if (lastTouchTime > 0) { vm.cancel(); lastTouchTime = 0; voice.SetActive(false); } break; case TOUCH_STATE.END: if (lastTouchTime > 0) { if (Time.time - lastTouchTime < 1.0f) { vm.cancel(); voice.SetActive(true); mic.SetActive(false); volume.SetActive(false); cancel.SetActive(false); warning.SetActive(true); time.transform.localScale = new Vector2(0, 1); notice.text = "录制时间太短"; PUtils.setTimeout(() => { voice.SetActive(false); }, 1.0f); } else { onVoiceOK(); } lastTouchTime = 0; } break; default: break; } }
void Update() { VoiceMgr vm = VoiceMgr.GetInstance(); float now = Time.time; if (Input.GetMouseButtonDown(0)) { Ray ray = cam.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { GameObject ob = hit.collider.gameObject; if (ob.Equals(button)) { enter(TOUCH_STATE.START); inButton = true; draging = true; } } } if (draging) { bool found = false; Ray ray = cam.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { GameObject ob = hit.collider.gameObject; if (ob.Equals(button)) { found = true; } } if (Input.GetMouseButtonUp(0)) { enter(found ? TOUCH_STATE.END : TOUCH_STATE.CANCEL); draging = false; } else if (draging) { if (found != inButton) { enter(found ? TOUCH_STATE.MOVE_IN : TOUCH_STATE.MOVE_OUT); inButton = found; } } } if (voice.activeSelf && volume.activeSelf) { if (now - lastCheckTime > 0.3f) { int v = vm.getVoiceLevel(5); for (int i = 0; i < volumes.Length; i++) { volumes [i].SetActive(v > i); } lastCheckTime = now; } } if (lastTouchTime > 0) { long t = (long)((Time.time - lastTouchTime) * 1000); if (t >= MAXTIME) { onVoiceOK(); lastTouchTime = 0; } else { time.transform.localScale = new Vector2((float)t / MAXTIME, 1); } } }