1

as you can see in the following code

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

in my uwp app I am trying to set the DisplayProperties to be shown in systemmediatransportcontrols of my mediaplaybackitem. I am able to set other properties, but when I try to set the thumbnail, I am getting a StorageItemThumbnail object from GetThumbnailAsync and I want to assign that to props.Thumbnail which is of type RandomAccessStreamReference so I am wondering how can I convert it to the required type.

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.

Muhammad Touseef
  • 4,357
  • 4
  • 31
  • 75

2 Answers2

3
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);
wosky
  • 31
  • 3
2

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

For what it's worth, as Thumbnails are actual RandomAccessStreams it's best to dispose of them when you're finished with them.

Johnny Westlake
  • 1,461
  • 10
  • 13
  • any tips on how I might do that? because I am actually using MediaPlaybackList and adding playbackitems to it, so do I have to dispose off the old thumbnail everytime the mediaplaybackitemchanges, within the playbacklist? @Johnny Westlake – Muhammad Touseef Apr 16 '18 at 14:04