Example #1
0
 private void trackChanged(object sender, AudioChangeArgs e)
 {
     if (e.getPlayback().Item != null)
     {
         PlaybackContext track = e.getPlayback();
         pictureBox1.Load(track.Item.Album.Images[0].Url);
         WriteTextSafe(track.Item.Name);
         try
         {
             ArduinoInterface.sendFromImageUrl(track.Item.Album.Images[0].Url);
             ArduinoInterface.sendPlay(track.ProgressMs * 1000, track.Item.DurationMs * 1000);
         }
         catch (Exception ee)
         {
             RefreshButton.Visible = true;
         }
     }
     else
     {
         pictureBox1.Image = Properties.Resources.NoSong;
         WriteTextSafe("No Song Playing");
         try {
             ArduinoInterface.sendImage(Properties.Resources.NoSong);
             ArduinoInterface.sendPause(0, 0);
         }
         catch (Exception ee)
         {
             RefreshButton.Visible = true;
         }
     }
 }
Example #2
0
 private void RefreshButton_Click(object sender, EventArgs e)
 {
     if (ArduinoInterface.retryConnection())
     {
         RefreshButton.Visible = false;
         ConnectionLabel.Text  = ArduinoInterface.DeviceInfo.Item1;
         ArduinoInterface.BeginSerial();
     }
 }
Example #3
0
        private async void spotifyDataLoop()
        {
            connected = true;
            bool playbackState = false;

            while (true)
            {
                if (token.IsExpired())
                {
                    token = await auth.RefreshToken(token.RefreshToken);

                    api.AccessToken = token.AccessToken;
                    api.TokenType   = token.TokenType;
                }
                var playback = api.GetPlayingTrack();
                if (playback.HasError())
                {
                    Console.WriteLine(playback.Error.Message);
                }
                else if (playback.Item == null)
                {
                    if (currentlyPlaying != "")
                    {
                        currentlyPlaying = "";
                        OnAudioChange(this, new AudioChangeArgs(playback));
                        //picture.Image = Properties.Resources.NoSong;
                        //playingLabel.Text = currentlyPlaying;
                    }
                }
                else if (currentlyPlaying != playback.Item.Id)
                {
                    Console.WriteLine(playback.Item.Name + " " + playback.Item.PreviewUrl);
                    currentlyPlaying = playback.Item.Id;
                    OnAudioChange(this, new AudioChangeArgs(playback));
                }
                if (playback.IsPlaying != playbackState)
                {
                    if (playback.IsPlaying)
                    {
                        ArduinoInterface.sendPlay(playback.ProgressMs, playback.Item.DurationMs);
                    }
                    else
                    {
                        ArduinoInterface.sendPause(playback.ProgressMs, playback.Item.DurationMs);
                    }
                }


                playbackState = playback.IsPlaying;
                Thread.Sleep(1000);
            }
        }
Example #4
0
 public static void pausePlay()
 {
     if (isPlaying())
     {
         api.PausePlayback();
         ArduinoInterface.sendPause(api.GetPlayback().ProgressMs, api.GetPlayback().Item.DurationMs);
     }
     else
     {
         api.ResumePlayback(offset: "");
         ArduinoInterface.sendPlay(api.GetPlayback().ProgressMs, api.GetPlayback().Item.DurationMs);
     }
 }
Example #5
0
        public UI()
        {
            InitializeComponent();
            setupCustomFont();
            SpotifyLoad spotify = new SpotifyLoad();

            spotify.OnAudioChange += trackChanged;

            ArduinoInterface arduinoInterface = new ArduinoInterface();
            AudioPassthrough ap = new AudioPassthrough();

            if (arduinoInterface.hasError)
            {
                RefreshButton.Visible = true;
            }
            else
            {
                ArduinoInterface.BeginSerial();
                ConnectionLabel.Text = ArduinoInterface.DeviceInfo.Item1;
            }
        }