Example #1
0
        async public void Toggle(Windows.UI.Xaml.Controls.CaptureElement preview)
        {
            if (CallState == CallState.NoCall)
            {
                // Start call
                voipCall = voipCallCoordinator.RequestNewOutgoingCall("/ActiveCallContext", "Jack And Jill", "Whazzuuupppp", Windows.ApplicationModel.Calls.VoipPhoneCallMedia.Audio);

                captureElement = new Windows.Media.Capture.MediaCapture();
                await captureElement.InitializeAsync();

                preview.Source = captureElement;
                await captureElement.StartPreviewAsync();

                voipCall.NotifyCallActive();

                CallState = CallState.InCall;
            }
            else if (CallState == CallState.InCall)
            {
                // Stop call
                await captureElement.StopPreviewAsync();

                preview.Source = null;

                captureElement.Dispose();
                captureElement = null;

                voipCall.NotifyCallEnded();
                voipCall = null;

                CallState = CallState.NoCall;
            }
        }
Example #2
0
        /// <summary>
        /// Cleans up the microphone resources and the stream and unregisters from MediaCapture events
        /// </summary>
        /// <returns>true if successful</returns>
        public async System.Threading.Tasks.Task <bool> CleanupRecording()
        {
            if (isRecordingInitialized)
            {
                // If a recording is in progress during cleanup, stop it to save the recording
                if (isRecording)
                {
                    await StopRecording();
                }
                isRecordingInitialized = false;
            }

            if (mediaCapture != null)
            {
                mediaCapture.RecordLimitationExceeded -= mediaCapture_RecordLimitationExceeded;
                mediaCapture.Failed -= mediaCapture_Failed;
                mediaCapture.Dispose();
                mediaCapture = null;
            }
            if (STTStream != null)
            {
                STTStream.BufferReady -= STTStream_BufferReady;
                STTStream.AudioLevel  -= STTStream_AudioLevel;
                STTStream.Dispose();
                STTStream = null;
            }
            return(true);
        }