Beispiel #1
0
        public async Task <TrackItem> GetTrackItemFromFile(StorageFile track, string token = null)
        {
            //TODO: Warning, is it safe to consider this a good idea?
            var trackItem = musicDatabase.LoadTrackFromPath(track.Path);

            if (trackItem != null)
            {
                return(trackItem);
            }

            MusicProperties trackInfos = null;

            try
            {
                trackInfos = await track.Properties.GetMusicPropertiesAsync();
            }
            catch
            {
            }
            trackItem = new TrackItem
            {
                ArtistName = (string.IsNullOrEmpty(trackInfos?.Artist)) ? Strings.UnknownArtist : trackInfos?.Artist,
                AlbumName  = trackInfos?.Album ?? Strings.UnknownAlbum,
                Name       = (string.IsNullOrEmpty(trackInfos?.Title)) ? track.DisplayName : trackInfos?.Title,
                Path       = track.Path,
                Duration   = trackInfos?.Duration ?? TimeSpan.Zero,
                File       = track,
            };
            if (!string.IsNullOrEmpty(token))
            {
                trackItem.Token = token;
            }
            return(trackItem);
        }