public IEnumerator LoadChartTracks()
    {
        yield return(new WaitForSeconds(2));

        if (chartTracks == null || chartTracks.Count == 0)
        {
            Debug.LogError("Chart tracks is null/empty");
        }
        else
        {
            for (int i = 0; i < meshRenderers.Length; i++)
            {
                //i+1 because first row is header names
                ChartTrack chartTrack = (ChartTrack)chartTracks[i + 1];
                FullTrack  fullTrack  = spotifyManagerScript.GetTrack(chartTrack.apiUrl);

                if (fullTrack.HasError())
                {
                    Debug.LogError(fullTrack.Error.Status);
                    Debug.LogError(fullTrack.Error.Message);
                }
                else
                {
                    string chartTrackImageURL = fullTrack.Album.Images[0].Url;

                    GameObject meshRendererGameObject = meshRenderers[i].transform.gameObject;

                    PlaylistScript playlistScript = meshRendererGameObject.GetComponent <PlaylistScript>();

                    WWW imageURLWWW = new WWW(chartTrackImageURL);

                    yield return(imageURLWWW);

                    meshRenderers[i].material.mainTexture = imageURLWWW.texture;

                    AudioAnalysis audioAnalysis = spotifyManagerScript.GetAudioAnalysis(fullTrack.Id);

                    playlistScript.setFullTrack(fullTrack);
                    playlistScript.setPlaylistName(fullTrack.Name);
                    playlistScript.setPlaylistURI(fullTrack.Uri);
                    playlistScript.artistId            = fullTrack.Artists[0].Id;
                    playlistScript.artistName          = fullTrack.Artists[0].Name;
                    playlistScript.sprite              = ConvertWWWToSprite(imageURLWWW);
                    playlistScript.audioAnalysis       = audioAnalysis;
                    playlistScript.audioAnalysisCustom = new AudioAnalysisCustom(audioAnalysis);
                    playlistScript.trackId             = fullTrack.Id;
                    playlistScript.streams             = chartTrack.streams;
                    saveLoad.SaveTextureToFilePNG(Converter.ConvertWWWToTexture(imageURLWWW), "chartTrack" + i + ".png");
                    saveLoad.savedChartTracks.Add(new PlaylistScriptData(playlistScript));

                    Vector3 v = popCubes[i].transform.localScale;

                    if (chartTrack.streams != null)
                    {
                        popCubes[i].transform.localScale = new Vector3(v.x, float.Parse(chartTrack.streams) * streamsScaling, v.z);
                    }
                }
            }
        }
    }
Beispiel #2
0
    public IEnumerator LoadRecentlyPlayed()
    {
        yield return(new WaitForSeconds(2));

        recentlyPlayed = spotifyManagerScript.GetRecentlyPlayed();

        if (recentlyPlayed == null || recentlyPlayed.Items.Count == 0)
        {
            Debug.LogError("recentlyPlayed is null/empty");
        }
        else
        {
            for (int i = 0; i < meshRenderers.Length; i++)
            {
                FullTrack fullTrack = spotifyManagerScript.GetTrack(recentlyPlayed.Items[i].Track.Id);

                string recentlyPlayedImageURL = null;

                if (fullTrack.Album.Images.Count != 0)
                {
                    recentlyPlayedImageURL = fullTrack.Album.Images[0].Url;
                }

                GameObject meshRendererGameObject = meshRenderers[i].transform.gameObject;

                PlaylistScript playlistScript = meshRendererGameObject.GetComponent <PlaylistScript>();

                WWW imageURLWWW = null;

                if (recentlyPlayedImageURL != null)
                {
                    imageURLWWW = new WWW(recentlyPlayedImageURL);

                    yield return(imageURLWWW);

                    meshRenderers[i].material.mainTexture = imageURLWWW.texture;
                }


                AudioAnalysis audioAnalysis = spotifyManagerScript.GetAudioAnalysis(recentlyPlayed.Items[i].Track.Id);

                playlistScript.setPlaylistName(recentlyPlayed.Items[i].Track.Name);
                playlistScript.trackType = PlaylistScript.TrackType.track;
                playlistScript.setPlaylistURI(recentlyPlayed.Items[i].Track.Uri);
                playlistScript.artistId      = recentlyPlayed.Items[i].Track.Artists[0].Id;
                playlistScript.trackId       = recentlyPlayed.Items[i].Track.Id;
                playlistScript.audioAnalysis = audioAnalysis;

                if (imageURLWWW != null)
                {
                    playlistScript.www    = imageURLWWW;
                    playlistScript.sprite = Converter.ConvertWWWToSprite(imageURLWWW);
                    saveLoad.SaveTextureToFilePNG(Converter.ConvertWWWToTexture(imageURLWWW), "recentlyPlayed" + i + ".png");
                }

                playlistScript.audioAnalysisCustom = new AudioAnalysisCustom(audioAnalysis);
                saveLoad.savedRecentlyPlayed.Add(new PlaylistScriptData(playlistScript));
            }
        }
    }
    public IEnumerator loadTopTracks()
    {
        yield return(new WaitForSeconds(2));

        usersTopTracks = spotifyManagerScript.GetUsersTopTracks();
        if (usersTopTracks == null || usersTopTracks.Items.Count == 0)
        {
            Debug.LogError("usersTopTracks is null/empty");
        }
        else
        {
            for (int i = 0; i < meshRenderers.Length; i++)
            {
                string topTrackImageURL = null;

                if (usersTopTracks.Items[i].Album.Images.Count != 0)
                {
                    topTrackImageURL = usersTopTracks.Items[i].Album.Images[0].Url;
                }

                GameObject meshRendererGameObject = meshRenderers[i].transform.gameObject;

                PlaylistScript playlistScript = meshRendererGameObject.GetComponent <PlaylistScript>();

                WWW imageURLWWW = null;

                if (topTrackImageURL != null)
                {
                    imageURLWWW = new WWW(topTrackImageURL);

                    yield return(imageURLWWW);

                    meshRenderers[i].material.mainTexture = imageURLWWW.texture;
                }

                AudioAnalysis audioAnalysis = spotifyManagerScript.GetAudioAnalysis(usersTopTracks.Items[i].Id);

                playlistScript.setPlaylistName(usersTopTracks.Items[i].Name);
                playlistScript.setPlaylistURI(usersTopTracks.Items[i].Uri);
                playlistScript.setFullTrack(usersTopTracks.Items[i]);
                playlistScript.audioAnalysis = audioAnalysis;

                if (imageURLWWW != null)
                {
                    playlistScript.www    = imageURLWWW;
                    playlistScript.sprite = ConvertWWWToSprite(imageURLWWW);
                    saveLoad.SaveTextureToFilePNG(ConvertWWWToTexture(imageURLWWW), "topTrack" + i + ".png");
                }

                playlistScript.trackId             = usersTopTracks.Items[i].Id;
                playlistScript.audioAnalysisCustom =
                    new AudioAnalysisCustom(audioAnalysis);
                saveLoad.savedTopTracks.Add(new PlaylistScriptData(playlistScript));
            }
            // yield return new WaitForSeconds(saveLoad.saveTime);
            // saveLoad.Save();
        }
    }
