Retrieving thumbnail of a StorageFile (Video&#

2019-06-26 01:59发布

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>

2条回答
乱世女痞
2楼-- · 2019-06-26 02:39

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();
        }
查看更多
爱情/是我丢掉的垃圾
3楼-- · 2019-06-26 02:43

This is a known issue with the platform. For files in the public directories the media service extracts the thumbnails as a part of tracking the files for the video app.

When the files are in the app data container, the storage code tries to extract the thumbnail using the system thumbnail providers which aren't present.

There isn't a good workaround other than to move the file to a public location, get the thumbnail, save it, and move the file back.

查看更多
登录 后发表回答