My latest try is with this class I found:
Code: Select all
class AudioPlayer:
def __init__(self):
self.instance = vlc.Instance()
self.mediaplayer = self.instance.media_player_new()
self.mediaplayer.audio_set_volume(15)
self.event_manager = self.mediaplayer.event_manager()
self.event_manager.event_attach(vlc.EventType.MediaPlayerEndReached, self.trackEnded)
self.event_manager.event_attach(vlc.EventType.MediaPlayerMediaChanged, self.mediaChanged)
self.titleNum = 0
self.playlist = []
print ("Player Created")
def add_to_playlist(self, newtrack):
self.playlist.append(newtrack)
print ("Playlist Updated")
def loadTrack(self, path):
return self.instance.media_new(path)
print("track loaded")
def playTrack(self, track):
print ("Entered playTrack")
print track
self.mediaplayer.set_media(track)
print("PLAYING TRACK")
self.mediaplayer.play()
def playCurrTrack(self):
print("trying to load new track...")
track = self.loadTrack(self.playlist[self.titleNum])
print("trying to play track...")
self.playTrack(track)
def trackEnded(self, event):
print("Track ended")
self.nextTrack()
def mediaChanged(self, event):
print("Media Changed")
def prevTrack(self):
self.setTitle(self.getTitle()-1)
self.playCurrTrack()
def nextTrack(self):
print ("Get Next Track")
self.setTitle(self.getTitle()+1)
self.playCurrTrack()
def getTitle(self):
return self.titleNum
def setTitle(self, number):
self.titleNum = number
if self.titleNum < 0:
self.titleNum = len(self.playlist) + self.titleNum
elif self.titleNum >= len(self.playlist):
self.titleNum = len(self.playlist) - self.titleNum
print("track %i of %i: %s" % (self.titleNum+1, len(self.playlist), self.playlist[self.titleNum]))
Code: Select all
def main():
try:
print "Ready.."
global myplayer
myplayer = AudioPlayer()
myplayer.add_to_playlist(random_selector())
myplayer.playCurrTrack()
Code: Select all
def random_selector():
#removed R for Radio & V for playlists
string.letters="ABCDEFGHJKLMNPQST"
string.numbers="12345678"
LET = random.choice(string.letters)
NUM = random.choice(string.numbers)
track_choice = m_path+LET+NUM
return track_choice
Code: Select all
def new_track_callback(channel):
# call new track when button pressed
global myplayer
myplayer.add_to_playlist(random_selector())
print ("New Track Added")
Code: Select all
def playTrack(self, track):
print ("Entered playTrack")
print track
self.mediaplayer.set_media(track)
print("PLAYING TRACK")
self.mediaplayer.play()
Track ended
Get Next Track
track 2 of 2: /mnt/usb/C4
trying to load new track...
trying to play track...
Entered playTrack
<vlc.Media object at 0x7649ef50>