public async void StartRecord(string label, uint quality) { try { if (mode == RecordMode.AUDIO) { StorageFile file = await videoStore.CreateFileAsync($"{label}.mp3", CreationCollisionOption.GenerateUniqueName); await MediaCap.StartRecordToStorageFileAsync(MediaEncodingProfile.CreateMp3(AudioEncodingQuality.Auto), file); } else if (mode == RecordMode.VIDEO || mode == RecordMode.VIDEOAUDIO) { // Choose quality based recording MediaCap.SetEncoderProperty(MediaStreamType.VideoRecord, new Guid(0x1c0608e9, 0x370c, 0x4710, 0x8a, 0x58, 0xcb, 0x61, 0x81, 0xc4, 0x24, 0x23), PropertyValue.CreateUInt32(3)); // Set quality level MediaCap.SetEncoderProperty(MediaStreamType.VideoRecord, new Guid(0xfcbf57a3, 0x7ea5, 0x4b0c, 0x96, 0x44, 0x69, 0xb4, 0x0c, 0x39, 0xc3, 0x91), PropertyValue.CreateUInt32(quality)); StorageFile file = await videoStore.CreateFileAsync($"{label}.mp4", CreationCollisionOption.GenerateUniqueName); await MediaCap.StartRecordToStorageFileAsync(MediaEncodingProfile.CreateMp4(VideoEncodingQuality.Auto), file); } else { IsRecording = false; } IsRecording = true; Log.Error("Began Recording"); } catch (Exception ex) { Log.Error($"Failed to record:\t{ex}"); } }
public async void StopRecord() { if (IsRecording) { try { await MediaCap.StopRecordAsync(); IsRecording = false; Log.Error("Finished Recording"); } catch (Exception ex) { Log.Error($"Failed to save recording:\t{ex}"); } } }
/// <summary> /// Takes a picture from the webcam /// </summary> /// <returns>StorageFile of image</returns> public async Task <StorageFile> TakePicture() { try { //captureImage is our Xaml image control (to preview the picture onscreen) CaptureImage.Source = null; //gets a reference to the file we're about to write a picture into StorageFile photoFile = await KnownFolders.PicturesLibrary.CreateFileAsync( "EmotionPic.jpg", CreationCollisionOption.GenerateUniqueName); //use the MediaCapture object to stream captured photo to a file ImageEncodingProperties imageProperties = ImageEncodingProperties.CreateJpeg(); await MediaCap.CapturePhotoToStorageFileAsync(imageProperties, photoFile); //show photo onscreen IRandomAccessStream photoStream = await photoFile.OpenReadAsync(); BitmapImage bitmap = new BitmapImage(); bitmap.SetSource(photoStream); CaptureImage.Width = bitmap.PixelWidth; CaptureImage.Height = bitmap.PixelHeight; CaptureImage.Source = bitmap; AppStatus.Text = "Took Photo: " + photoFile.Name; return(photoFile); } catch (Exception ex) { //write the exception on screen AppStatus.Text = "Error taking picture: " + ex.Message; return(null); } }