Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Media keys work; but action immediately reveresed #27

Open
rtaibah opened this issue Oct 13, 2019 · 4 comments
Open

Media keys work; but action immediately reveresed #27

rtaibah opened this issue Oct 13, 2019 · 4 comments

Comments

@rtaibah
Copy link

rtaibah commented Oct 13, 2019

When using the media keys both on the my Mac and an external keyboard, they register but the action is immediately reversed. So if I press play I hear the music playing for a fraction of a second then stops. And if I press pause the music stops for a fraction of a second and plays again.

In both cases notifications are triggered.

@PhilipTrauner
Copy link
Owner

Never encountered that one before 😬.
Please run the code snippet below to help me figure out what's happening:

from AppKit import NSApplication, NSApplicationActivationPolicyProhibited
from AppKit import NSSystemDefined
from AppKit import NSKeyUp
from PyObjCTools import AppHelper

class KeySocketApp(NSApplication):
    def sendEvent_(self, event):
        if event.type() is NSSystemDefined and event.subtype() == 8:
            data = event.data1()
            key_code = (data & 0xFFFF0000) >> 16
            key_flags = (data & 0x0000FFFF)
            key_state = (key_flags & 0xFF00) >> 8

        if key_state is NSKeyUp:
            print("Key up detected.")
        elif key_code == 20 or key_code == 18:
            print("Previous key detected")
        elif key_code == 16:
            print("Play/pause key detected")
        elif key_code == 19 or key_code == 17:
            print("Next key detected.")
        else:
            print(f"Unknown key code: {key_code}")

app = KeySocketApp.sharedApplication()
app.setActivationPolicy_(NSApplicationActivationPolicyProhibited)
AppHelper.runEventLoop()

@rtaibah
Copy link
Author

rtaibah commented Oct 14, 2019

Here is the output. Not very helpful, so I made a video too.

rami@MacBook-Pro-4 ~/Music  #python3 debug.py
Play/pause key detected
Key up detected.
Play/pause key detected
Key up detected.
Play/pause key detected
Key up detected.
Play/pause key detected
Key up detected.
Play/pause key detected
Key up detected.
Play/pause key detected
Key up detected.

@PhilipTrauner
Copy link
Owner

I introduced a config variable named THROTTLE_INTERVAL to resolve this issue. It controls for how long key presses are ignored after the last key-press. Setting it to ~ 2.0 should hopefully fix the problem 🙂

Please upgrade to the most recent version (v3.0.4 at the time of writing), delete your config file and set an appropriate interval.

rm $(EDITOR=echo cmus-osx config)
cmus-osx config

@rtaibah
Copy link
Author

rtaibah commented Oct 15, 2019

This partially fixed the issue. Pressing play plays the music, however pausing pauses for a few seconds and plays again.

Things I done/things I noticed:

1- I changed a bit in the THROTTLE_INTERVAL variable, all the way up to 20.0.
2- The play icon on my Mac's touchbar doesn't change to pause or vice versa
3- I am not playing anything from my local system, but streaming a .pls file.
4- Doing your suggestion made the buttons unresponsive. Only after restarting I got the behaviour I describe here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants