private async void Capture_Click(object sender, RoutedEventArgs e)
{
// Using the CameraCaptureUI object to invoke webcam and capture the image.
CameraCaptureUI cc = new CameraCaptureUI();
cc.VideoSettings.Format = CameraCaptureUIVideoFormat.Mp4;
cc.VideoSettings.MaxResolution = CameraCaptureUIMaxVideoResolution.HighestAvailable;
// saving captured file in the StorageFile object, so that it can be later used to save the file in the specified location.
sf = await cc.CaptureFileAsync(CameraCaptureUIMode.Video);
if (sf != null)
{
rs = await sf.OpenAsync(FileAccessMode.Read);
video.SetSource(rs, sf.ContentType);
video.Play();
}
}
private async void Save_Click(object sender, RoutedEventArgs e)
{
try
{
// Creating object of FileSavePicker and adding few values to the properties of the object.
FileSavePicker fs = new FileSavePicker();
fs.FileTypeChoices.Add("video", new List < string > ()
{
".mp4"
});
fs.DefaultFileExtension = ".mp4";
fs.SuggestedFileName = "Video" + DateTime.Today.ToString();
fs.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
// Using storagefile object defined earlier in above method to save the file using filesavepicker.
fs.SuggestedSaveFile = sf;
// Saving the file
var s = await fs.PickSaveFileAsync();
if (s != null)
{
using(var dataReader = new DataReader(rs.GetInputStreamAt(0)))
{
await dataReader.LoadAsync((uint) rs.Size);
byte[] buffer = new byte[(int) rs.Size];
dataReader.ReadBytes(buffer);
await FileIO.WriteBytesAsync(s, buffer);
}
}
}
catch (Exception ex)
{
var messageDialog = new MessageDialog("Something went wrong.");
messageDialog.ShowAsync();
}
}This code snippet for VideoCapture App in Windows Store App.
