Пример #1
0
        public async Task StartRecordingAsync(IRandomAccessStream stream)
        {
            ThrowIfDisposed();
            if (IsRecording || _isStarting)
                return;

            _isStarting = true;
            _device = await AudioVideoCaptureDevice.OpenForAudioOnlyAsync();
            //_device.AudioEncodingFormat = CameraCaptureAudioFormat.Aac; // AAC is default
            _recordingStream = stream;
            await _device.StartRecordingToStreamAsync(_recordingStream);
            IsRecording = true;
            _isStarting = false;
        }
 public async Task StartRecordingAsync()
 {
     _mic = await AudioVideoCaptureDevice.OpenForAudioOnlyAsync();
     _mic.AudioEncodingFormat = CameraCaptureAudioFormat.Amr;
     try
     {
         await CreateFileStreamForAudioAsync(recordAudioFileName);
         await _mic.StartRecordingToStreamAsync(_randomAccessStream);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Пример #3
0
        // Set recording state: start recording.
        private async void StartVideoRecording()
        {
            try
            {
                // Connect fileSink to captureSource.
                if (_videoCaptureDevice != null)
                {
                    if (_currentAppState == ButtonState.Ready)
                    {
                        // Create the VideoBrush for the viewfinder.
                        _videoRecorderBrush = new VideoBrush();
                        _videoRecorderBrush.SetSource(_videoCaptureDevice);

                        // Display the viewfinder image on the rectangle.
                        ViewfinderRectangle.Fill = _videoRecorderBrush;
                    }

                    if (_currentAppState != ButtonState.Initialized)
                    {
                        _videoRecorderBrush = new VideoBrush();
                        _videoRecorderBrush.SetSource(_videoCaptureDevice);

                        // Display the viewfinder image on the rectangle.
                        ViewfinderRectangle.Fill = _videoRecorderBrush;

                        _stream = await _outputFile.OpenAsync(FileAccessMode.ReadWrite);

                        await _stream.FlushAsync();
                    }

                    await _videoCaptureDevice.StartRecordingToStreamAsync(_stream);

                    _dt.Start();
                    SaveThumbnail();
                }

                // Set the button states and the message.
                UpdateUi(ButtonState.Recording, "Recording...");
            }
            // If recording fails, display an error.
            catch (Exception e)
            {
                Dispatcher.BeginInvoke(delegate
                {
                    txtDebug.Text = "ERROR1: " + e.Message;
                });
            }
        }
        public async Task StartRecordingAsync()
        {
            _mic = await AudioVideoCaptureDevice.OpenForAudioOnlyAsync();

            _mic.AudioEncodingFormat = CameraCaptureAudioFormat.Amr;
            try
            {
                await CreateFileStreamForAudioAsync(recordAudioFileName);

                await _mic.StartRecordingToStreamAsync(_randomAccessStream);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #5
0
        // 开始录像
        private async void btnCapture_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                // 获取应用程序数据存储文件夹
                StorageFolder applicationFolder = ApplicationData.Current.LocalFolder;

                // 在指定的应用程序数据存储文件夹内创建指定的文件
                StorageFile storageFile = await applicationFolder.CreateFileAsync(recordVideoFileName, CreationCollisionOption.ReplaceExisting);

                // 打开文件流,准备写入录像数据
                _stream = await storageFile.OpenAsync(FileAccessMode.ReadWrite);

                // 录制视频到指定的流
                await _captureDevice.StartRecordingToStreamAsync(_stream);

                btnCapture.IsEnabled = false;
                btnStop.IsEnabled    = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
        async void ActivateCamera()
        {
            if (_dev == null)
            {
                if (AudioVideoCaptureDevice.AvailableSensorLocations.Contains(CameraSensorLocation.Back))
                {
                    _dev = await AudioVideoCaptureDevice.OpenAsync(CameraSensorLocation.Back, AudioVideoCaptureDevice.GetAvailableCaptureResolutions(CameraSensorLocation.Back).First());

                    _videoBrush = new VideoBrush();

                    _videoBrush.SetSource(_dev);
                    MainPage_OrientationChanged(null, null);

                    this.videoRect.Fill = _videoBrush;

                    StorageFolder localFolder = ApplicationData.Current.LocalFolder;
                    StorageFile storageFile = await localFolder.CreateFileAsync("CameraMovie.mp4", CreationCollisionOption.ReplaceExisting);
                    _path = storageFile.Path;

                    _sst = await storageFile.OpenAsync(FileAccessMode.ReadWrite);
                    await _dev.StartRecordingToStreamAsync(_sst);
                }
            }
        }
 private async Task StartRecordingAsync()
 {
     await mic.StartRecordingToStreamAsync(sst);
 }