-
Notifications
You must be signed in to change notification settings - Fork 0
/
mplayertest.aal
108 lines (99 loc) · 3.27 KB
/
mplayertest.aal
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
aal "mplayertest" {
language "python3" {
import pexpect
import subprocess
from time import sleep
def getstatusoutput(cmd):
r = subprocess.run(cmd, shell=True, stdout=subprocess.PIPE, text=True)
return r.returncode, r.stdout
response_time = 1.0 # seconds, mplayer should respond to commands within this time
def launchMplayer():
global mplayer
mplayer = pexpect.spawn("mplayer -idle -slave -quiet 1.mp3 2.mp3")
sleep(response_time)
def command(cmd):
log("mplayer command: " + cmd)
mplayer.write(cmd + "\n")
sleep(response_time)
log("mplayer response: " + str(mplayer.read_nonblocking(4096, 0)))
def openedMP3File():
return int(getstatusoutput("basename $(ls -l /proc/" + str(mplayer.pid) +
"/fd | awk '/mp3/{print $NF}') .mp3")[1])
def playing():
cmd = "pactl list"
status, output = getstatusoutput(cmd)
return 0 == status and "RUNNING" in output
}
# preview-show-vars: song
# preview-depth: 5
variables {
state, song, songcount
}
initial_state {
state = "playing" # either "playing" or "paused"
song = 1 # number of the song being played
songcount = 2 # number of songs in current playlist
}
adapter_init {
launchMplayer()
}
adapter_exit {
command("quit")
}
input "pause" {
guard { return state == "playing" }
body { state = "paused" }
adapter { command("pause") }
}
input "continue" {
guard { return state == "paused" }
body { state = "playing" }
adapter { command("pause") }
}
input "next song" {
guard { return song < songcount }
body { song += 1 }
adapter { command("pausing_keep pt_step 1") }
}
input "prev song" {
guard { return song > 1 }
body { song -= 1 }
adapter { command("pausing_keep pt_step -1") }
}
input "next song - already last" {
guard { return song == songcount }
adapter { command("pausing_keep pt_step 1") }
}
input "prev song - already first" {
guard { return song == 1 }
adapter { command("pausing_keep pt_step -1") }
}
input "add song" {
guard { return songcount < 5 }
body { songcount += 1 }
adapter { command("pausing_keep loadfile " + str(songcount+1) + ".mp3 1" ) }
}
input "reset playlist" {
body {
songcount = 1
song = 1
}
adapter { command("pausing_keep loadfile 1.mp3" ) }
}
tag "playing" {
guard { return state == "playing" }
adapter { assert playing() == True, "Player is not playing" }
}
tag "paused" {
guard { return state == "paused" }
adapter { assert playing() == False, "Player is not paused" }
}
tag "song==1", "song==2", "song==3" {
guard { return eval(tag_name) }
adapter {
if state == "playing":
assert openedMP3File() == song, "Playing incorrect song." + \
" Expected: %s, observed: %s." % (song, openedMP3File())
}
}
}