def toggleLed(self, isTurnedOn): if isTurnedOn: log("Turning led ON") GPIO.output(self.ledGPIO, GPIO.HIGH) else: log("Turning led OFF") GPIO.output(self.ledGPIO, GPIO.LOW)
def buttonPressed(): global isInitiallyMode log('Button pressed received from Main') if isInitiallyMode: isInitiallyMode = False player.play(allParts[0]) button.toggleLed(True) return isPaused = player.pause() button.toggleLed(not isPaused)
def pause(self): if self.isPaused: pygame.mixer.music.unpause() self.isPaused = False log("UNPause") return self.isPaused else: pygame.mixer.music.pause() self.isPaused = True log("Pause") return self.isPaused
def rewButtonPressed(): global currentPartPlaying player.pause() if player.getPosition() > 60: log("Cofam do poczatku modulu") player.play(allParts[currentPartPlaying]) button.toggleLed(True) else: log("Laduje poprzedni modul") currentPartPlaying -= 1 player.play(allParts[currentPartPlaying]) button.toggleLed(True)
def button_callback(self, channel): log('Some button pressed') self.callbackButtonPressed()
def rewind(self): pygame.mixer.music.rewind() log('rewind?')
def getPosition(self): position = round(pygame.mixer.music.get_pos() / 1000) log("Get position " + str(position) + "sec") return round(position)
def play(self, fileToPlay): pygame.mixer.music.set_endevent(self.bookPartEndEvent) pygame.mixer.music.load(THIS_FOLDER + "/../book/" + fileToPlay) pygame.mixer.music.play() self.isPaused = False log("Playing next part: " + fileToPlay)
def loadNextPart(): global currentPartPlaying print(currentPartPlaying) log('End of part: ' + str(currentPartPlaying)) currentPartPlaying += 1 player.play(allParts[currentPartPlaying])
import pygame from src.Player import Player from src.Logger import loggerInit, log, error from src.FilesManager import getAllFileNames from src.Button import Button BOOK_PART_END = pygame.USEREVENT + 1 loggerInit() player = Player(BOOK_PART_END) log("--- APP STARTED ---") allParts = getAllFileNames() log('Loaded parts' + ', '.join(allParts)) currentPartPlaying = 0 isInitiallyMode = True if len(allParts) == 0: error("There is no book to play!") def buttonPressed(): global isInitiallyMode log('Button pressed received from Main') if isInitiallyMode: isInitiallyMode = False player.play(allParts[0]) button.toggleLed(True) return isPaused = player.pause()