forked from skyline75489/pyfm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
player.py
29 lines (25 loc) · 880 Bytes
/
player.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import subprocess
from multiprocessing import Process
class Player:
def __init__(self):
self.is_playing = False
self.current_song = None
self.player_process = None
self.return_code = 0
def play(self, song):
self.current_song = song
#print("Now playing: ")
#print("Artist: "+ self.current_song.artist)
#print("Title: " + self.current_song.title)
#print("Album: " + self.current_song.album_title)
# using mpg123 to play the track
# -q(quiet) remove the output to stdout
self.player_process = subprocess.Popen(["mpg123", "-q", self.current_song.url])
self.is_playing = True
def stop(self):
if self.player_process is None:
return
try:
self.player_process.terminate()
except:
pass