Jump to content

"Auto mute/unmute" Spotify


msd1994
 Share

Recommended Posts

I made a general utility file for volume and playback control, using the _W7sound UDF for muting spotify and only spotify, but when trying to automate it, so whenever the title has or contains "Spotify" spotify should be muted. Otherwise, it should unmute spotify. If i initiate muting spotify with a hotkey, it works, and will unmute properly, but I want it to mute automatically as well. I've tried many different ways to do this, most recently this. 

while 1
   Sleep(300) ; give time for title of window to change
   $title = WinGetTitle("[CLASS:SpotifyMainWindow]") ; check what title is
   If (StringInStr($title, "Spotify")) Then ; if not song title, mute.
      If Not $autoUnmute Then
         autoMute()
      EndIf
   EndIf
   If $autoUnmute Then ;var set by "autoMute", if true, check when to unmute.
      ToolTip("Muted", 0, 0)
      While (StringInStr($title, "Spotify"))
      Sleep(200)
      $title = WinGetTitle("[CLASS:SpotifyMainWindow]")

      WEnd
      ToolTip("")
      Sleep(300)
      If $autoUnmute Then
         _SetVolume("[CLASS:SpotifyMainWindow]", _GetVolume("[CLASS:SpotifyMainWindow]"))
      EndIf

      $autoUnmute = False
   EndIf
    Sleep(200)
WEnd



Func autoMute()
   $title = WinGetTitle("[CLASS:SpotifyMainWindow]") ; double check still muted

   If (StringInStr($title, "Spotify")) Then ; if it is, mute, set var to true so while loop checks when to unmute.
      _MuteVolume("[CLASS:SpotifyMainWindow]")
      $autoUnmute = True
   EndIf

EndFunc

if i remove the part above "If $autoUnmute Then" and just call autoMute myself with the hotkey I set, it works and properly mutes, then unmutes. Trying like this seems to have trouble though. Anyone have some idea why I would be having trouble? I did notice a slight delay in the time of me pausing Spotify and the actual title changing in "SndVol.exe" (volume mixer), but haven't been able to figure out how to fix this if that was the issue.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...