@@ -11,13 +11,14 @@ namespace SpotifyAPIv1
1111 public class SpotifyMusicHandler
1212 {
1313 [ DllImport ( "user32.dll" ) ]
14- static extern void keybd_event ( byte bVk , byte bScan , uint dwFlags , int dwExtraInfo ) ;
14+ private static extern void keybd_event ( byte bVk , byte bScan , uint dwFlags , int dwExtraInfo ) ;
1515 [ DllImport ( "nircmd.dll" ) ]
16- public static extern bool DoNirCmd ( String NirCmdStr ) ;
16+ private static extern bool DoNirCmd ( String NirCmdStr ) ;
1717
1818 RemoteHandler rh ;
1919 StatusResponse sr ;
2020
21+ //Constants for the Keyboard Event (NextTrack + PreviousTrack)
2122 const byte VK_MEDIA_NEXT_TRACK = 0xb0 ;
2223 const byte VK_MEDIA_PREV_TRACK = 0xb1 ;
2324 const int KEYEVENTF_EXTENDEDKEY = 0x1 ;
@@ -27,66 +28,116 @@ public SpotifyMusicHandler()
2728 {
2829 rh = RemoteHandler . GetInstance ( ) ;
2930 }
31+ /// <summary>
32+ /// Simulates a KeyPress
33+ /// </summary>
34+ /// <param name="keyCode">The keycode for the represented Key</param>
3035 void PressKey ( byte keyCode )
3136 {
3237 keybd_event ( keyCode , 0x45 , KEYEVENTF_EXTENDEDKEY , 0 ) ;
3338 keybd_event ( keyCode , 0x45 , KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP , 0 ) ;
3439 }
40+ /// <summary>
41+ /// Checks if a song is playing
42+ /// </summary>
43+ /// <returns>True if a song is playing, false if not</returns>
3544 public Boolean IsPlaying ( )
3645 {
3746 return sr . playing ;
3847 }
48+ /// <summary>
49+ /// Returns the current Volume
50+ /// </summary>
51+ /// <returns>A value between 0 and 1</returns>
3952 public double GetVolume ( )
4053 {
4154 return sr . volume ;
4255 }
43- public void PlayURL ( String url )
56+ /// <summary>
57+ /// Plays a Spotify URI
58+ /// </summary>
59+ /// <param name="uri">The Spotify URI. Can be checked with <seealso cref="SpotifyAPI.IsValidSpotifyURI"/></param>
60+ public void PlayURL ( String uri )
4461 {
45- rh . SendPlayRequest ( url ) ;
62+ rh . SendPlayRequest ( uri ) ;
4663 }
64+ /// <summary>
65+ /// Checks if the current "Track" is an Advert
66+ /// </summary>
67+ /// <returns>True if it's an Advert, false if not</returns>
4768 public Boolean IsAdRunning ( )
4869 {
4970 return ! sr . next_enabled && ! sr . prev_enabled ;
5071 }
72+ /// <summary>
73+ /// Returns the current Track object
74+ /// </summary>
75+ /// <returns>Returns the current track object</returns>
5176 public Track GetCurrentTrack ( )
5277 {
5378 return sr . track ;
5479 }
80+ /// <summary>
81+ /// Skips the current song (Using keypress simulation)
82+ /// </summary>
5583 public void Skip ( )
5684 {
5785 PressKey ( VK_MEDIA_NEXT_TRACK ) ;
5886 }
87+ /// <summary>
88+ /// Emulates the "Previous" Key (Using keypress simulation)
89+ /// </summary>
90+ public void Previous ( )
91+ {
92+ PressKey ( VK_MEDIA_PREV_TRACK ) ;
93+ }
94+ /// <summary>
95+ /// Returns the current track postion
96+ /// </summary>
97+ /// <returns>A double between 0 and ∞</returns>
5998 public double GetTrackPosition ( )
6099 {
61100 return sr . playing_position ;
62101 }
102+ /// <summary>
103+ /// Mutes Spotify (Requires nircmd.dll)
104+ /// </summary>
63105 public void Mute ( )
64106 {
65107 if ( File . Exists ( "nircmd.dll" ) )
66108 DoNirCmd ( "muteappvolume spotify.exe 1" ) ;
67109 }
110+ /// <summary>
111+ /// Unmutes Spotify (Requires nircmd.dll)
112+ /// </summary>
68113 public void UnMute ( )
69114 {
70115 if ( File . Exists ( "nircmd.dll" ) )
71116 DoNirCmd ( "muteappvolume spotify.exe 0" ) ;
72117 }
73- public void Previous ( )
74- {
75- PressKey ( VK_MEDIA_PREV_TRACK ) ;
76- }
118+ /// <summary>
119+ /// Pause function
120+ /// </summary>
77121 public void Pause ( )
78122 {
79123 rh . SendPauseRequest ( ) ;
80-
81124 }
125+ /// <summary>
126+ /// Play function
127+ /// </summary>
82128 public void Play ( )
83129 {
84130 rh . SendPlayRequest ( ) ;
85131 }
132+ /// <summary>
133+ /// Returns all Informations gathered by the JSON Request
134+ /// </summary>
135+ /// <returns>A StatusResponse object</returns>
86136 public StatusResponse GetStatusResponse ( )
87137 {
88138 return sr ;
89139 }
140+ //Used internaly
90141 internal void Update ( StatusResponse sr )
91142 {
92143 this . sr = sr ;
0 commit comments