File tree Expand file tree Collapse file tree 3 files changed +8
-10
lines changed Expand file tree Collapse file tree 3 files changed +8
-10
lines changed Original file line number Diff line number Diff line change @@ -8,5 +8,5 @@ def player_option():
8
8
"--player" ,
9
9
help = "The player to use." ,
10
10
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 ,
12
12
)
Original file line number Diff line number Diff line change 1
1
import os
2
- import subprocess
3
2
import tempfile
4
3
import threading
5
4
import time
6
5
from typing import TYPE_CHECKING
7
6
7
+ from afplay import afplay , is_installed
8
+
8
9
from audius .player .base import BasePlayer
9
10
from audius .types import PlayerType
10
11
@@ -16,12 +17,8 @@ class AFPlayer(BasePlayer):
16
17
def __init__ (self , sdk : "Audius" ):
17
18
super ().__init__ (PlayerType .AFPLAY , sdk )
18
19
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 ()
25
22
26
23
def play (self , url : str ):
27
24
download_url = self .client .get_redirect_url (url )
@@ -35,7 +32,7 @@ def download():
35
32
# for entire track to finish download.
36
33
thread = threading .Thread (target = download )
37
34
thread .start ()
38
- time .sleep (5 ) # Buffer
39
- subprocess . Popen ([ " afplay" , _file .name ] )
35
+ time .sleep (3 ) # Buffer
36
+ afplay ( _file .name )
40
37
thread .join ()
41
38
time .sleep (1 )
Original file line number Diff line number Diff line change 61
61
"requests>=2.28.2,<3" ,
62
62
"click>=8.1.3,<9" ,
63
63
"tqdm>=4.65.0,<5" ,
64
+ "afplay-py>=0.2.0,<0.3" ,
64
65
],
65
66
python_requires = ">=3.9,<4" ,
66
67
extras_require = extras_require ,
You can’t perform that action at this time.
0 commit comments