예제 #1
0
        public void Connect()
        {
            if (!SpotifyLocalAPI.IsSpotifyRunning())
            {
                MessageBox.Show(@"Spotify isn't running!");
                return;
            }
            bool sukses;

            try { sukses = _spotify.Connect(); } catch { sukses = false; }
            if (sukses)
            {
                btnConnect.Text          = @"Sukses menyambungkan ke Spotify PC";
                btnConnect.Enabled       = false;
                _spotify.ListenForEvents = true;
                btnPlay.Enabled          = true;
                btnPause.Enabled         = true;
                SpotifyAPI.Local.Models.StatusResponse status = _spotify.GetStatus();
                if (status.Track != null)
                {
                    UpdateTrack(status.Track, "");
                }
            }
            else
            {
                DialogResult res = MessageBox.Show(@"Gagal menyambungkan ke Spotify PC. Coba lagi?", @"Spotify", MessageBoxButtons.YesNo);
                if (res == DialogResult.Yes)
                {
                    Connect();
                }
            }
        }
예제 #2
0
        private async void btnPlay_Click(object sender, EventArgs e)
        {
            string track = "";

            if (listView1.SelectedItems.Count > 0)
            {
                ListViewItem currentTrack = listView1.SelectedItems[0];
                track = currentTrack.SubItems[3].Text;
                currentTrack.Selected = false;
            }

            else if (listView3.SelectedItems.Count > 0)
            {
                ListViewItem currentTrack = listView3.SelectedItems[0];
                track = currentTrack.SubItems[3].Text;
                currentTrack.Selected = false;
            }

            else if (listView4.SelectedItems.Count > 0)
            {
                ListViewItem currentTrack = listView4.SelectedItems[0];
                track = currentTrack.SubItems[3].Text;
                currentTrack.Selected = false;
            }

            if (_currentUrlTrack != track)
            {
                await _spotify.PlayURL("https://open.spotify.com/track/" + track);

                SpotifyAPI.Local.Models.StatusResponse status = _spotify.GetStatus();
                if (status.Track != null)
                {
                    UpdateTrack(status.Track, track);
                }
            }
            else
            {
                await _spotify.Play();
            }
        }