aboutsummaryrefslogtreecommitdiff
path: root/helpers/actions/play.py
diff options
context:
space:
mode:
Diffstat (limited to 'helpers/actions/play.py')
-rw-r--r--helpers/actions/play.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/helpers/actions/play.py b/helpers/actions/play.py
new file mode 100644
index 0000000..fdba95b
--- /dev/null
+++ b/helpers/actions/play.py
@@ -0,0 +1,44 @@
1def run(action, music=None, fade_in=0, start_at=0,
2 restart_if_running=False, volume=100,
3 loop=0, **kwargs):
4 for music in action.music_list(music):
5 if restart_if_running:
6 if music.is_in_use():
7 music.stop()
8 music.play(
9 volume=volume,
10 fade_in=fade_in,
11 start_at=start_at,
12 loop=loop)
13 elif not music.is_in_use():
14 music.play(
15 volume=volume,
16 fade_in=fade_in,
17 start_at=start_at,
18 loop=loop)
19
20def description(action, music=None, fade_in=0, start_at=0,
21 restart_if_running=False, volume=100, loop=0, **kwargs):
22 message = "starting "
23 if music is not None:
24 message += "« {} »".format(music.name)
25 else:
26 message += "all musics"
27
28 if start_at != 0:
29 message += " at {}s".format(start_at)
30
31 if fade_in != 0:
32 message += " with {}s fade_in".format(fade_in)
33
34 message += " at volume {}%".format(volume)
35
36 if loop > 0:
37 message += " {} times".format(loop + 1)
38 elif loop < 0:
39 message += " in loop"
40
41 if restart_if_running:
42 message += " (restarting if already running)"
43
44 return message