Re: Pyglet help
I merged the file search segment with the prototype class, so what you do is enter the directory and nearest search word, and it will spit out a list of matching songs numbered from first to last. Enter the corresponding number and press enter to play your track of choice:
import os.path
import glob
import pyglet
from pyglet.window import key
class Prototype(pyglet.window.Window): def __init__(self): super(Prototype, self).__init__(640, 480, resizable=False, fullscreen=False, caption="Test") self.clear() self.types = [".mp3", ".wav", ".flac", ".mp4", ".mpg", ".avi", ".m4a"] self.types = str(self.types) self.playlist = [] self.path = input("Enter the path to your music folder.") self.letter = input("Name of the song? ") print(os.getcwd()) #list directories with os.scandir(self.path) as it: for entry in it: if not entry.name.startswith('.') and entry.is_file(): name = os.path.splitext(str(os.path.split(entry)[1])) if self.letter in name[0].lower(): if name[1].lower() in self.types: self.playlist += [name[0]+name[1]] ## print(self.playlist) if len(self.playlist) > 0: for a in range(0,len(self.playlist),1): print(a,". "+self.playlist[a]) self.index = int(input("select track:")) self.music = pyglet.media.StaticSource(pyglet.media.load(self.path+"\\"+self.playlist[self.index],streaming=False)) self.player = pyglet.media.Player() pyglet.clock.schedule_interval(self.update, .01) def update(self,dt): if self.player.playing == False: self.player.queue(self.music) self.player.play() #draw screen self.draw() def draw(self): self.clear() def on_key_press(self,symbol,modifiers): if symbol == key.UP and self.player.volume < 2.0: self.player.volume += 0.1 print(self.player.volume) if symbol == key.DOWN and self.player.volume > 0.0: self.player.volume -= 0.1 print(self.player.volume) if symbol == key.LEFT: print(self.player.time) if self.player.time - 10.0 < 0.0: self.player.seek(0.0) else: self.player.seek(self.player.time - 10.0) print(self.player.time) if symbol == key.RIGHT: print(self.player.time) get_duration = self.music.duration if self.player.time + 10.0 > get_duration: self.player.seek(get_duration) else: self.player.seek(self.player.time + 10.0) print(self.player.time) if symbol == key.ESCAPE: self.close() if __name__ == '__main__': window = Prototype() pyglet.app.run()
-- Audiogames-reflector mailing list Audiogames-reflector@sabahattin-gucukoglu.com https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector