private async void buttonPreviewWithVideoStabilizationClick(object sender, RoutedEventArgs e)
        {
            var _capture = new Windows.Media.Capture.MediaCapture();

            try
            {
                await _capture.InitializeAsync();
            }
            catch (UnauthorizedAccessException ex)
            {
                ShowRequestMessageAsync(ex);
                return;
            }



            // キャプチャしたビデオに手ブレ補正効果を追加する
            // http://msdn.microsoft.com/ja-jp/library/windows/apps/xaml/hh868169.aspx
            await _capture.AddEffectAsync(
                Windows.Media.Capture.MediaStreamType.VideoRecord,
                Windows.Media.VideoEffects.VideoStabilization,
                null);



            capturePreview.Source = _capture;
            await _capture.StartPreviewAsync();
        }
예제 #2
0
        private async void EnableMicrophoneButton_Click(object sender, RoutedEventArgs e)
        {
            bool isMicAvailable = true;

            try
            {
                var mediaCapture = new Windows.Media.Capture.MediaCapture();
                var settings     = new Windows.Media.Capture.MediaCaptureInitializationSettings();
                settings.StreamingCaptureMode = Windows.Media.Capture.StreamingCaptureMode.Audio;
                await mediaCapture.InitializeAsync(settings);
            }
            catch (Exception)
            {
                isMicAvailable = false;
            }
            if (!isMicAvailable)
            {
                await Windows.System.Launcher.LaunchUriAsync(new Uri("ms-settings:privacy-microphone"));
            }
            else
            {
                NotifyUser("Microphone was enabled", NotifyType.StatusMessage);
                this.EnableMicrophoneButton.IsEnabled = false;
                this.RecognizeKeywordButton.IsEnabled = true;
            }
        }
        private async void buttonPreviewClick(object sender, RoutedEventArgs e)
        {
            // 静止画撮影、動画録画をおこなうキャプチャーオブジェクト
            var _capture = new Windows.Media.Capture.MediaCapture();

            try
            {
                // Webカメラの初期化
                await _capture.InitializeAsync();
            }
            catch (UnauthorizedAccessException ex)
            {
                // "アクセスが拒否されました。 (HRESULT からの例外: 0x80070005 (E_ACCESSDENIED))"
                // Web カメラがユーザーに許可されていないと、
                // UnauthorizedAccessException が出る。
                ShowRequestMessageAsync(ex);
                return;
            }

            // MediaCapture インスタンスを CaptureElement コントロールに設定する
            capturePreview.Source = _capture;

            // プレビューを開始する
            await _capture.StartPreviewAsync();
        }
        // Check if the app has mic permissions. If not, query user for access
        private async Task CheckAndEnableMic()
        {
            bool isMicAvailable = true;

            try
            {
                var mediaCapture = new Windows.Media.Capture.MediaCapture();
                var settings     = new Windows.Media.Capture.MediaCaptureInitializationSettings();
                settings.StreamingCaptureMode = Windows.Media.Capture.StreamingCaptureMode.Audio;
                await mediaCapture.InitializeAsync(settings);
            }
            catch (Exception)
            {
                isMicAvailable = false;
            }
            if (!isMicAvailable)
            {
                await Windows.System.Launcher.LaunchUriAsync(new Uri("ms-settings:privacy-microphone"));
            }
            else
            {
                UpdateUI(() =>
                {
                    this.Messages.Add(new MessageDisplay("Microphone enabled", Sender.Other));
                });
            }
        }
예제 #5
0
        private async System.Threading.Tasks.Task <bool> InitializeRecording()
        {
            isRecordingInitialized = false;
            try
            {
                // Initialize MediaCapture
                mediaCapture = new Windows.Media.Capture.MediaCapture();

                await mediaCapture.InitializeAsync(new Windows.Media.Capture.MediaCaptureInitializationSettings
                {
                    //VideoSource = screenCapture.VideoSource,
                    //      AudioSource = screenCapture.AudioSource,
                    StreamingCaptureMode = Windows.Media.Capture.StreamingCaptureMode.Audio,
                    MediaCategory        = Windows.Media.Capture.MediaCategory.Other,
                    AudioProcessing      = Windows.Media.AudioProcessing.Raw
                });

                mediaCapture.RecordLimitationExceeded += mediaCapture_RecordLimitationExceeded;
                mediaCapture.Failed += mediaCapture_Failed;
                System.Diagnostics.Debug.WriteLine("Device Initialized Successfully...");
                isRecordingInitialized = true;
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("Exception while initializing the device: " + e.Message);
            }
            return(isRecordingInitialized);
        }
        public async Task <bool> GetPermissionsAsync()
        {
            var isMicAvailable = true;

            try
            {
                using (var mediaCapture = new Windows.Media.Capture.MediaCapture())
                {
                    var settings = new Windows.Media.Capture.MediaCaptureInitializationSettings
                    {
                        StreamingCaptureMode = Windows.Media.Capture.StreamingCaptureMode.Audio
                    };
                    await mediaCapture.InitializeAsync(settings);
                }
            }
            catch (Exception)
            {
                isMicAvailable = false;
            }

            if (!isMicAvailable)
            {
                await Windows.System.Launcher.LaunchUriAsync(new Uri("ms-settings:privacy-microphone"));
            }

            return(isMicAvailable);
        }
        private static async Task EnsureMicIsEnabled()
        {
            bool isMicAvailable = true;

            try
            {
                var mediaCapture = new Windows.Media.Capture.MediaCapture();
                var settings     = new Windows.Media.Capture.MediaCaptureInitializationSettings();
                settings.StreamingCaptureMode = Windows.Media.Capture.StreamingCaptureMode.Audio;
                await mediaCapture.InitializeAsync(settings);
            }
            catch (Exception)
            {
                isMicAvailable = false;
            }

            if (!isMicAvailable)
            {
                await Windows.System.Launcher.LaunchUriAsync(new Uri("ms-settings:privacy-microphone"));
            }
            else
            {
                Trace.WriteLine("Microphone already enabled");
            }
        }
