簡體   English   中英

檢索位於WP8.1中應用程序的本地文件夾中的StorageFile(視頻)的縮略圖

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

我正在嘗試將ApplicationFile的縮略圖放在應用程序的應用程序包(LocalFolder)中。 存儲文件是媒體文件,可以是圖像(jpg或png)或視頻(mp4或wmv)。 現在,當我嘗試使用StorageFile類的GetThumbnailAsync(ThumbnailMode)方法獲取縮略圖時,我得到了

System.Exception:找不到該組件。

錯誤,如果文件是圖像或不在應用程序包內的視頻,同樣的工作正常。 這是我正在使用的代碼隱藏

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

這是該平台的已知問題。 對於公共目錄中的文件,媒體服務提取縮略圖作為跟蹤視頻應用程序的文件的一部分。

當文件位於應用程序數據容器中時,存儲代碼會嘗試使用不存在的系統縮略圖提供程序提取縮略圖。

除了將文件移動到公共位置,獲取縮略圖,保存並移回文件之外,沒有其他好的解決方法。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM