检索StorageFile(视频)的缩略图是位于WP8.1应用的localfolder [英] Retrieving thumbnail of a StorageFile (Video) which is located in the localfolder of the app in WP8.1
问题描述
我试图让位于应用程序的应用程序包(LocalFolder)内StorageFile的缩略图。存储文件是一个媒体文件可以是图片(JPG或PNG)或视频(MP4或WMV)。现在,当我尝试使用StorageFile类我得到一个
的System.Exception的GetThumbnailAsync(ThumbnailMode)方法来获得缩略图:该组件不能被发现。
块引用>
错误,而同样的事情,工作正常,如果该文件是图像或视频这不是应用程序包内。下面是我使用
StorageFile文件代码隐藏;
私人异步无效BtnGetVideo_Click(对象发件人,RoutedEventArgs E)
{
StorageFolder文件夹=等待Windows.ApplicationModel.Package.Current.InstalledLocation.GetFolderAsync(Assets\\TestImgs);
档=等待folder.GetFileAsync(SMTest.mp4);
}
私人异步无效BtnGetThumb_Click(对象发件人,RoutedEventArgs E)
{
如果(文件!= NULL)
{
的BitmapImage图像=新的BitmapImage();
image.SetSource(等待file.GetThumbnailAsync(ThumbnailMode.VideosView));
ImagePreview.Source =图像;
}
}
和这里是XAML吧
< StackPanel中的HorizontalAlignment =中心VerticalAlignment =中心>
<按钮X:NAME =BtnGetVideoCONTENT =获取本地视频点击=BtnGetVideo_Click/>
<按钮X:NAME =BtnGetThumbCONTENT =获取缩略图点击=BtnGetThumb_Click/>
<图像X:NAME =ImagePreviewHEIGHT =200/>
< / StackPanel的>
解决方案我知道它的一个老问题,但它会帮助任何人仍在寻找解决方案。
下面是我能够一3小时斗争后成功运行的代码,它的工作。
使用(videoFrameReader videoFrameReader =新videoFrameReader(newCreatedVideo))
{
等待videoFrameReader.OpenMF();
VAR图像= videoFrameReader.GetFrameAsBitmap(TimeSpan.FromSeconds(0));
videoFrameReader.Finalize();
}
I'm trying to get the thumbnail of the StorageFile located inside the application package (LocalFolder) of the app. The storage file is a media file which can be image(jpg or png) or a video (mp4 or wmv). Now when i try to get the thumbnail using GetThumbnailAsync(ThumbnailMode) method of the StorageFile class i get a
System.Exception : The component cannot be found.
error, while the same thing works fine if the file is image or a video which is not inside the app package. Here is the codebehind i'm using
StorageFile file; private async void BtnGetVideo_Click(object sender, RoutedEventArgs e) { StorageFolder folder = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFolderAsync("Assets\\TestImgs"); file = await folder.GetFileAsync("SMTest.mp4"); } private async void BtnGetThumb_Click(object sender, RoutedEventArgs e) { if (file != null) { BitmapImage image = new BitmapImage(); image.SetSource(await file.GetThumbnailAsync(ThumbnailMode.VideosView)); ImagePreview.Source = image; } }
and here is the xaml for it
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center"> <Button x:Name="BtnGetVideo" Content="Get a Local Video" Click="BtnGetVideo_Click"/> <Button x:Name="BtnGetThumb" Content="Get Thumbnails" Click="BtnGetThumb_Click"/> <Image x:Name="ImagePreview" Height="200"/> </StackPanel>
解决方案I know its an old problem, but it will help anyone still searching for solution.
Below is the code I am able to run successfully after a 3 hours of struggle, and its working.
using (VideoFrameReader videoFrameReader = new VideoFrameReader(newCreatedVideo)) { await videoFrameReader.OpenMF(); var image = videoFrameReader.GetFrameAsBitmap(TimeSpan.FromSeconds(0)); videoFrameReader.Finalize(); }
这篇关于检索StorageFile(视频)的缩略图是位于WP8.1应用的localfolder的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!