-
Notifications
You must be signed in to change notification settings - Fork 2
/
UniversalPause.py
63 lines (45 loc) · 938 Bytes
/
UniversalPause.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import os
import subprocess
import serial
def idgetter(x):
pid_list=[]
strbuff=""
read=False
stopread=False
for i in x:
if i=='"':
if read:
stopread=True
read=~read
continue
if read:
strbuff+=i
if stopread:
stopread=False
pid_list.append(int(strbuff))
strbuff=""
return pid_list
def pauser():
to_pause=[]
noiseMakers=subprocess.check_output('pacmd list-sink-inputs| grep -e application.process.id ',shell=True)
noiseMakers=str(noiseMakers)
to_pause=idgetter(noiseMakers)
for i in to_pause:
os.system('kill -STOP '+str(i))
return to_pause
def resumer(x):
for i in x:
os.system('kill -CONT '+str(i))
def main():
paused=False
ser=serial.Serial('/dev/ttyACM0',9600)
while True:
p=ser.readline()
if (p[:4]==b'play' and paused):
resumer(frozen)
paused=False
if (p[:5]==b'pause' and ~paused):
frozen=pauser()
paused=True
if __name__ == '__main__':
main()