(1)拍摄视频
拍摄视频和拍摄相片的方法是基本一致的:
MediaCapture mediaCapture; MediaEncodingProfile videoEncodingProperties; protected override async void OnNavigatedTo(NavigationEventArgs e) { HardwareButtons.CameraHalfPressed += HardwareButtons_CameraHalfPressed; HardwareButtons.CameraReleased += HardwareButtons_CameraReleased; videoCaptrueElement.Source = await Initialize(); await mediaCapture.StartPreviewAsync(); } async void HardwareButtons_CameraHalfPressed(object sender, CameraEventArgs e) { if( mediaCapture != null ) { var video = await KnownFolders.VideosLibrary.CreateFileAsync("video.mp4", CreationCollisionOption.GenerateUniqueName); await mediaCapture.StartRecordToStorageFileAsync(videoEncodingProperties, video); } } async void HardwareButtons_CameraReleased(object sender, CameraEventArgs e) { if( mediaCapture != null ) { await mediaCapture.StopRecordAsync(); } } private async Task<MediaCapture> Initialize() { mediaCapture = new MediaCapture(); await mediaCapture.InitializeAsync(); mediaCapture.VideoDeviceController.PrimaryUse = CaptureUse.Video; videoEncodingProperties = MediaEncodingProfile.CreateMp4(VideoEncodingQuality.Vga); return mediaCapture; } protected override void OnNavigatedFrom(NavigationEventArgs e) { if( mediaCapture != null ) { mediaCapture.Dispose(); mediaCapture = null; } }