Beruflich Dokumente
Kultur Dokumente
0 1 3.5k
Video capturing is one of the common tool used now a days in application development. It is quite obvious a person might be needing to
integrate Video capturing in his Windows 10 Application. So, here we are beginning with our Video Capturing application:
In Visual Studio 2015, Start a new project and select Blank app in Universal App category. Before starting any coding, we have to go to
package.appxmanifest file of the solution, we need to select Webcam and Video Library under Capabilities.
Then in the MainPage.xaml file we will add the code for button which will be used to capture the video and a media element where video will
be shown:
After adding the above code in the xaml file, we will go to the methods of the buttons: Capture_button and Save_button and add their
functionality. But before adding the functionality to the methods, we need to add the namespaces which will be required in the application:
Now, we add the declaration code for two objects of StorageFile class and IRandomAccessStream class which will be used throughout the
application:
Now, the functionality for Capture_button method which will invoke the default video capturing tool of the system:
Now, as the save functionality we used in the last blog of Capture and save Image, same we will be using here but with minor adjustments
for the Video file extensions:
01. private async void save_Video(object sender, RoutedEventArgs e)
02. {
03. // Adding try catch block in case of occurence of an exception
04. try
05. {
06. // Creating object of FileSavePicker and adding few values to the properties of the object.
07. FileSavePicker fs = new FileSavePicker();
08. fs.FileTypeChoices.Add("Video", new List<string>() { ".mp4",".3gp" });
09. fs.DefaultFileExtension = ".mp4";
10. fs.SuggestedFileName = "Video" + DateTime.Today.ToString();
11. fs.SuggestedStartLocation = PickerLocationId.VideosLibrary;
12.
13. // Using storagefile object defined earlier in above method to save the file using filesavepicker.
14. fs.SuggestedSaveFile = sf;
15.
16. // Saving the file
17. var s = await fs.PickSaveFileAsync();
18. if (s != null)
19. {
20. using (var dataReader = new DataReader(rs.GetInputStreamAt(0)))
21. {
22. await dataReader.LoadAsync((uint)rs.Size);
23. byte[] buffer = new byte[(int)rs.Size];
24. dataReader.ReadBytes(buffer);
25. await FileIO.WriteBytesAsync(s, buffer);
26. }
27. }
28. }
29. catch (Exception ex)
30. {
31. var messageDialog = new MessageDialog("Something went wrong.");
32. await messageDialog.ShowAsync();
33. }
34. }
Aditya
Bhardwaj
Blogger, Geek, FreeLancer, Developer
http://intellectape.com/
1015 56.5k
0 1
Type your comment here and press Enter Key (Minimum 18 characters)
Philadelphia
New York
London
Delhi
J o i n C # C o r n e r
and millions of developer friends worldwide.
Learn ASP.NET MVC Learn ASP.NET Core Learn Python Learn JavaScript Learn Xamarin Learn Oracle More...
Home Events Consultants Jobs Career Advice Stories Partners
About Us Contact Us Privacy Policy Terms Media Kit Sitemap Report a Bug FAQ
©2018 C# Corner. All contents are copyright of their authors.