private async void PlayingItemChanged(IPlayableItem newPlayingItem) { if (newPlayingItem == null) { // No new item playing, reset UI UpdatePlayerInfo("No track playing", "No track playing", ""); SetLibraryBtnIsLiked(false); _currentProgressSlider.value = 0; _totalProgressText.text = _currentProgressText.text = "00:00"; } else { if (newPlayingItem.Type == ItemType.Track) { if (newPlayingItem is FullTrack track) { // Update player information with track info string allArtists = S4UUtility.ArtistsToSeparatedString(", ", track.Artists); SpotifyAPI.Web.Image image = S4UUtility.GetLowestResolutionImage(track.Album.Images); UpdatePlayerInfo(track.Name, allArtists, image?.Url); // Make request to see if track is part of user's library var client = SpotifyService.Instance.GetSpotifyClient(); LibraryCheckTracksRequest request = new LibraryCheckTracksRequest(new List <string>() { track.Id }); var result = await client.Library.CheckTracks(request); if (result.Count > 0) { SetLibraryBtnIsLiked(result[0]); } } } else if (newPlayingItem.Type == ItemType.Episode) { if (newPlayingItem is FullEpisode episode) { string creators = episode.Show.Publisher; SpotifyAPI.Web.Image image = S4UUtility.GetLowestResolutionImage(episode.Images); UpdatePlayerInfo(episode.Name, creators, image?.Url); } } } }
private void UpdateUI() { if (_track != null) { if (_trackNameText != null) { _trackNameText.text = _track.Name; } if (_trackArtistsText != null) { _trackArtistsText.text = S4UUtility.ArtistsToSeparatedString(", ", _track.Artists); } if (_albumText != null) { _albumText.text = _track.Album.Name; } if (_durationText != null) { _durationText.text = S4UUtility.MsToTimeString(_track.DurationMs); } } }
private void UpdateUI() { if (_name != null) { _name.text = _track.Name; } if (_artist != null) { _artist.text = S4UUtility.ArtistsToSeparatedString(", ", _track.Artists); } if (_duration != null) { _duration.text = S4UUtility.MsToTimeString(_track.DurationMs); } if (_playBtn != null) { _playBtn.onClick.AddListener(() => { var client = SpotifyService.Instance.GetSpotifyClient(); if (client != null) { PlayerResumePlaybackRequest request = new PlayerResumePlaybackRequest() { //ContextUri = , // Play within context of just the individual track Uris = new List <string>() { _track.Uri }, }; client.Player.ResumePlayback(request); Debug.Log($"Spotify App | Playing searched song '{S4UUtility.ArtistsToSeparatedString(", ", _track.Artists)} - {_track.Name}'"); } }); } }
private void LogTrackChange(string source) { Debug.Log($"Spotify App | {source} '{S4UUtility.ArtistsToSeparatedString(", ", _track.Artists)} - {_track.Name}'"); }
/// <summary> /// Gets a string to display a song and it's properties, separated with a dash. For example, "BLACKPINK - Don't Know What To Do" /// </summary> /// <param name="currentTrack"></param> /// <returns></returns> public static string GetTrackString(FullTrack track) { string artists = S4UUtility.ArtistsToSeparatedString(",", track.Artists); return(artists + " - " + track.Name); }