Skip to content

Commit

Permalink
Add support for playpause button on Linux and refactor media controls
Browse files Browse the repository at this point in the history
- Added support for playpause button on Linux
- Moved playpause, prevtrack, and nexttrack functions to a dedicated media.py file
- Updated import statements in __init__.py to include media control
- Refactored handle_command in commands.py to use media_control from media.py
  • Loading branch information
Lenochxd committed Dec 14, 2024
1 parent 33608c6 commit 27051fd
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 7 deletions.
3 changes: 2 additions & 1 deletion app/buttons/audio/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from .set_system_mic import set_microphone_by_name
from .set_system_speaker import set_speakers_by_name
from .volume import handle_command as change_volume
from .volume import handle_command as change_volume
from .media import handle_command as media_control
35 changes: 35 additions & 0 deletions app/buttons/audio/media.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from app.utils.platform import is_linux

import os
import keyboard
if not is_linux or os.environ.get("DISPLAY"):
import pyautogui


def handle_command(message):

if message.startswith("/mediacontrol playpause"):
playpause()
elif message.startswith("/mediacontrol previous"):
prevtrack()
elif message.startswith("/mediacontrol next"):
nexttrack()


def playpause():
try:
if is_linux:
keyboard.send("play/pause media")
else:
pyautogui.press("playpause")
except:
if is_linux:
keyboard.send(164)
else:
keyboard.send(-179)

def prevtrack():
pyautogui.press("prevtrack")

def nexttrack():
pyautogui.press("nexttrack")
9 changes: 3 additions & 6 deletions app/buttons/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,9 @@ def handle_command(message=None):

elif message.startswith("/soundcontrol mute"):
pyautogui.press("volumemute")
elif message.startswith("/mediacontrol playpause"):
pyautogui.press("playpause")
elif message.startswith("/mediacontrol previous"):
pyautogui.press("prevtrack")
elif message.startswith("/mediacontrol next"):
pyautogui.press("nexttrack")

elif message.startswith("/mediacontrol"):
audio.media_control(message)

elif message.startswith("/speechrecognition"):
pyautogui.hotkey("win", "h")
Expand Down

0 comments on commit 27051fd

Please sign in to comment.