diff --git a/SpotifyAPI/Local/SpotifyLocalAPI.cs b/SpotifyAPI/Local/SpotifyLocalAPI.cs
index 62a7fead..276ce758 100644
--- a/SpotifyAPI/Local/SpotifyLocalAPI.cs
+++ b/SpotifyAPI/Local/SpotifyLocalAPI.cs
@@ -44,6 +44,8 @@ namespace SpotifyAPI.Local
}
}
+ private const int WindowsSevenMajorVersion = 6;
+ private const int WindowsSevenMinorVersion = 1;
private const byte VkMediaNextTrack = 0xb0;
private const byte VkMediaPrevTrack = 0xb1;
private const int KeyeventfExtendedkey = 0x1;
@@ -134,6 +136,10 @@ namespace SpotifyAPI.Local
_eventTimer.Start();
}
+ private bool IsOSCompatible(int minMajor, int minMinor)
+ {
+ return Environment.OSVersion.Version.Major > minMajor || (Environment.OSVersion.Version.Major == minMajor && Environment.OSVersion.Version.Minor >= minMinor);
+ }
///
/// Connects with Spotify. Needs to be called before all other SpotifyAPI functions
///
@@ -157,13 +163,8 @@ namespace SpotifyAPI.Local
///
public void Mute()
{
- //Windows < Windows Vista Check
- if (Environment.OSVersion.Version.Major < 6)
+ if(!IsOSCompatible(WindowsSevenMajorVersion, WindowsSevenMinorVersion))
throw new NotSupportedException("This feature is only available on Windows 7 or newer");
- //Windows Vista Check
- if (Environment.OSVersion.Version.Major == 6)
- if(Environment.OSVersion.Version.Minor == 0)
- throw new NotSupportedException("This feature is only available on Windows 7 or newer");
VolumeMixerControl.MuteSpotify(true);
}
@@ -172,13 +173,8 @@ namespace SpotifyAPI.Local
///
public void UnMute()
{
- //Windows < Windows Vista Check
- if (Environment.OSVersion.Version.Major < 6)
+ if (!IsOSCompatible(WindowsSevenMajorVersion, WindowsSevenMinorVersion))
throw new NotSupportedException("This feature is only available on Windows 7 or newer");
- //Windows Vista Check
- if (Environment.OSVersion.Version.Major == 6)
- if (Environment.OSVersion.Version.Minor == 0)
- throw new NotSupportedException("This feature is only available on Windows 7 or newer");
VolumeMixerControl.MuteSpotify(false);
}
@@ -188,13 +184,8 @@ namespace SpotifyAPI.Local
/// Null if an error occured, otherwise the muted state
public bool IsSpotifyMuted()
{
- //Windows < Windows Vista Check
- if (Environment.OSVersion.Version.Major < 6)
+ if (!IsOSCompatible(WindowsSevenMajorVersion, WindowsSevenMinorVersion))
throw new NotSupportedException("This feature is only available on Windows 7 or newer");
- //Windows Vista Check
- if (Environment.OSVersion.Version.Major == 6)
- if (Environment.OSVersion.Version.Minor == 0)
- throw new NotSupportedException("This feature is only available on Windows 7 or newer");
return VolumeMixerControl.IsSpotifyMuted();
}
@@ -204,13 +195,8 @@ namespace SpotifyAPI.Local
/// A value between 0 and 100
public void SetSpotifyVolume(float volume = 100)
{
- //Windows < Windows Vista Check
- if (Environment.OSVersion.Version.Major < 6)
+ if (!IsOSCompatible(WindowsSevenMajorVersion, WindowsSevenMinorVersion))
throw new NotSupportedException("This feature is only available on Windows 7 or newer");
- //Windows Vista Check
- if (Environment.OSVersion.Version.Major == 6)
- if (Environment.OSVersion.Version.Minor == 0)
- throw new NotSupportedException("This feature is only available on Windows 7 or newer");
if (volume < 0 || volume > 100)
throw new ArgumentOutOfRangeException(nameof(volume));
VolumeMixerControl.SetSpotifyVolume(volume);
@@ -222,13 +208,8 @@ namespace SpotifyAPI.Local
/// Null if an error occured, otherwise a float between 0 and 100
public float GetSpotifyVolume()
{
- //Windows < Windows Vista Check
- if (Environment.OSVersion.Version.Major < 6)
+ if (!IsOSCompatible(WindowsSevenMajorVersion, WindowsSevenMinorVersion))
throw new NotSupportedException("This feature is only available on Windows 7 or newer");
- //Windows Vista Check
- if (Environment.OSVersion.Version.Major == 6)
- if (Environment.OSVersion.Version.Minor == 0)
- throw new NotSupportedException("This feature is only available on Windows 7 or newer");
return VolumeMixerControl.GetSpotifyVolume();
}