/// <summary> /// Get the title of the Spotify window /// </summary> /// <returns>The title of the Spotify window, or null if Spotify isn't running</returns> private string GetWindowTitle() { if (!IsRunning) { return(null); } return(User32Interop.GetWindowText(WindowHandle)); }
/// <summary> /// Attempt to set the media play state /// </summary> /// <param name="playing">Whether or not media is playing</param> private static void AttemptSetMediaPlaying(bool playing) { // don't do anything if not enabled if (!Preferences.Enabled) { return; } // don't unpause if we didn't pause if (!pausedMedia && playing) { return; } // do some checks to see if we need to change play state if (!pausedMedia || !playing) // if we didn't already pause or are trying to pause { // is editor muted? if (EditorUtility.audioMasterMute) { return; } } int windowHandle = User32Interop.HWND_BROADCAST; if (Preferences.ControlSpotifyDirectly) { // check if spotify is already in the desired state (prevents accidental unpause) Spotify.Instance.Refresh(); // make sure spotify is running and isn't already in the desired state if (!Spotify.Instance.IsRunning || Spotify.Instance.IsPlaying == playing) { return; } // control Spotify directly windowHandle = Spotify.Instance.WindowHandle.ToInt32(); } // set play state if (playing) { User32Interop.SendAppcommand(windowHandle, WinAppcommand.MediaPlay); } else { User32Interop.SendAppcommand(windowHandle, WinAppcommand.MediaPause); } pausedMedia = !playing; }
/// <summary> /// Attempts to get the window handle by process name /// </summary> private void RefreshWindowHandle() { WindowHandle = User32Interop.GetWindowByProcessName(processName); }