Retrieving thumbnail of a StorageFile (Video) which is located in the localfolder of the app in WP8.1

混江龙づ霸主 提交于 2019-12-23 15:07:23

问题


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>

回答1:


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



回答2:


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.



来源:https://stackoverflow.com/questions/24177962/retrieving-thumbnail-of-a-storagefile-video-which-is-located-in-the-localfolde

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!