public void FinishedLoading(PlayerQueueEntry entry, TrackOrEpisode metadata) { Debug.WriteLine("{0} finished loading.", entry); if (entry == queue.Head) { listener.FinishedLoading(metadata); } }
private async Task Load(bool preloaded, int initialSeek) { try { var j = await sink.Load(Playable, preloaded, this, initialSeek); Metadata = new TrackOrEpisode(j.track, j.episode); switch (Playable.Type) { case SpotifyType.Episode: Debug.WriteLine("Loaded episode. name: '{0}', uri: {1}, id: {2}", j.episode.Name, Playable.Uri, PlaybackId); break; case SpotifyType.Track: Debug.WriteLine("Loaded track. name: '{0}', uri: {1}, id: {2}", j.track.Name, Playable.Uri, PlaybackId); break; } if (initialSeek != -1) { sink.Position = TimeSpan.FromMilliseconds(initialSeek); seekTime = -1; } listener.FinishedLoading(this, Metadata); } catch (Exception x) { Dispose(); listener.LoadingError(this, x, Retried); Debug.WriteLine("{0} terminated at loading. " + x.ToString(), this); return; } }
public void EnrichWithMetadata([NotNull] TrackOrEpisode metadata) { if (metadata.track != null) { var track = metadata.track; GuardAgainst.ArgumentBeingNull(ConnectState.Track); if (track.HasDuration) { TracksKeeper.UpdateTrackDuration(track.Duration); } var b = ConnectState.Track; if (track.HasPopularity) { b.Metadata["popularity"] = track.Popularity.ToString(); } if (track.HasExplicit) { b.Metadata["is_explicit"] = track.Explicit.ToString().ToLower(); } if (track.HasName) { b.Metadata["title"] = track.Name; } if (track.HasDiscNumber) { b.Metadata["album_disc_number"] = track.DiscNumber.ToString(); } for (var i = 0; i < track.Artist.Count; i++) { var artist = track.Artist[i]; if (artist.HasName) { b.Metadata["artist_name" + (i == 0 ? "" : (":" + i))] = artist.Name; } if (artist.HasGid) { b.Metadata["artist_uri" + (i == 0 ? "" : (":" + i))] = new ArtistId(Utils.bytesToHex(artist.Gid.ToByteArray())).Uri; } } if (track.Album != null) { var album = track.Album; if (album.Disc.Count > 0) { b.Metadata["album_track_count"] = album.Disc.Select(z => z.Track).Count().ToString(); b.Metadata["album_disc_count"] = album.Disc.Count.ToString(); } if (album.HasName) { b.Metadata["album_title"] = album.Name; } if (album.HasGid) { b.Metadata["album_uri"] = AlbumId.FromHex(Utils.bytesToHex(album.Gid.ToByteArray())).Uri; } for (int i = 0; i < album.Artist.Count; i++) { var artist = album.Artist[i]; if (artist.HasName) { b.Metadata["album_artist_name" + (i == 0 ? "" : (":" + i))] = artist.Name; } if (artist.HasGid) { b.Metadata["album_artist_uri" + (i == 0 ? "" : (":" + i))] = ArtistId.FromHex(Utils.bytesToHex(artist.Gid.ToByteArray())).Uri; } } if (track.HasDiscNumber) { b.Metadata["album_track_number"] = album.Disc.SelectMany(z => z.Track).ToList().FindIndex(k => k.Gid == track.Gid) + 1.ToString(); } if (album.CoverGroup?.Image != null && album.CoverGroup.Image.Count > 0) { ImageId.PutAsMetadata(b, album.CoverGroup); } } var k = new JArray(); foreach (var j in track.File .Where(z => z.HasFormat)) { k.Add(j.Format.ToString()); } b.Metadata["available_file_formats"] = k.ToString(); ConnectState.Track = b; } }