微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

c# – 检索位于WP8.1中应用程序的本地文件夹中的StorageFile(视频)的缩略图

我正在尝试将ApplicationFile的缩略图放在应用程序的应用程序包(LocalFolder)中.存储文件是媒体文件,可以是图像(jpg或png)或视频(mp4或wmv).现在,当我尝试使用StorageFile类的GetThumbnailAsync(ThumbnailMode)方法获取缩略图时,我得到了

System.Exception : The component cannot be found.

错误,如果文件是图像或不在应用程序包内的视频,同样的工作正常.这是我正在使用的代码隐藏

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;
        }
    }

这是它的xaml

<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>

解决方法

我知道这是一个老问题,但它会帮助任何仍在寻找解决方案的人.

下面是我能够在经过3个小时的奋斗之后成功运行的代码,以及它的工作原理.

using (VideoFrameReader videoFrameReader = new VideoFrameReader(newCreatedVideo))
        {
            await videoFrameReader.OpenMF();
            var image = videoFrameReader.GetFrameAsBitmap(TimeSpan.FromSeconds(0));

            videoFrameReader.Finalize();
        }

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