mirror of
https://github.com/Sarsoo/Spotify.NET.git
synced 2024-12-23 22:56:25 +00:00
Added method to check for compatible OS (#147)
* Added method to check for compatible OS * Standardized const variables * Fixed typo * Negation of usage in if's * Moved const variables * simplified IsOSCompatible
This commit is contained in:
parent
3eefa5a2dc
commit
a932aaadc8
@ -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);
|
||||
}
|
||||
/// <summary>
|
||||
/// Connects with Spotify. Needs to be called before all other SpotifyAPI functions
|
||||
/// </summary>
|
||||
@ -157,13 +163,8 @@ namespace SpotifyAPI.Local
|
||||
/// </summary>
|
||||
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
|
||||
/// </summary>
|
||||
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
|
||||
/// <returns>Null if an error occured, otherwise the muted state</returns>
|
||||
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
|
||||
/// <param name="volume">A value between 0 and 100</param>
|
||||
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
|
||||
/// <returns>Null if an error occured, otherwise a float between 0 and 100</returns>
|
||||
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();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user