Beispiel #4
0
    public IEnumerator LoadUsersFollowedArtists()
    {
        yield return(new WaitForSeconds(2));

        FollowedArtists followedArtists = spotifyManagerScript.GetUsersFollowedArtists();

        if (followedArtists == null || followedArtists.Artists.Items.Count == 0)
        {
            Debug.LogError("followedArtists is null/empty");
        }
        else
        {
            for (int i = 0; i < meshRenderers.Length; i++)
            {
                string followedArtistsImageURL = null;

                if (followedArtists.Artists.Items[i].Images.Count > 0)
                {
                    followedArtistsImageURL = followedArtists.Artists.Items[i].Images[0].Url;
                }

                GameObject meshRendererGameObject = meshRenderers[i].transform.gameObject;

                PlaylistScript playlistScript = meshRendererGameObject.GetComponent <PlaylistScript>();

                WWW imageURLWWW = null;

                if (followedArtistsImageURL != null)
                {
                    imageURLWWW = new WWW(followedArtistsImageURL);

                    yield return(imageURLWWW);

                    meshRenderers[i].material.mainTexture = imageURLWWW.texture;
                }

                playlistScript.setPlaylistName(followedArtists.Artists.Items[i].Name);
                playlistScript.setPlaylistURI(followedArtists.Artists.Items[i].Uri);
                playlistScript.fullArtist = followedArtists.Artists.Items[i];
                SeveralTracks artistTopTracks = spotifyManagerScript.GetArtistsTopTracks(followedArtists.Artists.Items[i].Id);
                playlistScript.audioAnalysisCustom = new AudioAnalysisCustom(spotifyManagerScript.GetAudioAnalysis(artistTopTracks.Tracks[0].Id));

                if (imageURLWWW != null)
                {
                    playlistScript.sprite = ConvertWWWToSprite(imageURLWWW);
                    saveLoad.SaveTextureToFilePNG(Converter.ConvertWWWToTexture(imageURLWWW), "userFollowedArtist" + i + ".png");
                }

                playlistScript.artistId = followedArtists.Artists.Items[i].Id;
                saveLoad.savedUserFollowedArtists.Add(new PlaylistScriptData(playlistScript));
            }
        }
    }
Beispiel #5
0
    public IEnumerator Test_Spotify_GetAudioAnalysis()
    {
        Spotify spotify = new Spotify();

        spotify.TestSetup();

        //Opps
        string trackId = "0Pw6Gg8QChw5iSRRSrcWXP";

        AudioAnalysis audioAnalysis = spotify.GetAudioAnalysis(trackId);

        yield return(null);

        Debug.Log(audioAnalysis.ToString());

        Assert.IsFalse(audioAnalysis.HasError());
    }
    public IEnumerator loadTopArtists()
    {
        yield return(new WaitForSeconds(2));

        usersTopArtists = spotifyManagerScript.GetUsersTopArtists();
        if (usersTopArtists == null)
        {
            Debug.LogError("usersTopArtists is null");
        }
        else
        {
            for (int i = 0; i < meshRenderers.Length; i++)
            {
                string featuredPlaylistImageURL = usersTopArtists.Items[i].Images[0].Url;

                GameObject meshRendererGameObject = meshRenderers[i].transform.gameObject;

                PlaylistScript playlistScript = meshRendererGameObject.GetComponent <PlaylistScript>();

                WWW imageURLWWW = new WWW(featuredPlaylistImageURL);

                yield return(imageURLWWW);

                meshRenderers[i].material.mainTexture = imageURLWWW.texture;

                playlistScript.setPlaylistName(usersTopArtists.Items[i].Name);
                playlistScript.setPlaylistURI(usersTopArtists.Items[i].Uri);
                playlistScript.fullArtist = usersTopArtists.Items[i];
                playlistScript.artistId   = usersTopArtists.Items[i].Id;
                playlistScript.sprite     = ConvertWWWToSprite(imageURLWWW);
                SeveralTracks artistTopTracks = spotifyManagerScript.GetArtistsTopTracks(usersTopArtists.Items[i].Id);
                playlistScript.audioAnalysisCustom = new AudioAnalysisCustom(spotifyManagerScript.GetAudioAnalysis(artistTopTracks.Tracks[0].Id));
                saveLoad.SaveTextureToFilePNG(ConvertWWWToTexture(imageURLWWW), "topArtist" + i + ".png");
                saveLoad.savedTopArtists.Add(new PlaylistScriptData(playlistScript));
            }
        }
    }