Justice
Justice

Reputation: 442

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

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>

Upvotes: 4

Views: 2926

Answers (2)

Samee Mir
Samee Mir

Reputation: 145

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

Upvotes: 1

Adam
Adam

Reputation: 982

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.

Upvotes: 0

Related Questions