예제 #8
0
        public static async Task EnableMicrophone()
        {
            if (IsMicAvailable)
            {
                return;
            }

            IsMicAvailable = true;
            try
            {
                var mediaCapture = new Windows.Media.Capture.MediaCapture();
                var settings     = new Windows.Media.Capture.MediaCaptureInitializationSettings();
                settings.StreamingCaptureMode = Windows.Media.Capture.StreamingCaptureMode.Audio;
                await mediaCapture.InitializeAsync(settings);
            }
            catch (Exception)
            {
                IsMicAvailable = false;
            }

            if (!IsMicAvailable)
            {
                await Windows.System.Launcher.LaunchUriAsync(new Uri("ms-settings:privacy-microphone"));
            }
            else
            {
                Debug.WriteLine("Microphone was enabled");
            }
        }
예제 #9
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;
            }
        }
        private async Task RestartPreviewAsync()
        {
            Windows.Media.Capture.MediaCapture capture = capturePreview.Source;
            if (capture == null)
            {
                return; //以前はキャプチャしていなかった
            }
            // キャプチャオブジェクトを作り直し
            capture = new Windows.Media.Capture.MediaCapture();

            try
            {
                // Webカメラの初期化
                await capture.InitializeAsync();

                // 作り直した MediaCapture インスタンスを CaptureElement コントロールに設定する
                capturePreview.Source = capture;

                // 本当はフィルタも再設定しなければいけない

                // プレビューを再開する
                await capture.StartPreviewAsync();
            }
            catch
            {
                //(void)
            }
        }
예제 #11
0
        async private void GetPreview()
        {
            Windows.Media.Capture.MediaCapture takePhotoManager = new Windows.Media.Capture.MediaCapture();
            await takePhotoManager.InitializeAsync();

            // start previewing
            PhotoPreview.Source = takePhotoManager;
            await takePhotoManager.StartPreviewAsync();

            // to stop it
            await takePhotoManager.StopPreviewAsync();

            ImageEncodingProperties imgFormat = ImageEncodingProperties.CreateJpeg();

            // a file to save a photo
            StorageFile file = await ApplicationData.Current.LocalFolder.CreateFileAsync(
                "Photo.jpg", CreationCollisionOption.ReplaceExisting);

            await takePhotoManager.CapturePhotoToStorageFileAsync(imgFormat, file);

            // Get photo as a BitmapImage
            BitmapImage bmpImage = new BitmapImage(new Uri(file.Path));

            // imagePreivew is a <Image> object defined in XAML
            imagePreivew.Source = bmpImage;
        }
예제 #12
0
        private static async Task SetupCapturMedia()
        {
            var mediaCapture = new Windows.Media.Capture.MediaCapture();
            var settings     = new Windows.Media.Capture.MediaCaptureInitializationSettings();

            settings.StreamingCaptureMode = Windows.Media.Capture.StreamingCaptureMode.Audio;
            await mediaCapture.InitializeAsync(settings);
        }
예제 #13
0
        private async void SetupMicrophone()
        {
            // Set default microphone here, so we can get the usb mic not the webcam mic
            // Enables camera operations with PO

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

            microphone = captureDev.AudioDeviceController;
        }
