コード例 #1
0
        public void OnRemoveFromStack()
        {
            CleanEmoticon();

            if (audioPlay != null)
            {
                audioPlay.Stop();
                audioPlay = null;
                FusionAudio.ResumeMusic(pausedMusic);
                pausedMusic = string.Empty;
            }
        }
コード例 #2
0
        private void StartRecord()
        {
            moveFingerObj.CustomSetActive(true);
            releaseFingerObj.CustomSetActive(false);

            if (audioRecord != null)
            {
                EB.Debug.LogWarning("StartRecord: recording ...");
                return;
            }

            if (Microphone.devices.Length <= 0)
            {
                EB.Debug.LogWarning("StartRecord: their is no microphone devices");
                return;
            }

            microphoneDevice = Microphone.devices[0];
            if (string.IsNullOrEmpty(microphoneDevice))
            {
                EB.Debug.LogWarning("StartRecord: invalid microphone device");
                return;
            }

            if (audioPlay != null)
            {
                audioPlay.Stop();
                audioPlay = null;
            }
            else
            {
                pausedMusic = FusionAudio.StopMusic();
            }

            audioRecord = Microphone.Start(microphoneDevice, false, Mathf.FloorToInt(AudioWraper.MAXLENGTH),
                                           AudioWraper.FREQUENCY);
            if (audioRecord == null)
            {
                int minFreq = 0, maxFreq = 0;
                Microphone.GetDeviceCaps(microphoneDevice, out minFreq, out maxFreq);

                EB.Debug.LogWarning(
                    "StartRecord: Microphone.Start with device {0} minFreq = {1} maxFreq = {2} audioFreq = {3} maxLength = {4} failed",
                    microphoneDevice, minFreq, maxFreq, AudioWraper.FREQUENCY, AudioWraper.MAXLENGTH);

                FusionAudio.ResumeMusic(pausedMusic);
                pausedMusic      = string.Empty;
                microphoneDevice = string.Empty;

                LTChatManager.Instance.AskMicrophone();
            }
        }
コード例 #3
0
        public void Update()
        {
            if (audioRecord != null && !Microphone.IsRecording(microphoneDevice))
            {
                CloseChatTalkUI();
            }

            if (audioPlay != null && !audioPlay.isPlaying)
            {
                audioPlay = null;
                FusionAudio.ResumeMusic(pausedMusic);
                pausedMusic = string.Empty;
            }
        }
コード例 #4
0
        public void OnRelease()
        {
            if (isDragFinger)
            {
                audioRecord      = null;
                microphoneDevice = string.Empty;
                FusionAudio.ResumeMusic(pausedMusic);
                pausedMusic = string.Empty;

                talkUI.CustomSetActive(false);
            }
            else
            {
                CloseChatTalkUI();
            }
        }
コード例 #5
0
        private void EndRecord()
        {
            if (Microphone.devices.Length <= 0)
            {
                EB.Debug.LogWarning("EndRecord: their is no microphone devices");
                return;
            }

            if (audioRecord == null)
            {
                EB.Debug.LogWarning("EndRecord: audio clip is null");
                return;
            }

            if (string.IsNullOrEmpty(microphoneDevice))
            {
                EB.Debug.LogWarning("EndRecord: invalid microphone device");
                return;
            }

            int samplePos = audioRecord.samples;

            if (Microphone.IsRecording(microphoneDevice))
            {
                samplePos = Microphone.GetPosition(microphoneDevice);
                Microphone.End(microphoneDevice);
            }

            int limit = Mathf.FloorToInt(AudioWraper.MINLENGTH * AudioWraper.FREQUENCY);

            if (samplePos < limit)
            {
                MessageTemplateManager.ShowMessage(902102);
                EB.Debug.LogWarning("EndRecord: too short, {0} < {1}", samplePos, limit);
                audioRecord      = null;
                microphoneDevice = string.Empty;
                FusionAudio.ResumeMusic(pausedMusic);
                pausedMusic = string.Empty;
                return;
            }

            ChatRule.CHAT_CHANNEL channelType = ChatRule.CHAT_CHANNEL.CHAT_CHANNEL_WORLD;

            bool privateChannel = false;

            string channelStr = ChatRule.CHANNEL2STR[channelType];
            float  leftTime   = SparxHub.Instance.ChatManager.GetLastSendTime(channelStr) + GetSendInterval(channelType) - Time.realtimeSinceStartup;

            if (leftTime > 0)
            {
                var ht = Johny.HashtablePool.Claim();
                ht.Add("0", Mathf.CeilToInt(leftTime).ToString());
                MessageTemplateManager.ShowMessage(902100, ht, null);
                EB.Debug.LogWarning("EndRecord: time limited");
                audioRecord      = null;
                microphoneDevice = string.Empty;
                FusionAudio.ResumeMusic(pausedMusic);
                pausedMusic = string.Empty;
                return;
            }

            if (privateChannel)
            {
                ChatController.instance.RequestSendChat(channelType, audioRecord, samplePos, ChatController.instance.TargetPrivateUid, ChatController.instance.TargetPrivateName);
            }
            else
            {
                ChatController.instance.RequestSendChat(channelType, audioRecord, samplePos);
            }

            audioRecord      = null;
            microphoneDevice = string.Empty;
            FusionAudio.ResumeMusic(pausedMusic);
            pausedMusic = string.Empty;
        }
