47 lines
1.2 KiB
Python
47 lines
1.2 KiB
Python
import os, random, vlc, phatbeat, time
|
|
|
|
|
|
class VLCdriver():
|
|
|
|
__init__(self, folder):
|
|
self.files = []
|
|
self.vlc_instance = vlc.Instance()
|
|
self.vlc_player = instance.media_player_new()
|
|
self.is_playing = False
|
|
|
|
def load_folder(self, folder):
|
|
# get list of files in music_dir
|
|
self.files = [ f for f in os.listdir(folder) if os.path.isfile(os.path.join(music_dir,f)) and f.endswith('.mp3') ]
|
|
print(f"loaded {folder}")
|
|
|
|
def play_file(self, path):
|
|
print(f"playing {path}")
|
|
self.media = self.vlc_instance.media_new(path)
|
|
self.vlc_player.set_media(self.media)
|
|
self.vlc_player.play()
|
|
self.is_playing = True
|
|
|
|
def play_random(self):
|
|
path = random.choice(self.files)
|
|
self.play_file(path)
|
|
|
|
@phatbeat.on(phatbeat.BTN_FASTFWD)
|
|
def fast_forward(pin):
|
|
self.play_random()
|
|
time.sleep(1)
|
|
|
|
@phatbeat.on(phatbeat.BTN_PLAYPAUSE)
|
|
def play_pause(pin):
|
|
if self.is_playing:
|
|
self.player.stop()
|
|
self.is_playing = False
|
|
else:
|
|
self.player.play()
|
|
self.is_playing = True
|
|
time.sleep(1)
|
|
|
|
|
|
d = VLCdriver()
|
|
d.load_folder('/home/jducastel/music/')
|
|
d.play_random()
|