public SpotifyHook() { RefreshTimer = new Timer((e) => { if (IsRunning()) { WindowName = Spotify.MainWindowTitle; Handle = Spotify.MainWindowHandle; if (VolumeControl == null) { VolumeControl = AudioUtils.GetVolumeControl(Children); } else { lastPeak = peak; peak = AudioUtils.GetPeakVolume(VolumeControl.Control); } } else { ClearHooks(); HookSpotify(); } }, null, TimeSpan.Zero, TimeSpan.FromMilliseconds(500)); }
private bool HookSpotify() { Children = new HashSet <int>(); // Try hooking through window title foreach (Process p in Process.GetProcessesByName("spotify")) { Children.Add(p.Id); Spotify = p; if (p.MainWindowTitle.Length > 1) { return(true); } } // Try hooking through audio device VolumeControl = AudioUtils.GetVolumeControl(Children); if (VolumeControl != null) { Spotify = Process.GetProcessById(VolumeControl.ProcessId); return(true); } return(false); }
public SpotifyHook() { RefreshTimer = new Timer((e) => { if (IsRunning()) { WindowName = Spotify.MainWindowTitle; Handle = Spotify.MainWindowHandle; VolumeControl = AudioUtils.GetVolumeControl(Spotify); } else { ClearHooks(); } }, null, TimeSpan.Zero, TimeSpan.FromMilliseconds(300)); }
public SpotifyState Check() { if (!Hooked) //if never or no more hooked, start hook { Hooked = HookSpotify(); } else if (!IsRunning()) // if hooked and spotify no more running, clean hook { CleanHook(); } else // else inspect spotify process { if (volumeControl != null) { lastPeak = peak; peak = AudioUtils.GetPeakVolume(volumeControl.Control); } else { volumeControl = AudioUtils.GetVolumeControl(children); } if (Spotify.HasExited) { handle = IntPtr.Zero; return(SpotifyState.NonHooked); } handle = Spotify.MainWindowHandle; var windowName = Spotify.MainWindowTitle; if (windowName.Equals("Spotify Free")) { return(SpotifyState.Pause); } if ((windowName.Equals("Advertisement") || windowName.Equals("Spotify")) && IsPlaying()) { return(SpotifyState.PlayingAd); } if (IsPlaying()) { return(SpotifyState.Playing); } } return(SpotifyState.NonHooked); }
private void RefreshTimer_Tick(object state) { if (IsRunning()) { WindowName = Spotify.MainWindowTitle; Handle = Spotify.MainWindowHandle; if (VolumeControl == null) { VolumeControl = AudioUtils.GetVolumeControl(Children); } else { lastPeak = peak; peak = AudioUtils.GetPeakVolume(VolumeControl.Control); } } else { ClearHooks(); HookSpotify(); } }