-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmusic_player.py
More file actions
47 lines (39 loc) · 978 Bytes
/
Copy pathmusic_player.py
File metadata and controls
47 lines (39 loc) · 978 Bytes
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import os,sys
import backdraft
import subprocess
import time
class Player:
def __init__(self):
self.proc = None
def play(self, music_file):
if self.proc and self.proc.poll() is not None:
return
self.proc = subprocess.Popen(['mplayer', music_file], shell=False)
def stop(self):
if self.proc:
self.proc.terminate()
self.proc = None
class MusicMonitor:
def __init__(self, song):
self.player = Player()
self.song = song
def power_on(self, whatever):
self.player.play(self.song)
def power_off(self, whatever):
self.player.stop()
def monitor(song):
monitor = MusicMonitor(song)
urls = {
"http://chb1.kcprod.info:8080/hudson/job/kc-backend-chb2/rssAll": (0, 2),
}
monitor = backdraft.AsyncMonitor([monitor], urls)
monitor.start()
def test(song):
player = Player()
player.play(song)
time.sleep(5)
player.stop()
if __name__ == '__main__':
song = sys.argv[1]
monitor(song)
# test(song)