Ejemplo n.º 1
0
        public void StartRecordClicked(object sender, EventArgs e)
        {
            string errMsg   = null;
            string filename = null;

            if (rec.StartRecord(ref errMsg, ref filename))
            {
                // label updates,
                labelRecStatus.Text  = "Recording..";
                currentRecordedFile  = filename;
                currentRecordSeconds = 0;
                isTimerOn            = true;
                Xamarin.Forms.Device.StartTimer(new TimeSpan(0, 0, 1), UpdateRecordStatus);
                buttonRec.BackgroundColor = Color.Red;
            }
            else
            {
                // update status label
                labelRecStatus.Text = errMsg;
            }
        }
Ejemplo n.º 2
0
        // Start capture audio session
        public bool StartCapture()
        {
            // Check if we can start capture session
            if (status != CaptureStatus.READY)
            {
                OnCaptureError(new CaptureErrorEventArgs(CaptureErrorCode.CAPTURE_ALREADY_IN_PROGRESS));
                return(false);
            }

            saveFolderFullPath = Utils.CreateFolder(saveFolder);

            // Init audio recorder
            if (captureMicrophone)
            {
                if (MicrophoneRecorder.singleton == null)
                {
                    gameObject.AddComponent <MicrophoneRecorder>();
                }
                MicrophoneRecorder.singleton.saveFolderFullPath = saveFolderFullPath;
                MicrophoneRecorder.singleton.captureType        = CaptureType.VOD;
                audioRecorder = MicrophoneRecorder.singleton;
            }
            else
            {
                if (AudioRecorder.singleton == null)
                {
                    if (GetComponent <DontDestroy>() != null)
                    {
                        // Reset AudioListener
                        AudioListener listener = FindObjectOfType <AudioListener>();
                        if (listener)
                        {
                            Destroy(listener);
                            Debug.LogFormat(LOG_FORMAT, "AudioListener found, reset in game scene.");
                        }
                        gameObject.AddComponent <AudioListener>();
                        gameObject.AddComponent <AudioRecorder>();
                    }
                    else
                    {
                        // Keep AudioListener
                        AudioListener listener = FindObjectOfType <AudioListener>();
                        if (!listener)
                        {
                            listener = gameObject.AddComponent <AudioListener>();
                            Debug.LogFormat(LOG_FORMAT, "AudioListener not found, add a new AudioListener.");
                        }
                        listener.gameObject.AddComponent <AudioRecorder>();
                    }
                }
                AudioRecorder.singleton.saveFolderFullPath = saveFolderFullPath;
                AudioRecorder.singleton.captureType        = CaptureType.VOD;
                audioRecorder = AudioRecorder.singleton;
            }

            if (audioRecorder == null)
            {
                OnCaptureError(new CaptureErrorEventArgs(CaptureErrorCode.AUDIO_CAPTURE_START_FAILED));
                return(false);
            }

            audioRecorder.StartRecord();

            Debug.LogFormat(LOG_FORMAT, "Audio capture session started.");

            return(true);
        }