windows10 IoT Core的视频录制移动应用程序,是一个展示如何在windows10 IoT Core上创建视频捕获移动应用程序的实例,同时也支持在拍摄过程中预览视频。
【需求组件:】
1个USB摄像头
1个USB鼠标
1个HDMI显示器和HDMI线
1个树莓派2开发板
【建立示例移动应用程序:】
连接USB摄像头,USB鼠标,HDMI显示器,以太网电缆(或者WiFi无线网络)到树莓派2,然后打开它
下载示例,构建并部署到树莓派2上
查看如何在树莓派2上运行
【移动应用程序建立核心步骤:】
1、 打开VS2015,创建一个新的Windows通用空白应用程序:
2、启用package.appxmanifest功能,确保麦克风和视频库(用于保存音频文件)以及网络摄像头功能被选中:
在MainPage.xaml中,添加按钮“开始捕捉”,“结束捕捉”,“播放拍摄的视频”,增加一个“捕捉元件”用于视频预览和一个“媒体元件”用于视频播放
【 】
在MainPage.xaml.cs中,你将需要枚举找到录像机设备:
【var devices = await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(Windows.Devices.Enumeration.DeviceClass.VideoCapture);】
设置“捕获设置”:
【captureInitSettings = new】 【Windows.Media.Capture.MediaCaptureInitializationSettings();captureInitSettings.StreamingCaptureMode = Windows.Media.Capture.StreamingCaptureMode.AudioAndVideo;captureInitSettings.PhotoCaptureSource = Windows.Media.Capture.PhotoCaptureSource.VideoPreview;】
初始化“媒体捕捉”:
【mediaCapture = new Windows.Media.Capture.MediaCapture();await mediaCapture.InitializeAsync(captureInitSettings);】
创建文件:
【profile = Windows.Media.MediaProperties.MediaEncodingProfile.CreateMp4(Windows.Media.MediaProperties.VideoEncodingQuality.Qvga);】
开始录制:
【var storageFile = await Windows.Storage.KnownFolders.VideosLibrary.CreateFileAsync("cameraCapture.wmv", Windows.Storage.CreationCollisionOption.GenerateUniqueName); await mediaCapture.StartRecordToStorageFileAsync(profile, storageFile);】
也可以在拍摄过程中启动预览:
【// start the preview capturePreview.Source=mediaCapture; await mediaCapture.StartPreviewAsync();】
停止录制和预览:
【private async void StopMediaCaptureSession() { await mediaCapture.StopRecordAsync(); recording = false; (App.Current as App).IsRecording = false; //stop the preview await mediaCapture.StopPreviewAsync(); }】
播放录像:
【private async void playVideo(object sender, RoutedEventArgs e) { Windows.Storage.StorageFile storageFile = await Windows.Storage.KnownFolders.VideosLibrary.GetFileAsync(fileName); var stream = await storageFile.OpenAsync(Windows.Storage.FileAccessMode.Read); // mediaControl is a MediaElement defined in XAML if (null != stream) { media.Visibility = Visibility.Visible; media.SetSource(stream, storageFile.ContentType); media.Play(); } }】