Skip to content

Commit 9df6d95

Browse files
committed
fix: afplay fix
1 parent 67fd4f7 commit 9df6d95

File tree

3 files changed

+8
-10
lines changed

3 files changed

+8
-10
lines changed

audius/cli/options.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ def player_option():
88
"--player",
99
help="The player to use.",
1010
type=click.Choice([x.value for x in PlayerType.__members__.values()], case_sensitive=False),
11-
callback=lambda _, _2, val: PlayerType(val),
11+
callback=lambda _, _2, val: PlayerType(val) if val else None,
1212
)

audius/player/af.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import os
2-
import subprocess
32
import tempfile
43
import threading
54
import time
65
from typing import TYPE_CHECKING
76

7+
from afplay import afplay, is_installed
8+
89
from audius.player.base import BasePlayer
910
from audius.types import PlayerType
1011

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

19-
def is_available(self):
20-
try:
21-
subprocess.run("afplay", stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
22-
return True
23-
except FileNotFoundError:
24-
return False
20+
def is_available(self) -> bool:
21+
return is_installed()
2522

2623
def play(self, url: str):
2724
download_url = self.client.get_redirect_url(url)
@@ -35,7 +32,7 @@ def download():
3532
# for entire track to finish download.
3633
thread = threading.Thread(target=download)
3734
thread.start()
38-
time.sleep(5) # Buffer
39-
subprocess.Popen(["afplay", _file.name])
35+
time.sleep(3) # Buffer
36+
afplay(_file.name)
4037
thread.join()
4138
time.sleep(1)

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
"requests>=2.28.2,<3",
6262
"click>=8.1.3,<9",
6363
"tqdm>=4.65.0,<5",
64+
"afplay-py>=0.2.0,<0.3",
6465
],
6566
python_requires=">=3.9,<4",
6667
extras_require=extras_require,

0 commit comments

Comments
 (0)