예제 #1
0
        private static async void ChooseMusicMood(SpotifyWebAPI api)
        {
            PrivateProfile profile = await api.GetPrivateProfileAsync();

            string name = string.IsNullOrEmpty(profile.DisplayName) ? profile.Id : profile.DisplayName;



            Console.WriteLine($"Hello there, {name}!");



            Console.WriteLine("Your playlists:");

            Paging <SimplePlaylist> playlists = await api.GetUserPlaylistsAsync(profile.Id);

            //do
            //{
            playlists.Items.ForEach(playlist =>
            {
                Console.WriteLine($"- {playlist.Name}");
            });

            PlaybackContext context = api.GetPlayback();

            if (context.IsPlaying)
            {
                Console.WriteLine($"You are listening {context.Item.Name}!");
            }

            Console.WriteLine("do you want to listen to music related to your mood ? (yes/no)");



            while (true)
            {
                string risposta = Console.ReadLine();

                if (risposta.Equals("Y") || risposta.Equals("yes") || risposta.Equals("y") || risposta.Equals("YES"))
                {
                    Console.WriteLine("Yes");
                    List <FullPlaylist> Playlists = new List <FullPlaylist>();
                    Console.WriteLine("choose your playlists to play according to your mood.");
                    Thread.Sleep(2000);
                    Console.WriteLine("type 1 to use default playlists ");
                    Console.WriteLine("type 2 to load your own playlists");
                    Console.WriteLine("type 3 to create your own playlists");


                    //string line = Console.ReadLine();
                    // switch (line)
                    //{


                    // case "1":
                    //    Playlists = PlayMusic.GetPlaylists(api);
                    //    Console.WriteLine("press enter when you are ready");
                    //    Console.ReadLine();
                    //    break;


                    //case "2":
                    //Console.WriteLine("Please enter the Uri of yours playlists you want to load");
                    //Playlists = PlayMusic.LoadPlaylists(api);
                    //        Console.WriteLine("press enter when you are ready");
                    //        Console.ReadLine();
                    //        break;


                    //    case "3":
                    //        Playlists = PlayMusic.CreatePLaylists(api);
                    //        Console.WriteLine("press enter when you are ready");
                    //        Console.ReadLine();
                    //        break;

                    //    default:
                    //        Console.WriteLine("Enter 1 2 or a 3");
                    //        break;


                    //}



                    while (true)

                    {
                        string mode = Console.ReadLine();

                        if (mode.Equals("1"))
                        {
                            Playlists = PlayMusic.GetPlaylists(api);

                            break;
                        }

                        else if (mode.Equals("2"))
                        {
                            Console.WriteLine("Please enter the Uri of yours playlists you want to load");
                            Playlists = PlayMusic.LoadPlaylists(api);

                            break;
                        }

                        else if (mode.Equals("3"))
                        {
                            Playlists = PlayMusic.CreatePLaylists(api);

                            break;
                        }
                        else
                        {
                            Console.WriteLine("Enter 1,2 or 3 please");
                        }
                    }



                    FullPlaylist PlaylistMood = PlayMusic.GetPlaylistMood(Playlists);
                    Console.WriteLine("Let's me choose a song for you:");
                    PlayMusic.ChangePlayback(api, PlaylistMood);
                    PlaybackContext context2 = api.GetPlayback();

                    Console.WriteLine($"You are listening {context2.Item.Name} now!");

                    PlayMusic.ManagePlayback(api);



                    Thread.Sleep(1000);

                    //Prog.Unsubscribe();



                    break;
                }
                else if (risposta.Equals("N") || risposta.Equals("NO") || risposta.Equals("n") || risposta.Equals("no"))
                {
                    Console.WriteLine("No");
                    Console.WriteLine("Ok, enjoy your song ");
                    break;
                }

                else
                {
                    Console.WriteLine("Enter yes or no please");
                }
            }



            Console.WriteLine("Thanks for trying the App");
        }