diff --git a/MiniSpotify/MiniSpotify/Assets/Images/Icons/Logo/NoteM.ico b/MiniSpotify/MiniSpotify/Assets/Images/Icons/Logo/NoteM.ico new file mode 100644 index 0000000..9b06e4c Binary files /dev/null and b/MiniSpotify/MiniSpotify/Assets/Images/Icons/Logo/NoteM.ico differ diff --git a/MiniSpotify/MiniSpotify/Assets/Images/Icons/Logo/NoteM.png b/MiniSpotify/MiniSpotify/Assets/Images/Icons/Logo/NoteM.png new file mode 100644 index 0000000..8a9bd05 Binary files /dev/null and b/MiniSpotify/MiniSpotify/Assets/Images/Icons/Logo/NoteM.png differ diff --git a/MiniSpotify/MiniSpotify/Assets/Images/Icons/Logo/NoteM.psd b/MiniSpotify/MiniSpotify/Assets/Images/Icons/Logo/NoteM.psd new file mode 100644 index 0000000..4800c9e Binary files /dev/null and b/MiniSpotify/MiniSpotify/Assets/Images/Icons/Logo/NoteM.psd differ diff --git a/MiniSpotify/MiniSpotify/Assets/Images/Icons/Logo/NoteMW.ico b/MiniSpotify/MiniSpotify/Assets/Images/Icons/Logo/NoteMW.ico new file mode 100644 index 0000000..3a9b51f Binary files /dev/null and b/MiniSpotify/MiniSpotify/Assets/Images/Icons/Logo/NoteMW.ico differ diff --git a/MiniSpotify/MiniSpotify/Assets/Images/Icons/Logo/NoteMW.png b/MiniSpotify/MiniSpotify/Assets/Images/Icons/Logo/NoteMW.png new file mode 100644 index 0000000..7c6240f Binary files /dev/null and b/MiniSpotify/MiniSpotify/Assets/Images/Icons/Logo/NoteMW.png differ diff --git a/MiniSpotify/MiniSpotify/EditorWindow.xaml b/MiniSpotify/MiniSpotify/EditorWindow.xaml new file mode 100644 index 0000000..d28394a --- /dev/null +++ b/MiniSpotify/MiniSpotify/EditorWindow.xaml @@ -0,0 +1,14 @@ + + + + + diff --git a/MiniSpotify/MiniSpotify/EditorWindow.xaml.cs b/MiniSpotify/MiniSpotify/EditorWindow.xaml.cs new file mode 100644 index 0000000..095a5b7 --- /dev/null +++ b/MiniSpotify/MiniSpotify/EditorWindow.xaml.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Shapes; + +namespace MiniSpotify +{ + /// + /// Interaction logic for EditorWindow.xaml + /// + public partial class EditorWindow : Window + { + public EditorWindow() + { + InitializeComponent(); + } + } +} diff --git a/MiniSpotify/MiniSpotify/MainWindow.xaml b/MiniSpotify/MiniSpotify/MainWindow.xaml index db0b9af..995def9 100644 --- a/MiniSpotify/MiniSpotify/MainWindow.xaml +++ b/MiniSpotify/MiniSpotify/MainWindow.xaml @@ -55,7 +55,7 @@ - + - + + diff --git a/MiniSpotify/MiniSpotify/MainWindow.xaml.cs b/MiniSpotify/MiniSpotify/MainWindow.xaml.cs index f5dbef2..14435b0 100644 --- a/MiniSpotify/MiniSpotify/MainWindow.xaml.cs +++ b/MiniSpotify/MiniSpotify/MainWindow.xaml.cs @@ -21,13 +21,22 @@ public partial class MainWindow : Window { private bool m_pinnedToTop = true; + private bool m_editWindowOpen = false; + private double m_editWindowGap = 10; + EditorWindow editWindow; + public MainWindow() { InitializeComponent(); + editWindow = new EditorWindow(); + editWindow.Hide(); + APIRequestor.Instance.m_onSongChanged += OnSongChanged; APIRequestor.Instance.m_onAuthComplete += UpdateUI; - APIRequestor.Instance.m_onAPIPolled += UpdateProgressBar; + APIRequestor.Instance.m_onAPIPolled += UpdateUI; + + LocationChanged += UpdateEditWindowPosition; } public void UpdateUI(FullTrack a_latestTrack = null) @@ -35,6 +44,9 @@ public void UpdateUI(FullTrack a_latestTrack = null) bool playing = APIRequestor.Instance.GetIsPlaying(); UpdatePlayIcon(playing); + float progress = APIRequestor.Instance.GetLatestSongProgress(); + UpdateProgressBar(progress); + string artworkURL = APIRequestor.Instance.GetCurrentSongArtwork(); if (string.IsNullOrEmpty(artworkURL)) { @@ -114,6 +126,26 @@ public void OnClickPreviousSong(object a_sender, RoutedEventArgs a_args) { APIRequestor.Instance.SkipSongPlayback(false); } + + public void OnClickEditorButton(object a_sender, RoutedEventArgs a_args) + { + m_editWindowOpen = !m_editWindowOpen; + + if(m_editWindowOpen) + { + editWindow.Show(); + double mainWidth = RootWindow.ActualWidth; + double editWindowX = Application.Current.MainWindow.Left + mainWidth; + double editWindowY = Application.Current.MainWindow.Top; + editWindow.Top = editWindowY; + editWindow.Left = editWindowX + m_editWindowGap; + } + else + { + editWindow.Hide(); + } + } + private async void UpdateDisplayImage(string a_artworkURL) { if (!string.IsNullOrEmpty(a_artworkURL)) @@ -180,6 +212,15 @@ private void UpdatePlayIcon(bool a_isPlaying) } }); } + private void UpdateEditWindowPosition(object sender, EventArgs e) + { + double mainWidth = RootWindow.ActualWidth; + double editWindowX = Application.Current.MainWindow.Left + mainWidth; + double editWindowY = Application.Current.MainWindow.Top; + editWindow.Top = editWindowY; + editWindow.Left = editWindowX + m_editWindowGap; + } + #region Window Bar controls private void OnClickClose(object sender, RoutedEventArgs e) diff --git a/MiniSpotify/MiniSpotify/MiniSpotify.csproj b/MiniSpotify/MiniSpotify/MiniSpotify.csproj index 29f96a2..a22e90d 100644 --- a/MiniSpotify/MiniSpotify/MiniSpotify.csproj +++ b/MiniSpotify/MiniSpotify/MiniSpotify.csproj @@ -14,6 +14,7 @@ 4 true true + false publish\ true Disk @@ -26,7 +27,6 @@ true 0 1.0.0.%2a - false false true @@ -41,7 +41,7 @@ 4 - AnyCPU + x86 pdbonly true bin\Release\ @@ -62,6 +62,9 @@ Properties\app.manifest + + NoteMW.ico + ..\packages\Newtonsoft.Json.12.0.1\lib\net45\Newtonsoft.Json.dll @@ -99,10 +102,17 @@ MSBuild:Compile Designer + + EditorWindow.xaml + + + Designer + MSBuild:Compile + MSBuild:Compile Designer @@ -150,20 +160,24 @@ - - Always - - - Always - + + PreserveNewest + + + PreserveNewest + - + + PreserveNewest + + + PreserveNewest @@ -188,6 +202,9 @@ PreserveNewest + + PreserveNewest + PreserveNewest diff --git a/MiniSpotify/MiniSpotify/NoteM.ico b/MiniSpotify/MiniSpotify/NoteM.ico new file mode 100644 index 0000000..9b06e4c Binary files /dev/null and b/MiniSpotify/MiniSpotify/NoteM.ico differ diff --git a/MiniSpotify/MiniSpotify/NoteMW.ico b/MiniSpotify/MiniSpotify/NoteMW.ico new file mode 100644 index 0000000..3a9b51f Binary files /dev/null and b/MiniSpotify/MiniSpotify/NoteMW.ico differ diff --git a/MiniSpotify/MiniSpotify/Properties/app.manifest b/MiniSpotify/MiniSpotify/Properties/app.manifest new file mode 100644 index 0000000..66981ed --- /dev/null +++ b/MiniSpotify/MiniSpotify/Properties/app.manifest @@ -0,0 +1,70 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/MiniSpotify/MiniSpotify/Source/APIRequestor.cs b/MiniSpotify/MiniSpotify/Source/APIRequestor.cs index 0bf3210..bd7b4d3 100644 --- a/MiniSpotify/MiniSpotify/Source/APIRequestor.cs +++ b/MiniSpotify/MiniSpotify/Source/APIRequestor.cs @@ -35,9 +35,11 @@ public static APIRequestor Instance private Task m_pollingTask; + private FullTrack m_latestTrack; + public Action m_onSongChanged; public Action m_onAuthComplete; - public Action m_onAPIPolled; + public Action m_onAPIPolled; private int m_songChangePollDelayMS = /*10000*/1000;//1 second @@ -257,22 +259,39 @@ public FullTrack GetLatestTrack() { if(m_spotifyWebAPI != null) { - if(!m_spotifyWebAPI.GetPlayback().IsPlaying) + if (m_spotifyWebAPI.GetPlayback().IsPlaying || m_spotifyWebAPI.GetPlayingTrack().Item != null) { - if(m_spotifyWebAPI.GetUsersRecentlyPlayedTracks().Error == null) + return m_spotifyWebAPI.GetPlayingTrack().Item; + } + else + { + FullTrack latestTrack = m_spotifyWebAPI.GetPlayingTrack().Item; + if (latestTrack != null) + { + return latestTrack; + } + else if (m_spotifyWebAPI.GetUsersRecentlyPlayedTracks().Error == null) { CursorPaging history = m_spotifyWebAPI.GetUsersRecentlyPlayedTracks(); return m_spotifyWebAPI.GetTrack(history.Items[0].Track.Id); } } - else - { - return m_spotifyWebAPI.GetPlayingTrack().Item; - } } return null; } + public float GetLatestSongProgress() + { + if (m_spotifyWebAPI != null) + { + FullTrack currentTrack = Instance.GetLatestTrack(); + float progress = (float)m_spotifyWebAPI.GetPlayback().ProgressMs / (float)currentTrack.DurationMs; + return progress; + } + else + return -1; + } + public bool GetIsPlaying() { if(m_spotifyWebAPI != null) @@ -284,33 +303,29 @@ public bool GetIsPlaying() } private async void PollSongChange() - { - FullTrack lastTrack = new FullTrack(); - if(m_spotifyWebAPI != null) - lastTrack = m_spotifyWebAPI.GetPlayingTrack().Item; - + { while (m_spotifyWebAPI != null) { - //FullTrack currentTrack = m_spotifyWebAPI.GetPlayback().Item; - if (m_spotifyWebAPI.GetPlayingTrack().HasError()) - { - Console.WriteLine(m_spotifyWebAPI.GetPlayingTrack().Error); - } - FullTrack currentTrack = m_spotifyWebAPI.GetPlayingTrack().Item; + FullTrack currentTrack = m_instance.GetLatestTrack(); if(currentTrack != null) { - if(lastTrack != null && currentTrack != lastTrack) + if(m_instance.m_latestTrack == null) { m_instance.m_onSongChanged(currentTrack); - lastTrack = currentTrack; + } + else if(currentTrack != m_instance.m_latestTrack) + { + m_instance.m_onSongChanged(currentTrack); + m_instance.m_latestTrack = currentTrack; } - float progress = (float)m_spotifyWebAPI.GetPlayback().ProgressMs / (float)currentTrack.DurationMs; - - m_instance.m_onAPIPolled(progress); + m_instance.m_onAPIPolled(currentTrack); } + //Update for next time. + m_instance.m_latestTrack = m_instance.GetLatestTrack(); + await Task.Delay(m_songChangePollDelayMS); } }