コード例 #1
0
class AudioPlayer:
    def __init__(self):
        self.current_audio = MediaPlayer()

    def play(self, audio_path):
        self.audio_path = audio_path
        self.current_audio = MediaPlayer('file://' + audio_path)
        self.current_audio.play()

    def pause(self):
        self.current_audio.set_pause(True)

    def is_playing(self):
        return self.current_audio.is_playing()

    def resume(self):
        self.current_audio.set_pause(False)

    def set_volume(self, volume):
        volume = int(volume)
        self.current_audio.audio_set_volume(volume)

    def seek(self, target):
        self.current_audio.set_position(target)

    def seek_information(self):
        return (self.current_audio.get_position(), 1.0)

    def remaining(self):
        ms_left = (self.current_audio.get_length() -
                   self.current_audio.get_time()) / 1000

        return '-' + str(int(ms_left / 60)) + ':' + str(int(
            ms_left % 60)).zfill(2)

    def replay(self):
        self.play(self.audio_path)
コード例 #2
0
timecodes_ms = []
texts = []
for item in f.readlines():
	m = re.fullmatch('\[(?P<mm>\d\d):(?P<ss>\d\d).(?P<msms>\d\d)\](?P<txt>[\S ]+)?', item.strip())
	if m:
		if m.group('txt') != None:
			texts.append(m.group('txt'))
		else:
			texts.append('')
			
		timecodes_ms.append( (int(m.group('mm'))*60000) + (int(m.group('ss'))*1000) + (int(m.group('msms'))))
init = False
p.play()
while p.get_state() != State.Ended and p.get_state() != State.NothingSpecial:
	if p.get_state() != State.Opening:
		if init is False:
			duration = p.get_length()
			init = True
		pos_in_ms = duration*(p.get_position())
		if len(timecodes_ms)>0:
			if pos_in_ms>timecodes_ms[0]:
				if len(texts) == 1 and texts[0] == '':
					print('\n[THE END]\n(waiting for song file to end)')
				else:
					print(texts[0])
				del texts[0]
				del timecodes_ms[0]
	else:
		continue
	continue