class MusicBar(Frame): def __init__(self, parent, music_filepath): Frame.__init__(self, parent) self.player = Player(music_filepath) title = os.path.basename(music_filepath) label = tkinter.Label(self, text=title, width=30) label.pack(side=LEFT) padx = 10 #image = tkinter.PhotoImage(file=icon_play) play_button = Button(self, text="Play")#image=image) play_button.pack(side=LEFT, padx=padx) play_button.bind("<Button-1>", self.play) #image = tkinter.PhotoImage(file=icon_pause) #pause_button = Button(self, text="Pause")#image=image) #pause_button.pack(side=LEFT, padx=padx) #pause_button.bind("<Button-1>", self.pause) #self.pausing = False #image = tkinter.PhotoImage(file=icon_stop) stop_button = Button(self, text="Stop")#image=image) stop_button.pack(side=LEFT, padx=padx) stop_button.bind("<Button-1>", self.stop) #MusicBar(self, music_filepath) def play(self, event): self.player.play() def stop(self, event): self.player.stop()
def reset_music(): global albumCover global songTitle global albumTitle global totalTime global musicData global currentMusic global durationTime global slider global anim global image global start global currentValue global anim_timeline global playedTime global player if (anim_timeline != None): lv.anim_timeline_stop(anim_timeline) lv.anim_timeline_del(anim_timeline) anim_timeline = None albumCover.set_src(musicData[currentMusic]["album_url"]) songTitle.set_text(musicData[currentMusic]["title"]) albumTitle.set_text(musicData[currentMusic]["album"]) durationTime = musicData[currentMusic]["duration"] currentValue = 0 slider.set_range(0, durationTime) slider.set_value(0, lv.ANIM.ON) anim.set_time(durationTime * 1000) anim.set_values(0, durationTime) anim_timeline = lv.anim_timeline_create() lv.anim_timeline_add(anim_timeline, 0, anim) setLabelValue(totalTime, durationTime) setLabelValue(playedTime, 0) if (player != None): player.pause() player.close() player = None if (start == False): image[1].set_src(RESOURCES_ROOT + "images/play.png") else: image[1].set_src(RESOURCES_ROOT + "images/pause.png") lv.anim_timeline_start(anim_timeline) player = Player() player.open() player.play(musicData[currentMusic]["url"], sync=False) player.on(cb) if (musicData[currentMusic]["favorite"] == False): image[3].set_src(RESOURCES_ROOT + "images/favorite.png") else: image[3].set_src(RESOURCES_ROOT + "images/favorited.png")
def controller_click_cb(e, func): global anim global start global anim_timeline global durationTime global player global image global currentValue global musicData global currentMusic print(func, anim_timeline) if (func == "play"): if (start == False): start = True if (currentValue == durationTime): currentValue = 0 anim.set_time((durationTime - currentValue) * 1000) anim.set_values(currentValue, durationTime) anim_timeline = lv.anim_timeline_create() lv.anim_timeline_add(anim_timeline, 0, anim) lv.anim_timeline_start(anim_timeline) image[1].set_src(RESOURCES_ROOT + "images/pause.png") if (player == None): player = Player() player.open() player.play(musicData[currentMusic]["url"], sync=False) player.on(cb) else: player.resume() # state = player.getState() # print(state) # if (state == 2): # player.resume() # image[1].set_src(RESOURCES_ROOT + "images/pause.png") # else: # player.pause() # image[1].set_src(RESOURCES_ROOT + "images/play.png") else: start = False image[1].set_src(RESOURCES_ROOT + "images/play.png") lv.anim_timeline_stop(anim_timeline) lv.anim_timeline_del(anim_timeline) anim_timeline = None anim.set_time((durationTime - currentValue) * 1000) anim.set_values(currentValue, durationTime) anim_timeline = lv.anim_timeline_create() lv.anim_timeline_add(anim_timeline, 0, anim) player.pause() elif (func == "fav"): if (musicData[currentMusic]["favorite"] == False): image[3].set_src(RESOURCES_ROOT + "images/favorited.png") musicData[currentMusic]["favorite"] = True else: musicData[currentMusic]["favorite"] = False image[3].set_src(RESOURCES_ROOT + "images/favorite.png") elif (func == "next"): currentMusic += 1 if (len(musicData) == currentMusic): currentMusic = 0 reset_music() elif (func == "prev"): currentMusic -= 1 if (currentMusic < 0): currentMusic = len(musicData) - 1 reset_music()