Skip to content

Commit

Permalink
fix: afplay fix
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey committed Apr 8, 2023
1 parent 67fd4f7 commit 9df6d95
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
2 changes: 1 addition & 1 deletion audius/cli/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ def player_option():
"--player",
help="The player to use.",
type=click.Choice([x.value for x in PlayerType.__members__.values()], case_sensitive=False),
callback=lambda _, _2, val: PlayerType(val),
callback=lambda _, _2, val: PlayerType(val) if val else None,
)
15 changes: 6 additions & 9 deletions audius/player/af.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import os
import subprocess
import tempfile
import threading
import time
from typing import TYPE_CHECKING

from afplay import afplay, is_installed

from audius.player.base import BasePlayer
from audius.types import PlayerType

Expand All @@ -16,12 +17,8 @@ class AFPlayer(BasePlayer):
def __init__(self, sdk: "Audius"):
super().__init__(PlayerType.AFPLAY, sdk)

def is_available(self):
try:
subprocess.run("afplay", stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
return True
except FileNotFoundError:
return False
def is_available(self) -> bool:
return is_installed()

def play(self, url: str):
download_url = self.client.get_redirect_url(url)
Expand All @@ -35,7 +32,7 @@ def download():
# for entire track to finish download.
thread = threading.Thread(target=download)
thread.start()
time.sleep(5) # Buffer
subprocess.Popen(["afplay", _file.name])
time.sleep(3) # Buffer
afplay(_file.name)
thread.join()
time.sleep(1)
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"requests>=2.28.2,<3",
"click>=8.1.3,<9",
"tqdm>=4.65.0,<5",
"afplay-py>=0.2.0,<0.3",
],
python_requires=">=3.9,<4",
extras_require=extras_require,
Expand Down

0 comments on commit 9df6d95

Please sign in to comment.