path = os.path.dirname(os.path.realpath(__file__))
return path + "/../"
+def duration_to_min_sec(duration):
+ minutes = int(duration / 60)
+ seconds = int(duration) % 60
+ if minutes < 100:
+ return "{:2}:{:0>2}".format(minutes, seconds)
+ else:
+ return "{}:{:0>2}".format(minutes, seconds)
def run(self):
print(self.description())
getattr(self, self.action)(**self.arguments)
- #pygame.event.post(pygame.event.Event(pygame.USEREVENT))
def description(self):
return getattr(self, self.action + "_print")(**self.arguments)
if music is not None:
music.pause()
else:
- pygame.mixer.pause()
+ for music in self.key.parent.open_files.values():
+ if music.is_playing() and not music.is_paused():
+ music.pause()
def unpause(self, music = None, **kwargs):
if music is not None:
music.unpause()
else:
- pygame.mixer.unpause()
+ for music in self.key.parent.open_files.values():
+ if music.is_playing() and music.is_paused():
+ music.unpause()
def play(self, music = None, fade_in = 0, start_at = 0,
restart_if_running = False, volume = 100, **kwargs):
import pydub
import pygame
import math
+import time
class MusicFile:
def __init__(self, filename, lock, channel_id, name = None, gain = 1):
def is_paused(self):
return self.flag_paused
+ @property
+ def sound_position(self):
+ if self.is_playing() and not self.is_paused():
+ return min(time.time() - self.started_at, self.sound_duration)
+ elif self.is_playing() and self.is_paused():
+ return min(self.paused_at - self.started_at, self.sound_duration)
+ else:
+ return 0
+
def play(self, fade_in = 0, volume = 100, start_at = 0):
self.channel().set_endevent()
self.channel().set_endevent(pygame.USEREVENT)
else:
sound = pygame.mixer.Sound(self.raw_data)
+ self.started_at = time.time()
self.channel().play(sound, fade_ms = int(fade_in * 1000))
self.flag_paused = False
def pause(self):
+ self.paused_at = time.time()
self.channel().pause()
self.flag_paused = True
def unpause(self):
+ self.started_at += (time.time() - self.paused_at)
self.channel().unpause()
self.flag_paused = False
text: self.parent.first_key
text_size: None, None
valign: "top"
+ halign: "center"
size_hint: None, None
size: self.parent.width, self.texture_size[1]
pos: 0, self.parent.height - self.height
text: self.parent.second_key
text_size: None, None
valign: "top"
+ halign: "center"
size_hint: None, None
size: self.parent.width, self.texture_size[1]
pos: 0, self.parent.height - key_list_first.height - self.height
text: self.parent.third_key
text_size: None, None
valign: "top"
+ halign: "center"
size_hint: None, None
size: self.parent.width, self.texture_size[1]
pos: 0, self.parent.height - key_list_first.height - key_list_second.height - self.height
text: "\n".join(self.parent.keylist[3:])
text_size: None, None
valign: "top"
+ halign: "center"
size_hint: None, None
size: self.parent.width, self.texture_size[1]
pos: 0, self.parent.height - key_list_first.height - key_list_second.height - key_list_third.height - self.height
size_hint: None, None
pos: 15, self.y
size: self.texture_size[0], self.parent.height
+ Label:
+ id: playlist_times
+ font_name: h.path() + "fonts/Ubuntu-Regular.ttf"
+ line_height: self.parent.parent.ubuntu_regular_line_height or 1
+ font_size: math.ceil(2 * math.sqrt(self.parent.parent.key_size or 10))
+ color: 0, 0, 0, 1
+ text: "\n".join(map(lambda x: x[2], self.parent.playlist))
+ text_size: None, self.parent.height
+ halign: "left"
+ valign: "top"
+ size_hint: None, None
+ pos: self.parent.width - 3 * self.width / 2 - 2 * (self.parent.parent.border or 0), self.y
+ size: self.texture_size[0], self.parent.height
<Mapping>:
size_hint: None, None
third_key = StringProperty("")
def append(self, value):
- self.keylist = [value] + self.keylist
+ self.keylist.insert(0, value)
def on_keylist(self, instance, new_key_list):
if len(self.keylist) > 0:
for music_file in open_files.values():
if not music_file.is_playing():
continue
+
+ text = "{}/{}".format(
+ helpers.duration_to_min_sec(music_file.sound_position),
+ helpers.duration_to_min_sec(music_file.sound_duration)
+ )
+
if music_file.is_paused():
- self.playlist.append(["⏸", music_file.name, False])
+ self.playlist.append(["⏸", music_file.name, text, False])
else:
- self.playlist.append(["⏵", music_file.name, True])
+ self.playlist.append(["⏵", music_file.name, text, True])
class ActionList(RelativeLayout):