Closed sidequestboy closed 4 years ago
Huh. Seems like changing the YouTube playing vs not playing status also triggers the event handler. Perhaps we'd need to implement some kind of check on the source of the event.
The event is interpreted in this block.
How familiar are you with programming? Perhaps you could log some more info on the event itself and see if it's possible to see whether it comes from Spotify or not? Otherwise I may just try and spin up my Linux again to have a go at it.
I was able to fix it by modifying the event_handler
method:
def event_handler(*args, **kwargs):
"""event handler for the receiver."""
"""arg[1] contains metadata"""
"""arg[1][1] contains PlaybackStatus"""
data = unwrap(args)
print(data)
if 'spotify' in data[1]['Metadata']['mpris:trackid']: # Checking for spotify here
if data[1]['PlaybackStatus'] == "Playing":
print("Music is playing")
system("polybar-msg hook playpause 2")
""" Send IPC hook 2 to all bars for module playpause """
if data[1]['PlaybackStatus'] == "Paused":
print("Music is paused.")
""" Send IPC hook 3 to all bars module playpause """
system("polybar-msg hook playpause 3")
""" Send IPC hook 2 to all bars for module spotify """
system("polybar-msg hook spotify 2")
Here's an example for the contents of the data
variable when using Spotify:
['org.mpris.MediaPlayer2.Player', {'Metadata': {'mpris:trackid': 'spotify:track:3BQHpFgAp4l80e1XslIjNI', 'mpris:length': 125666000, 'mpris:artUrl': 'https://open.spotify.com/image/ab67616d00001e02e3e3b64cea45265469d4cafa', 'xesam:album': 'Help! (Remastered)', 'xesam:albumArtist': ['The Beatles'], 'xesam:artist': ['The Beatles'], 'xesam:autoRating': dbus.Double(0.78, variant_level=1), 'xesam:discNumber': 1, 'xesam:title': 'Yesterday - Remastered 2009', 'xesam:trackNumber': 13, 'xesam:url': 'https://open.spotify.com/track/3BQHpFgAp4l80e1XslIjNI'}, 'PlaybackStatus': 'Paused'}, []]
And here's an example for youtube:
['org.mpris.MediaPlayer2.Player', {'PlaybackStatus': 'Paused'}, []]
Would you like me to open a PR @dietervanhoof ?
Perfect! Just as expected there are events being processed from other tools. I'd very much appreciate a PR! It's been a while since I last booted up my Linux machine and thus it's also been a while since I last worked on this.
Your contribution is much appreciated.
thank you both! works great (:
Why does this happen?
I am running pulseaudio