コード例 #6
0
        private void EndRecord()
        {
            if (Microphone.devices.Length <= 0)
            {
                EB.Debug.LogWarning("EndRecord: their is no microphone devices");
                return;
            }

            if (audioRecord == null)
            {
                EB.Debug.LogWarning("EndRecord: audio clip is null");
                return;
            }

            if (string.IsNullOrEmpty(microphoneDevice))
            {
                EB.Debug.LogWarning("EndRecord: invalid microphone device");
                return;
            }

            int samplePos = audioRecord.samples;

            if (Microphone.IsRecording(microphoneDevice))
            {
                samplePos = Microphone.GetPosition(microphoneDevice);
                Microphone.End(microphoneDevice);
            }

            int limit = Mathf.FloorToInt(AudioWraper.MINLENGTH * AudioWraper.FREQUENCY);

            if (samplePos < limit)
            {
                MessageTemplateManager.ShowMessage(902102);
                EB.Debug.LogWarning("EndRecord: too short, {0} < {1}", samplePos, limit);
                audioRecord      = null;
                microphoneDevice = string.Empty;
                FusionAudio.ResumeMusic(pausedMusic);
                pausedMusic = string.Empty;
                return;
            }

            ChatRule.CHAT_CHANNEL channelType = GetCurChannelType();
            if (channelType == ChatRule.CHAT_CHANNEL.CHAT_CHANNEL_NONE)
            {
                EB.Debug.LogWarning("EndRecord: invalid channel");
                audioRecord      = null;
                microphoneDevice = string.Empty;
                FusionAudio.ResumeMusic(pausedMusic);
                pausedMusic = string.Empty;
                return;
            }

            bool privateChannel = true;

            string channelStr = ChatRule.CHANNEL2STR[channelType];
            float  leftTime   = SparxHub.Instance.ChatManager.GetLastSendTime(channelStr) + GetSendInterval(channelType) -
                                Time.realtimeSinceStartup;

            if (leftTime > 0)
            {
                var ht = Johny.HashtablePool.Claim();
                ht.Add("0", Mathf.CeilToInt(leftTime).ToString());
                MessageTemplateManager.ShowMessage(902100, ht, null);
                EB.Debug.LogWarning("EndRecord: time limited");
                audioRecord      = null;
                microphoneDevice = string.Empty;
                FusionAudio.ResumeMusic(pausedMusic);
                pausedMusic = string.Empty;
                return;
            }

            // 如果在别人的黑名单里面或者别人在自己的黑名单里面,该消息只做本地显示,不向服务器上发
            if (FriendManager.Instance.CheckBeblack(ChatController.instance.TargetPrivateUid) ||
                FriendManager.Instance.CheckBlacklist(ChatController.instance.TargetPrivateUid))
            {
                EB.Sparx.ChatMessage msg =
                    ChatController.instance.NewChatMessage(ChatRule.CHAT_CHANNEL.CHAT_CHANNEL_PRIVATE, string.Empty);
                msg.privateUid  = ChatController.instance.TargetPrivateUid;
                msg.privateName = ChatController.instance.TargetPrivateName;
                msg.isAudio     = true;
                msg.audioClip   = audioRecord;
                SparxHub.Instance.ChatManager.OnMessages(new EB.Sparx.ChatMessage[] { msg });
            }
            else if (privateChannel)
            {
                ChatController.instance.RequestSendChat(channelType, audioRecord, samplePos,
                                                        ChatController.instance.TargetPrivateUid, ChatController.instance.TargetPrivateName);

                LaunchChat();
            }
            else
            {
                ChatController.instance.RequestSendChat(channelType, audioRecord, samplePos);
            }

            audioRecord      = null;
            microphoneDevice = string.Empty;
            FusionAudio.ResumeMusic(pausedMusic);
            pausedMusic = string.Empty;
            mInvalid    = true;
        }