uwp 将 StorageItemThumbnail 转换为 RandomAccessStreamReference

uwp converting StorageItemThumbnail to RandomAccessStreamReference

如下代码所示

var mediaPlaybackItem = new MediaPlaybackItem(MediaSource.CreateFromStorageFile(myVideoFile));
MediaItemDisplayProperties props = mediaPlaybackItem.GetDisplayProperties();
props.Type = Windows.Media.MediaPlaybackType.Video;
props.VideoProperties.Title = CurrentVideo.MyVideoFile.DisplayName;
props.Thumbnail = (await CurrentVideo.MyVideoFile.GetThumbnailAsync(ThumbnailMode.VideosView));
mediaPlaybackItem.ApplyDisplayProperties(props);

在我的 uwp 应用程序中,我正在尝试将 DisplayProperties 设置为显示在 systemmediatransportcontrols 我的 mediaplaybackitem。我可以设置其他属性,但是当我尝试设置缩略图时,我从 GetThumbnailAsync 得到一个 StorageItemThumbnail 对象,我想将它分配给 props.ThumbnailRandomAccessStreamReference 类型所以我想知道如何将它转换为所需的类型。

systemmedia transport controls do have a method to update the thumbnail by copying the metadata automatically from the file. but in my scenario I am updating the display properties with my mediaplaybackitem the docs do show how to update the title as I am doing here, but they don't show how to update the thumbnail. also when the media opens I don't have acces to storagefile object, that is why I want to set the display properties on the mediaPlayBackItem object so it can manage automatically whenever the source of my media changes.

var thumb = await CurrentVideo.MyVideoFile.GetThumbnailAsync(ThumbnailMode.VideosView); props.Thumbnail = RandomAccessStreamReference.CreateFromStream(thumb);

就其价值而言,由于缩略图是实际的 RandomAccessStreams,因此最好在用完后将其丢弃。

using Windows.Media;
using Windows.Storage;
using Windows.Storage.Streams;
....
SystemMediaTransportControlsDisplayUpdater updater = _systemMediaTransportControls.DisplayUpdater;
....
_ImagePath = @"c:\temp\img.jpg";
StorageFile file2 = await StorageFile.GetFileFromPathAsync(_ImagePath);
updater.Thumbnail = RandomAccessStreamReference.CreateFromFile(file2);