public StartRecordToStorageFileAsync ( [ encodingProfile, [ file ) : IAsyncAction | ||
encodingProfile | [ | |
file | [ | |
return | IAsyncAction |
//Record the Screen private async void btnRecord_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e) { if (btnRecord.IsChecked.HasValue && btnRecord.IsChecked.Value) { // Initialization - Set the current screen as input var scrCaptre = ScreenCapture.GetForCurrentView(); mCap = new MediaCapture(); await mCap.InitializeAsync(new MediaCaptureInitializationSettings { VideoSource = scrCaptre.VideoSource, AudioSource = scrCaptre.AudioSource, }); // Start Recording to a File and set the Video Encoding Quality var file = await GetScreenRecVdo(); await mCap.StartRecordToStorageFileAsync(MediaEncodingProfile.CreateMp4(VideoEncodingQuality.Auto), file); } else { // Stop recording and start playback of the file await StopRecording(); //If Media Element is taken on XAML //var file = await GetScreenRecVdo(CreationCollisionOption.OpenIfExists); //OutPutScreen.SetSource(await file.OpenReadAsync(), file.ContentType); } }
private async void StartRecord() { try { ShowStatusMessage("Starting Record"); String fileName; fileName = VIDEO_FILE_NAME; m_recordStorageFile = await Windows.Storage.KnownFolders.VideosLibrary.CreateFileAsync(fileName, Windows.Storage.CreationCollisionOption.GenerateUniqueName); ShowStatusMessage("Create record file successful"); MediaEncodingProfile recordProfile = null; recordProfile = MediaEncodingProfile.CreateMp4(Windows.Media.MediaProperties.VideoEncodingQuality.Auto); await m_mediaCaptureMgr.StartRecordToStorageFileAsync(recordProfile, m_recordStorageFile); m_bRecording = true; btnStartStopRecord1.IsEnabled = true; btnStartStopRecord1.Content = "StopRecord"; ShowStatusMessage("Start Record successful"); } catch (Exception exception) { ShowExceptionMessage(exception); } }
private async void startRecord(object sender, RoutedEventArgs e) { var selected = captureDeviceListView.SelectedItem as DeviceInformation; if (selected != null) { InitCaptureSettings(selected.Id); await InitMediaCapture(); var storageFile = await Windows.Storage.KnownFolders.VideosLibrary.CreateFileAsync("audioOut.mp3", Windows.Storage.CreationCollisionOption.GenerateUniqueName); audioFileName = storageFile.Name; MediaEncodingProfile profile = null; profile = MediaEncodingProfile.CreateM4a(Windows.Media.MediaProperties.AudioEncodingQuality.Auto); await audioCapture.StartRecordToStorageFileAsync(profile, storageFile); isRecording = true; outputTextBlock.Text = "Recording..."; } else { outputTextBlock.Text = "Error: No audio device selected."; } refreshUI(); }
internal async void btnStartStopRecord_Click(Object sender, Windows.UI.Xaml.RoutedEventArgs e) { try { String fileName; EnableButton(false, "StartStopRecord"); if (!m_bRecording) { ShowStatusMessage("Starting Record"); fileName = VIDEO_FILE_NAME; m_recordStorageFile = await Windows.Storage.KnownFolders.VideosLibrary.CreateFileAsync(fileName, Windows.Storage.CreationCollisionOption.GenerateUniqueName); ShowStatusMessage("Create record file successful"); MediaEncodingProfile recordProfile = null; recordProfile = MediaEncodingProfile.CreateMp4(Windows.Media.MediaProperties.VideoEncodingQuality.Auto); await m_mediaCaptureMgr.StartRecordToStorageFileAsync(recordProfile, m_recordStorageFile); m_bRecording = true; SwitchRecordButtonContent(); EnableButton(true, "StartStopRecord"); ShowStatusMessage("Start Record successful"); } else { ShowStatusMessage("Stopping Record"); await m_mediaCaptureMgr.StopRecordAsync(); m_bRecording = false; EnableButton(true, "StartStopRecord"); SwitchRecordButtonContent(); ShowStatusMessage("Stop record successful"); if (!m_bSuspended) { var stream = await m_recordStorageFile.OpenAsync(Windows.Storage.FileAccessMode.Read); ShowStatusMessage("Record file opened"); ShowStatusMessage(this.m_recordStorageFile.Path); playbackElement1.AutoPlay = true; playbackElement1.SetSource(stream, this.m_recordStorageFile.FileType); playbackElement1.Play(); } } } catch (Exception ex) { ShowExceptionMessage(ex); m_bRecording = false; SwitchRecordButtonContent(); EnableButton(true, "StartStopRecord"); } }
// </SnippetMediaCaptureVideo_InitMCobjectCS> // <SnippetMediaCaptureVideo_StartRecordCS> // Start the video capture. private async void StartMediaCaptureSession() { var storageFile = await Windows.Storage.KnownFolders.VideosLibrary.CreateFileAsync( "cameraCapture.mp4", Windows.Storage.CreationCollisionOption.GenerateUniqueName); await _mediaCapture.StartRecordToStorageFileAsync(_profile, storageFile); _recording = true; }
private async void startRecord(object sender, RoutedEventArgs e) { var storageFile = await Windows.Storage.KnownFolders.VideosLibrary.CreateFileAsync("audioOut.mp3", Windows.Storage.CreationCollisionOption.GenerateUniqueName); audioFileName = storageFile.Name; MediaEncodingProfile profile = null; profile = MediaEncodingProfile.CreateM4a(Windows.Media.MediaProperties.AudioEncodingQuality.Auto); await audioCapture.StartRecordToStorageFileAsync(profile, storageFile); }
async private void RecordVideo_Click(object sender, RoutedEventArgs e) { captureFile = await KnownFolders.VideosLibrary.CreateFileAsync( "video", Windows.Storage.CreationCollisionOption.GenerateUniqueName); MediaEncodingProfile recordProfile = null; recordProfile = MediaEncodingProfile.CreateMp4(Windows.Media.MediaProperties.VideoEncodingQuality.Auto); await captureManager.StartRecordToStorageFileAsync(recordProfile, captureFile); }
//<SnippetStartRecordWithRotation> public async void StartRecordWithRotation(Windows.Storage.StorageFile videoFile) { var mediaEncodingProps = Windows.Media.MediaProperties.MediaEncodingProfile.CreateMp4( Windows.Media.MediaProperties.VideoEncodingQuality.Auto); System.Guid MFVideoRotationGuid = new System.Guid("C380465D-2271-428C-9B83-ECEA3B4A85C1"); // MF_MT_VIDEO_ROTATION in Mfapi.h int MFVideoRotation = ConvertVideoRotationToMFRotation(VideoRotation.Clockwise90Degrees); mediaEncodingProps.Video.Properties.Add(MFVideoRotationGuid, PropertyValue.CreateInt32(MFVideoRotation)); await captureMgr.StartRecordToStorageFileAsync(mediaEncodingProps, videoFile); }
// Start the Video Capture private async void StartMediaCaptureSession() { var storageFile = await Windows.Storage.KnownFolders.VideosLibrary.CreateFileAsync("cameraCapture.wmv", Windows.Storage.CreationCollisionOption.GenerateUniqueName); fileName = storageFile.Name; await mediaCapture.StartRecordToStorageFileAsync(profile, storageFile); recording = true; // start the preview capturePreview.Source = mediaCapture; await mediaCapture.StartPreviewAsync(); }
internal async void btnStartStopRecord_Click(Object sender, Windows.UI.Xaml.RoutedEventArgs e) { try { String fileName; EnableButton(false, "StartStopRecord"); if (!m_bRecording) { ShowStatusMessage("Starting Record"); fileName = AUDIO_FILE_NAME; m_recordStorageFile = await Windows.Storage.KnownFolders.VideosLibrary.CreateFileAsync(fileName, Windows.Storage.CreationCollisionOption.GenerateUniqueName); ShowStatusMessage("Create record file successful"); MediaEncodingProfile recordProfile = null; recordProfile = MediaEncodingProfile.CreateM4a(Windows.Media.MediaProperties.AudioEncodingQuality.Auto); await m_mediaCaptureMgr.StartRecordToStorageFileAsync(recordProfile, this.m_recordStorageFile); m_bRecording = true; SwitchRecordButtonContent(); EnableButton(true, "StartStopRecord"); ShowStatusMessage("Start Record successful"); } else { stopRack.Visibility = Visibility.Collapsed; ShowStatusMessage("Stopping Record"); await m_mediaCaptureMgr.StopRecordAsync(); m_bRecording = false; EnableButton(true, "StartStopRecord"); SwitchRecordButtonContent(); ShowStatusMessage("Stop record successful"); } } catch (Exception exception) { EnableButton(true, "StartStopRecord"); ShowExceptionMessage(exception); m_bRecording = false; } }
public async Task<RecordingToken> StartAsync() { var capture = new MediaCapture(); var initSettings = new MediaCaptureInitializationSettings(); initSettings.StreamingCaptureMode = StreamingCaptureMode.Audio; await capture.InitializeAsync(initSettings); var fileName = DateTimeOffset.Now.TimeOfDay.ToString().Replace(':', '_') + ".wav"; var file = await ApplicationData.Current.LocalFolder.CreateFileAsync(fileName); var profile = MediaEncodingProfile.CreateWav(AudioEncodingQuality.Medium); await capture.StartRecordToStorageFileAsync(profile, file); return new RecordingToken(file.Path, async () => { await capture.StopRecordAsync(); // It's important to dispose the capture device here to avoid application crash when using FileSavePicker afterwards capture.Dispose(); }); }
private async void Initialize() { try { var mediaCapture = new MediaCapture(); await mediaCapture.InitializeAsync(); var file = await ApplicationData.Current.LocalFolder.CreateFileAsync(Guid.NewGuid() + ".mp4", CreationCollisionOption.ReplaceExisting); await mediaCapture.StartRecordToStorageFileAsync(MediaEncodingProfile.CreateMp4(VideoEncodingQuality.Wvga), file); var videoDev = mediaCapture.VideoDeviceController; videoDev.TorchControl.Enabled = true; _torchControl = videoDev.TorchControl; TorchSupported = _torchControl.Supported; TorchPowerSupported = _torchControl.PowerSupported; if (TorchPowerSupported) _torchControl.PowerPercent = PercentValue; if (TorchSupported) _torchControl.Enabled = IsOn; _isInitialized = true; _toggleTorchCommand.RaiseCanExecuteChanged(); } catch (Exception ex) { ErrorMessage = "Etwas unerwartetes ist passiert. Entschuldige!"; } }
//录音初始化 private async void record_Tapped(object sender, TappedRoutedEventArgs e) { try { _mediaCaptureManager = new MediaCapture(); var settings = new MediaCaptureInitializationSettings(); settings.StreamingCaptureMode = StreamingCaptureMode.Audio;//设置为音频 await _mediaCaptureManager.InitializeAsync(settings); gridRecord.Visibility = Visibility.Visible; myChat.Visibility = Visibility.Collapsed; record.IsTapEnabled = false; storyboard.Begin(); String fileName = "1.aac"; _recordStorageFile = await KnownFolders.MusicLibrary.CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting); MediaEncodingProfile recordProfile = MediaEncodingProfile.CreateM4a(AudioEncodingQuality.Auto);//录音 await _mediaCaptureManager.StartRecordToStorageFileAsync(recordProfile, this._recordStorageFile);//将录音保存到视频库 } catch (Exception ex) { Debug.WriteLine(ex.Message.ToString()); } }
public async void RecordSound() { _recordMediaCapture = new MediaCapture(); var settings = new MediaCaptureInitializationSettings { StreamingCaptureMode = StreamingCaptureMode.Audio, MediaCategory = MediaCategory.Other, AudioProcessing = AudioProcessing.Default }; await _recordMediaCapture.InitializeAsync(settings); _url = string.Format("Sound_{0}.{1}", Guid.NewGuid(), "aac"); var path = Path.Combine(StorageService.SoundPath); var folder = await StorageFolder.GetFolderFromPathAsync(path); _recordStorageFile = await folder.CreateFileAsync(_url); MediaEncodingProfile profil = MediaEncodingProfile.CreateM4a(AudioEncodingQuality.Auto); await _recordMediaCapture.StartRecordToStorageFileAsync(profil, _recordStorageFile); }
private async void StartMediaCaptureRecord_Click(object sender, RoutedEventArgs e) { StartCaptureElementRecord.IsEnabled = false; // Skip if no camera var devices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture); if (devices.Count == 0) { return; } StorageFile destination = await KnownFolders.VideosLibrary.CreateFileAsync("VideoEffectsTestApp.MediaCapture.mp4", CreationCollisionOption.ReplaceExisting); var capture = new MediaCapture(); await capture.InitializeAsync(new MediaCaptureInitializationSettings { StreamingCaptureMode = StreamingCaptureMode.Video }); var definition = await CreateEffectDefinitionAsync( (VideoEncodingProperties)capture.VideoDeviceController.GetMediaStreamProperties(MediaStreamType.VideoRecord) ); await capture.AddEffectAsync(MediaStreamType.VideoRecord, definition.ActivatableClassId, definition.Properties); await capture.StartRecordToStorageFileAsync(MediaEncodingProfile.CreateMp4(VideoEncodingQuality.Qvga), destination); await Task.Delay(3000); await capture.StopRecordAsync(); StartCaptureElementRecord.IsEnabled = true; }
private async void StartRecording() { try { // Get instance of the ScreenCapture object var screenCapture = Windows.Media.Capture.ScreenCapture.GetForCurrentView(); // Set the MediaCaptureInitializationSettings to use the ScreenCapture as the // audio and video source. var mcis = new Windows.Media.Capture.MediaCaptureInitializationSettings(); mcis.VideoSource = screenCapture.VideoSource; mcis.AudioSource = screenCapture.AudioSource; mcis.StreamingCaptureMode = Windows.Media.Capture.StreamingCaptureMode.AudioAndVideo; // Initialize the MediaCapture with the initialization settings. _mediaCapture = new MediaCapture(); await _mediaCapture.InitializeAsync(mcis); // Set the MediaCapture to a variable in App.xaml.cs to handle suspension. (App.Current as App).MediaCapture = _mediaCapture; // Hook up events for the Failed, RecordingLimitationExceeded, and SourceSuspensionChanged events _mediaCapture.Failed += new Windows.Media.Capture.MediaCaptureFailedEventHandler(RecordingFailed); _mediaCapture.RecordLimitationExceeded += new Windows.Media.Capture.RecordLimitationExceededEventHandler(RecordingReachedLimit); screenCapture.SourceSuspensionChanged += new Windows.Foundation.TypedEventHandler<ScreenCapture, SourceSuspensionChangedEventArgs>(SourceSuspensionChanged); // Create a file to record to. var videoFile = await ApplicationData.Current.LocalFolder.CreateFileAsync("recording.mp4", CreationCollisionOption.ReplaceExisting); // Create an encoding profile to use. var profile = Windows.Media.MediaProperties.MediaEncodingProfile.CreateMp4(Windows.Media.MediaProperties.VideoEncodingQuality.HD1080p); // Start recording var start_action = _mediaCapture.StartRecordToStorageFileAsync(profile, videoFile); start_action.Completed += CompletedStart; // Set a tracking variable for recording state in App.xaml.cs (App.Current as App).IsRecording = true; } catch (Exception ex) { NotifyUser("StartRecord Exception: " + ex.Message, NotifyType.ErrorMessage); } }
/// <summary> /// This method is called each time the motion sensor forwards data to the host. /// /// Note that reading is relatively straight forward and follows the general WinRT paradigm of using events args /// and reading from buffers. /// </summary> /// <param name="sender">The hidDevice that raised the event (the one that received the interrupt)</param> /// <param name="eventArgs">Contains the HidInputReport that caused the interrupt</param> private async void OnGeneralInterruptEvent(HidDevice sender, HidInputReportReceivedEventArgs eventArgs) { // Retrieve the sensor data HidInputReport inputReport = eventArgs.Report; IBuffer buffer = inputReport.Data; DataReader dr = DataReader.FromBuffer(buffer); byte[] bytes = new byte[inputReport.Data.Length]; dr.ReadBytes(bytes); // Set the video length and delay values. TimeSpan length = TimeSpan.FromSeconds(5); // Video length 5 seconds TimeSpan delay = TimeSpan.FromSeconds(15); // Pause or delay 15 seconds TimeSpan radioDelay = TimeSpan.FromMilliseconds(250); // Duration of radio-button highlight await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { // Briefly check the radio button to show that an event was fired radio1.IsChecked = true; }); // Create a threadpool timer which toggles the radio button on for the radioDelay interval ThreadPoolTimer RadioButtonTimer = ThreadPoolTimer.CreateTimer( async(source) => { await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { // Radio button is unchecked once duration expires radio1.IsChecked = false; }); }, radioDelay); // The first byte contains the motion data if ((bytes[1] == 1) && !Capture) { Capture = true; // Create a threadpool timer which stops the video capture after "length" seconds ThreadPoolTimer VideoStopTimer = ThreadPoolTimer.CreateTimer( async(source) => { await CaptureMgr.StopRecordAsync(); await rootPage.Dispatcher.RunAsync( CoreDispatcherPriority.Normal, new DispatchedHandler(() => { rootPage.NotifyUser("Video capture concluded.", NotifyType.StatusMessage); })); }, length); // Create a threadpool timer which prevents false captures by pausing detection for "delay" seconds ThreadPoolTimer CapturePauseTimer = ThreadPoolTimer.CreateTimer( async(source) => { Capture = false; await rootPage.Dispatcher.RunAsync( CoreDispatcherPriority.Normal, new DispatchedHandler(() => { rootPage.NotifyUser("Presence sensor enabled.", NotifyType.StatusMessage); })); }, delay); await rootPage.Dispatcher.RunAsync( CoreDispatcherPriority.Normal, new DispatchedHandler(() => { rootPage.NotifyUser("Video capture started.", NotifyType.StatusMessage); })); String fileName; fileName = VIDEO_FILE_NAME; StorageFile = await Windows.Storage.KnownFolders.VideosLibrary.CreateFileAsync(fileName, Windows.Storage.CreationCollisionOption.GenerateUniqueName); MediaEncodingProfile recordProfile = MediaEncodingProfile.CreateMp4(Windows.Media.MediaProperties.VideoEncodingQuality.Auto); await CaptureMgr.StartRecordToStorageFileAsync(recordProfile, StorageFile); } }