UWP视频导入

我正在尝试将视频导入UWP画布。 我有这个代码,成功导入图片: 私人异步无效AddImageButton_Click(对象发件人,RoutedEventArgs e) { 图片MyImage = new Image();UWP视频导入

 var picker = new FileOpenPicker(); 

picker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;

picker.FileTypeFilter.Add(".jpg");

picker.FileTypeFilter.Add(".png");

StorageFile file = await picker.PickSingleFileAsync();

if (file != null)

{

StorageApplicationPermissions.FutureAccessList.AddOrReplace("PickedFolderToken", file);

// var files = await file.GetFilesAsync();

var bitmap = new BitmapImage();

var stream = await file.OpenReadAsync();

// AddHandler(, new ExceptionRoutedEventHandler(Bitmap_ImageFailed), true);

bitmap.ImageFailed += Bitmap_ImageFailed;

await bitmap.SetSourceAsync(stream);

MyImage.Source = bitmap;

AddHandler(ManipulationStartedEvent, new ManipulationStartedEventHandler(Image_ManipulationStarted), true);

AddHandler(ManipulationDeltaEvent, new ManipulationDeltaEventHandler(Image_ManipulationDelta), true);

AddHandler(ManipulationCompletedEvent, new ManipulationCompletedEventHandler(Image_ManipulationCompleted), true);

ManipulationMode = ManipulationModes.All;

MyImage.RenderTransform = ImageTransforms;

parentCanvas.Children.Add(MyImage);

}

}

我试着调整它来导入视频,但在将位图转换为MediaPlayerElement时卡住了。有什么建议么?

谢谢!

回答:

根据您上面添加图片到Canvas的代码,你可以试试下面的代码添加MediaPlayerElement到画布上,并使用FileOpenPicker到选择器中的媒体文件作为MediaPlayerElement的来源。您可以进行一些修改以满足您的要求。

private async void AddMediaPlayerElementButton_Click_1(object sender, RoutedEventArgs e) 

{

var picker = new FileOpenPicker();

picker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;

picker.FileTypeFilter.Add(".mp4");

StorageFile file = await picker.PickSingleFileAsync();

MediaPlayerElement mediaPlayer = new MediaPlayerElement() { AreTransportControlsEnabled = true };

if (file != null)

{

mediaPlayer.Source = MediaSource.CreateFromStorageFile(file);

}

parentCanvas.Children.Add(mediaPlayer);

}

以上是 UWP视频导入 的全部内容, 来源链接: utcz.com/qa/267080.html

回到顶部