Search code examples
c#.netuwpmedia-playerwindows-10-universal

DisplayProperties empty when creating a MediaPlaybackItem from file


I'm creating a playlist from files using the default MediaPlaybackItem constructor:

songs = a.OfType<StorageFile>().Select(o => new MediaPlaybackItem(MediaSource.CreateFromStorageFile(o))).ToList();

But for some reason this process doesn't preserve the file properties, which are rather important in case of a music playback software.

For reference:

// This works just fine
var prop = await (_a as StorageFile).Properties.GetMusicPropertiesAsync();
// This doesn't.
var item = new MediaPlaybackItem(MediaSource.CreateFromStorageFile((StorageFile)_a));
item.GetDisplayProperties().MusicProperties;

The DisplayProperties of an item, as well as MusicProperties attached to it are empty.

Is there any way to take care of that during the item creation or do I have to asynchronously assign properties after creating the item one by one?

foreach(var _a in a)
{
    var prop = await (_a as StorageFile).Properties.GetMusicPropertiesAsync();
    var item = new MediaPlaybackItem(MediaSource.CreateFromStorageFile((StorageFile)_a));
    var attached = item.GetDisplayProperties().MusicProperties;
    attached.AlbumArtist = prop.AlbumArtist;
    attached.AlbumTitle = prop.Album;
    // ...
    songs.Add(item);
}

Cheers!


Solution

  • For now, we can only programmatically provide metadata for media items by calling GetDisplayProperties(), setting the data of the returned MediaItemDisplayProperties, and then calling ApplyDisplayProperties(MediaItemDisplayProperties) like what you've done.

    But there is a new prerelease property named AutoLoadedDisplayProperties in MediaPlaybackItem. With setting this property, the system should automatically load metadata from the content to display in the System Media Transport Controls. However, please note Some information relates to pre-released product which may be substantially modified before it’s commercially released. Microsoft makes no warranties, express or implied, with respect to the information provided here.

    You are welcome to join Windows Insider and try the latest Insider Preview SDK.