Update test.py
This commit is contained in:
47
test.py
47
test.py
@ -1,15 +1,46 @@
|
||||
import vlc, phatbeat
|
||||
|
||||
music_dir = '/home/jducastel/music/'
|
||||
import os, random, vlc, phatbeat, time
|
||||
|
||||
|
||||
class player():
|
||||
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_all(self):
|
||||
for song in self.files:
|
||||
p = vlc.MediaPlayer(file)
|
||||
p.play()
|
||||
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()
|
||||
|
Reference in New Issue
Block a user