예제 #14
0
 private async void EnableMicrophone()
 {
     try
     {
         var mediaCapture = new Windows.Media.Capture.MediaCapture();
         var settings     = new Windows.Media.Capture.MediaCaptureInitializationSettings();
         settings.StreamingCaptureMode = Windows.Media.Capture.StreamingCaptureMode.Audio;
         await mediaCapture.InitializeAsync(settings);
     }
     catch (Exception)
     {
         MyMessageBox("No se pudo inicializar el micrófono");
     }
 }
 private async Task CheckMicSettings()
 {
     try
     {
         var mediaCapture = new Windows.Media.Capture.MediaCapture();
         var settings     = new Windows.Media.Capture.MediaCaptureInitializationSettings();
         settings.StreamingCaptureMode = Windows.Media.Capture.StreamingCaptureMode.Audio;
         await mediaCapture.InitializeAsync(settings);
     }
     catch (Exception exp)
     {
         LogOutput($"Error initialing mic: {exp}");
     }
 }
예제 #16
0
        private int intDelay = 200;  // Record Time in millesecond...
        // Short time - increase repetet noise ...
        // Long time - create echo ...
        // I think 200ms is optimum ...

        // If you use headphones - best time will be 500..1000ms ...


        private async void btnStart_Click(object sender, RoutedEventArgs e)
        {
            blnStart            = true;
            btnStart.Visibility = Visibility.Collapsed;
            btnStop.Visibility  = Visibility.Visible;

            textBlock.Visibility = Visibility.Visible;

            mediaCaptureAudioPrimery = new Windows.Media.Capture.MediaCapture();

            var settings = new Windows.Media.Capture.MediaCaptureInitializationSettings();

            settings.StreamingCaptureMode = Windows.Media.Capture.StreamingCaptureMode.Audio;
            settings.MediaCategory        = Windows.Media.Capture.MediaCategory.Other;
            settings.AudioProcessing      = Windows.Media.AudioProcessing.Default; // Use only Default

            await mediaCaptureAudioPrimery.InitializeAsync(settings);

            recordProfile = MediaEncodingProfile.CreateWav(Windows.Media.MediaProperties.AudioEncodingQuality.Low);


            while (blnStart)  // Repeate untile stop ...
            {
                try
                {
                    msIRAS0     = new MemoryStream();
                    streamIRAS0 = msIRAS0.AsRandomAccessStream();                                        // New Stream ...
                    await mediaCaptureAudioPrimery.StartRecordToStreamAsync(recordProfile, streamIRAS0); // write audio in first stream ...

                    await Task.Delay(intDelay);

                    await mediaCaptureAudioPrimery.StopRecordAsync();   // Stop first stream
                    await PlayThreadMethod(streamIRAS0);                // Play from first stream

                    msIRAS1     = new MemoryStream();
                    streamIRAS1 = msIRAS0.AsRandomAccessStream();                                        // Second Stream ...
                    await mediaCaptureAudioPrimery.StartRecordToStreamAsync(recordProfile, streamIRAS1); // sweetch stream ... to second stream ...

                    await Task.Delay(intDelay);

                    await mediaCaptureAudioPrimery.StopRecordAsync();
                    await PlayThreadMethod(streamIRAS1);                // Play Second Streem
                }
                catch (Exception ex)
                {
                    Stop();
                }
            }
        }
예제 #17
0
        internal async Task initializeCamera()
        {
            try
            {
                if (!initialized)
                {
	                m_mediaCaptureMgr = new Windows.Media.Capture.MediaCapture();
	                await m_mediaCaptureMgr.InitializeAsync();
                    if (debug) statusListBox.Items.Add("Device initialized successful");                    
                    initialized = true;
                }
            }
            catch (Exception exception)
            {
                if (debug) statusListBox.Items.Add("error initialize");
            }
        }
        private async Task <bool> GetPermissions()
        {
#if WINDOWS_UWP
            try
            {
                var capture = new Windows.Media.Capture.MediaCapture();
                await capture.InitializeAsync();

                Debug.Log("Camera and Microphone permissions OK");
                return(true);
            }
            catch (UnauthorizedAccessException)
            {
                Debug.LogError("Camera and microphone permissions not granted.");
                return(false);
            }
#else // WINDOWS_UWP
            SimpleConsole.AddLine(log, $"Not setup for WINDOWS_UWP");
            await Task.CompletedTask;
            return(false);
#endif // WINDOWS_UWP
        }
        /// <summary>
        /// Open Microphone
        /// </summary>
        private async void EnableMicrophone()
        {
            bool isMicAvailable = true;

            try
            {
                var mediaCapture = new Windows.Media.Capture.MediaCapture();
                var settings     = new Windows.Media.Capture.MediaCaptureInitializationSettings();
                settings.StreamingCaptureMode = Windows.Media.Capture.StreamingCaptureMode.Audio;
                await mediaCapture.InitializeAsync(settings);
            }
            catch (Exception)
            {
                isMicAvailable = false;
            }
            if (!isMicAvailable)
            {
                await Windows.System.Launcher.LaunchUriAsync(new Uri("ms-settings:privacy-microphone"));
            }
            else
            {
                NotifyUser("Microphone was enabled", NotifyType.StatusMessage);
            }
        }