mirror of
https://github.com/Sarsoo/Spotify.NET.git
synced 2024-12-24 23:16:28 +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 VkMediaNextTrack = 0xb0;
|
||||||
private const byte VkMediaPrevTrack = 0xb1;
|
private const byte VkMediaPrevTrack = 0xb1;
|
||||||
private const int KeyeventfExtendedkey = 0x1;
|
private const int KeyeventfExtendedkey = 0x1;
|
||||||
@ -134,6 +136,10 @@ namespace SpotifyAPI.Local
|
|||||||
_eventTimer.Start();
|
_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>
|
/// <summary>
|
||||||
/// Connects with Spotify. Needs to be called before all other SpotifyAPI functions
|
/// Connects with Spotify. Needs to be called before all other SpotifyAPI functions
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -157,13 +163,8 @@ namespace SpotifyAPI.Local
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public void Mute()
|
public void Mute()
|
||||||
{
|
{
|
||||||
//Windows < Windows Vista Check
|
if(!IsOSCompatible(WindowsSevenMajorVersion, WindowsSevenMinorVersion))
|
||||||
if (Environment.OSVersion.Version.Major < 6)
|
|
||||||
throw new NotSupportedException("This feature is only available on Windows 7 or newer");
|
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);
|
VolumeMixerControl.MuteSpotify(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -172,13 +173,8 @@ namespace SpotifyAPI.Local
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public void UnMute()
|
public void UnMute()
|
||||||
{
|
{
|
||||||
//Windows < Windows Vista Check
|
if (!IsOSCompatible(WindowsSevenMajorVersion, WindowsSevenMinorVersion))
|
||||||
if (Environment.OSVersion.Version.Major < 6)
|
|
||||||
throw new NotSupportedException("This feature is only available on Windows 7 or newer");
|
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);
|
VolumeMixerControl.MuteSpotify(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -188,13 +184,8 @@ namespace SpotifyAPI.Local
|
|||||||
/// <returns>Null if an error occured, otherwise the muted state</returns>
|
/// <returns>Null if an error occured, otherwise the muted state</returns>
|
||||||
public bool IsSpotifyMuted()
|
public bool IsSpotifyMuted()
|
||||||
{
|
{
|
||||||
//Windows < Windows Vista Check
|
if (!IsOSCompatible(WindowsSevenMajorVersion, WindowsSevenMinorVersion))
|
||||||
if (Environment.OSVersion.Version.Major < 6)
|
|
||||||
throw new NotSupportedException("This feature is only available on Windows 7 or newer");
|
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();
|
return VolumeMixerControl.IsSpotifyMuted();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -204,13 +195,8 @@ namespace SpotifyAPI.Local
|
|||||||
/// <param name="volume">A value between 0 and 100</param>
|
/// <param name="volume">A value between 0 and 100</param>
|
||||||
public void SetSpotifyVolume(float volume = 100)
|
public void SetSpotifyVolume(float volume = 100)
|
||||||
{
|
{
|
||||||
//Windows < Windows Vista Check
|
if (!IsOSCompatible(WindowsSevenMajorVersion, WindowsSevenMinorVersion))
|
||||||
if (Environment.OSVersion.Version.Major < 6)
|
|
||||||
throw new NotSupportedException("This feature is only available on Windows 7 or newer");
|
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)
|
if (volume < 0 || volume > 100)
|
||||||
throw new ArgumentOutOfRangeException(nameof(volume));
|
throw new ArgumentOutOfRangeException(nameof(volume));
|
||||||
VolumeMixerControl.SetSpotifyVolume(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>
|
/// <returns>Null if an error occured, otherwise a float between 0 and 100</returns>
|
||||||
public float GetSpotifyVolume()
|
public float GetSpotifyVolume()
|
||||||
{
|
{
|
||||||
//Windows < Windows Vista Check
|
if (!IsOSCompatible(WindowsSevenMajorVersion, WindowsSevenMinorVersion))
|
||||||
if (Environment.OSVersion.Version.Major < 6)
|
|
||||||
throw new NotSupportedException("This feature is only available on Windows 7 or newer");
|
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();
|
return VolumeMixerControl.GetSpotifyVolume();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user