private async Task StopRecording() { await mediaCapture.StopRecordAsync(); isRecording = false; loggingChannel.LogMessage("Stopped audio recording"); }
public async void StopAudioRecording() { if (bRecordAudio == false) { return; } //crash on this line //due to invaid random access stream if (mediaCapture == null) { if (parent != null) { parent.StartWritingOutput("Error Writing Audio", 1); } return; } await mediaCapture.StopRecordAsync(); await SaveAudioToFile(); mediaCapture.Dispose(); mediaCapture = null; }
private async void AudioCaptureDialog_Closing(ContentDialog sender, ContentDialogClosingEventArgs args) { if (_capture != null) { try { await _capture.StopRecordAsync(); } catch { }; try { _capture.Dispose(); } catch { }; _mediaTimelineController.Pause(); try { (_player.Source as MediaSource).Dispose(); } catch { }; _player.Dispose(); _timer.Stop(); if (!_proceed) { await(await ApplicationData.Current.TemporaryFolder.GetFileAsync(_tempFile)).DeleteAsync(); } } }
// closing process private async void closingScenario() { try { if (isRecording) { ShowStatusMessage("Stopping record"); await mediaCaptureMgr.StopRecordAsync(); isRecording = false; } if (isPreviewing) { ShowStatusMessage("Stopping record"); await mediaCaptureMgr.StopPreviewAsync(); isRecording = false; } if (mediaCaptureMgr != null) { ShowStatusMessage("Stopping Camera"); previewElement.Source = null; mediaCaptureMgr.Dispose(); } } catch (Exception e) { } }
/// <summary> /// Callback function for any failures in MediaCapture operations /// </summary> /// <param name="currentCaptureObject"></param> /// <param name="currentFailure"></param> private async void mediaCapture_Failed(MediaCapture currentCaptureObject, MediaCaptureFailedEventArgs currentFailure) { await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async() => { try { //status.Text = "MediaCaptureFailed: " + currentFailure.Message; if (isRecording) { await mediaCapture.StopRecordAsync(); //status.Text += "\n Recording Stopped"; } } catch (Exception) { } //finally //{ // SetInitButtonVisibility(Action.DISABLE); // //status.Text += "\nCheck if camera is diconnected. Try re-launching the app"; //} }); //face_init.IsEnabled = true; //identify_init.IsEnabled = false; //traingroup.IsEnabled = false; //detect_init.IsEnabled = false; //generate the person group //traingroup.IsEnabled = false; //cleanup.IsEnabled = true; }
private async Task StopPreviewAsync() { if (mediaCapture != null) { if (isRecording) { await mediaCapture.StopRecordAsync(); } if (isPreviewing) { await mediaCapture.StopPreviewAsync(); } await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { captureElement.Source = null; if (displayRequest != null) { displayRequest.RequestRelease(); } mediaCapture.Dispose(); mediaCapture = null; }); } return; }
//void logo_PointerExited(object sender, PointerRoutedEventArgs e) //{ // logo.PointerExit(); //} //void logo_PointerEntered(object sender, PointerRoutedEventArgs e) //{ // logo.PointerEnter(); //} async void logo_Tapped(object sender, TappedRoutedEventArgs e) { if (!b) { //StartRecord(); file = await folder.CreateFileAsync(DateTime.Now.ToString("yyyy-MM-dd hh-mm-ss") + ".mp3", CreationCollisionOption.GenerateUniqueName); await micphone.StartRecordToStorageFileAsync(MediaEncodingProfile.CreateMp3(AudioEncodingQuality.Auto), file); b = true; logo.StartFlash(); } else { //StopRecord(); await micphone.StopRecordAsync(); var stream = await file.OpenAsync(FileAccessMode.Read); mediaElement.SetSource(stream, file.FileType); mediaElement.AutoPlay = false; b = false; logo.StopFlash(); obs.Add(file.Name); } }
private async Task StopRecording() { await mediaCapture.StopRecordAsync(); isRecording = false; Debug.WriteLine("Stopped audio recording..."); }
async Task finishEnrollment() { _speakerId = Guid.Parse((lbProfiles.SelectedItem as ListBoxItem).Content.ToString()); btnRecordEnroll.Content = "Start record enrollment"; btnRecordEnroll.IsEnabled = false; await CaptureMedia.StopRecordAsync(); Stream str = AudioStream.AsStream(); str.Seek(0, SeekOrigin.Begin); Enrollment response; try { response = await _serviceClient.EnrollAsync(str, _speakerId); } catch (EnrollmentException ex) { txtInfo.Text = ex.Message; CleanAfter(); return; } txtInfo.Text = "Remaining enrollments: " + txtInfo.Text + response.RemainingEnrollments.ToString(); txtInfo.Text = txtInfo.Text + Environment.NewLine + response.Phrase; CleanAfter(); }
/// <summary> /// 'Initialize Audio and Video' button action function /// Dispose existing MediaCapture object and set it up for audio and video /// Enable or disable appropriate buttons /// - DISABLE 'Initialize Audio and Video' /// - DISABLE 'Start Audio Record' /// - ENABLE 'Initialize Audio Only' /// - ENABLE 'Start Video Record' /// - ENABLE 'Take Photo' /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void initVideo_Click(object sender, RoutedEventArgs e) { // Disable all buttons until initialization completes SetInitButtonVisibility(Action.DISABLE); SetVideoButtonVisibility(Action.DISABLE); SetAudioButtonVisibility(Action.DISABLE); try { if (mediaCapture != null) { // Cleanup MediaCapture object if (isPreviewing) { await mediaCapture.StopPreviewAsync(); isPreviewing = false; } if (isRecording) { await mediaCapture.StopRecordAsync(); isRecording = false; recordVideo.Content = "Start Video Record"; recordAudio.Content = "Start Audio Record"; } mediaCapture.Dispose(); mediaCapture = null; } status.Text = "Initializing camera to capture audio and video..."; // Use default initialization mediaCapture = new MediaCapture(); await mediaCapture.InitializeAsync(); // Set callbacks for failure and recording limit exceeded status.Text = "Device successfully initialized for video recording!"; mediaCapture.Failed += new MediaCaptureFailedEventHandler(mediaCapture_Failed); mediaCapture.RecordLimitationExceeded += new Windows.Media.Capture.RecordLimitationExceededEventHandler(mediaCapture_RecordLimitExceeded); // Start Preview previewElement.Source = mediaCapture; await mediaCapture.StartPreviewAsync(); isPreviewing = true; status.Text = "Camera preview succeeded"; // Enable buttons for video and photo capture SetVideoButtonVisibility(Action.ENABLE); // Enable Audio Only Init button, leave the video init button disabled audio_init.IsEnabled = true; } catch (Exception ex) { status.Text = "Unable to initialize camera for audio/video mode: " + ex.Message; SetInitButtonVisibility(Action.ENABLE); } }
async void Stop(bool hide = false) { try { //ShowLoading(); await mediaCapture.StopRecordAsync(); //await _mediaRecording.StopAsync(); IsWorking = false; RootTimer.Stop(); //SearchButton.Content = SearchIcon; var fName = file.Name; Debug.WriteLine(fName); file = null; file = await localFolder.GetFileAsync(fName); //Uploader.UploadSingleVoice(file, ThreadId); Transcode(file, hide); //var stream = await file.OpenAsync(FileAccessMode.ReadWrite); //var datas = await stream.AsStream().ToByteArray(); //try //{ // await file.DeleteAsync(); //} //catch (Exception ex) { Debug.WriteLine("ex while deleting file: " + ex.Message); } } catch (Exception ex) { ex.PrintException("Upload").ShowMsg("ERR"); } }
public async void StartVideoRecordingOnThread(StreamSocket _socket) { //Make sure the MediaCapture object is initialized await CheckSetUp(); Streamer streamer = new Streamer(_socket); // When the streamer is connected, create a new Output stream using the streamer isRecording = true; while (true) { InMemoryRandomAccessStream stream = new InMemoryRandomAccessStream(); await _mediaCapture.StartRecordToStreamAsync(MediaEncodingProfile.CreateMp4(VideoEncodingQuality.Vga), stream); await Task.Delay(TimeSpan.FromSeconds(1)); await _mediaCapture.StopRecordAsync(); stream.Seek(0); Windows.Storage.Streams.Buffer buffer = new Windows.Storage.Streams.Buffer((uint)stream.Size); await stream.ReadAsync(buffer, (uint)stream.Size, Windows.Storage.Streams.InputStreamOptions.None); streamer.WriteToSocketUsingReader(buffer); } }
public async Task StartMediaCaptureProcess() { //message += $"{Environment.NewLine}start process:"; //txtBlock.Text = message; var sw = new Stopwatch(); isRecording = true; while (isRecording) { sw.Start(); fileName = GenerateFileName("mp4"); var storageFile = await Windows.Storage.KnownFolders.VideosLibrary.CreateFileAsync(fileName, Windows.Storage.CreationCollisionOption.GenerateUniqueName); //message += $"{Environment.NewLine}start: {fileName}, "; //txtBlock.Text = message; await mediaCapture.StartRecordToStorageFileAsync(profile, storageFile); while (sw.Elapsed.TotalMilliseconds <= 60000) { //delay between start recording and stop recording } //message += $"{Environment.NewLine}stop: {fileName}, "; //txtBlock.Text = message; IsPhoneDetected(""); await mediaCapture.StopRecordAsync(); sw.Reset(); } }
public async void Stop() { await _mediaCapture.StopRecordAsync(); await _memoryBuffer.FlushAsync(); //sendAudioThread.Abort(); }
private async void StopButton_Click(object sender, RoutedEventArgs e) { await m_mediaCapture.StopRecordAsync(); UpdateRecordingControls(RecordingMode.Stopped); m_timer.Stop(); CallVoiceService(); }
private async void SwitchRecordingFile(object ignored) { _isRecording = false; await _mediaCapture.StopRecordAsync(); await ExecuteStart(); _isRecording = true; }
private async void RecordLimitationExceeded(MediaCapture currentCaptureObject) { if (_isRecording) { await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async() => { ShowStatusMessage("Stopping Record on exceeding max record duration"); await m_mediaCaptureMgr.StopRecordAsync(); _isRecording = false; }); } }
// </SnippetStartRecording> // <SnippetStopRecording> private async void StopRecording() { try { //Stop Screen Recorder await _mediaCapture.StopRecordAsync(); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("StartRecording Exception: " + ex.Message); } }
private async System.Threading.Tasks.Task StopRecordAsync() { try { await m_mediaCapture.StopRecordAsync(); } catch (Exception) { } IsRecording = false; IsCaptureEnabled = true; }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void MainPage_Unloaded(object sender, RoutedEventArgs e) { if (isPreview) { await capture.StopPreviewAsync(); } if (isRecording) { await capture.StopRecordAsync(); } capture.Dispose(); capture = null; }
protected override async void OnNavigatedFrom(NavigationEventArgs e) { if (CaptureButton.IsChecked.Value) { await _capture.StopPreviewAsync(); await _capture.StopRecordAsync(); } else { await _capture.StopPreviewAsync(); } _capture.Dispose(); SystemNavigationManager.GetForCurrentView().BackRequested -= NavigateBackRequested; }
public async Task StopAsync() { try { if (m_lowLag != null) { await m_lowLag.StopAsync(); await m_lowLag.FinishAsync(); } else { await m_mediaCapture.StopRecordAsync(); } m_mediaCapture.Dispose(); m_mediaCapture = null; if (m_opusSink is IDisposable disposable) { disposable.Dispose(); m_opusSink = null; } } catch { } }
public async Task <InMemoryRandomAccessStream> StopRecording() { await _mediaCapture.StopRecordAsync(); IsRecording = false; return(_memoryBuffer); }
private async void CaptureMedia_Failed(MediaCapture sender, MediaCaptureFailedEventArgs errorEventArgs) { await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() => { await sender.StopRecordAsync(); }); }
private async void CaptureMedia_RecordLimitationExceeded(MediaCapture sender) { await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() => { await sender.StopRecordAsync(); }); }
private async void Unchecked() { if (isRecording) { await audioCapture.StopRecordAsync(); } }
private async Task BeginRecording() { while (true) { try { Debug.WriteLine($"Recording started"); var memoryStream = new InMemoryRandomAccessStream(); await _mediaCap.StartRecordToStreamAsync(MediaEncodingProfile.CreateMp4(VideoEncodingQuality.Vga), memoryStream); await Task.Delay(TimeSpan.FromSeconds(5)); await _mediaCap.StopRecordAsync(); Debug.WriteLine($"Recording finished, {memoryStream.Size} bytes"); memoryStream.Seek(0); CurrentVideo.Id = Guid.NewGuid(); CurrentVideo.Data = new byte[memoryStream.Size]; await memoryStream.ReadAsync(CurrentVideo.Data.AsBuffer(), (uint)memoryStream.Size, InputStreamOptions.None); Debug.WriteLine($"Bytes written to stream"); _signal.Set(); _signal.Reset(); } catch (Exception ex) { Debug.WriteLine($"StartRecording -> {ex.Message}"); break; } } }
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; }
/// <summary> /// Stops recording a video /// </summary> /// <returns></returns> private async Task StopRecordingAsync() { try { Debug.WriteLine("Stopping recording..."); _isRecording = false; await _mediaCapture.StopRecordAsync(); // If VS disabled itself during recording, clean up the effect if (_videoStabilizationEffect != null && !_videoStabilizationEffect.Enabled) { // Cleaning up the effect here is an implementation choice in this sample, so that, at the end of the recording, it's clearer // to the user that the effect turned itself off. Alternatively, one could try to re-enable the effect (e.g. if the reason // it disabled itself was RunningSlowly, there's a chance it will work next time), and/or prompt the user to choose a lower capture // resolution / framerate instead. await CleanUpVideoStabilizationEffectAsync(); } Debug.WriteLine("Stopped recording!"); } catch (Exception ex) { // File I/O errors are reported as exceptions Debug.WriteLine("Exception when stopping video recording: {0}", ex.ToString()); } }
/// <summary> /// Stop video recording /// </summary> /// <returns></returns> private async Task StopVideoRecordingAsync() { try { await _mediaCapture.StopRecordAsync(); await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => PhotoButton.IsEnabled = false); if (_lowLagPhotoCapture != null) { await _lowLagPhotoCapture.FinishAsync(); _lowLagPhotoCapture = null; } await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => PhotoButton.IsEnabled = true); } catch (Exception ex) { string errorMessage = string.Format("StopVideoRecording did not complete: {0}", ex.Message); Debug.Write(errorMessage); await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() => { await new MessageDialog(errorMessage).ShowAsync(); }); } }