Python VLC Audio Player
Posted: 02 Feb 2020 14:02
I'm trying to code a Python VLC audio player for my chicken coop control that runs on a Raspberry Pi 3. I've been searching and trying for a week with only partial success. I get get the following to play one song but then no sound. The events keep showing up but no sound. I just use time.sleep for testing in the PyQt5 application it runs all the time.
if you know of a "working" example I'd love to see it. I've found 14 examples that either don't work at all or only play one song. The ultimate is to just play randomly all the songs in /home/john/Music.
The terminal output
Thanks
JT
if you know of a "working" example I'd love to see it. I've found 14 examples that either don't work at all or only play one song. The ultimate is to just play randomly all the songs in /home/john/Music.
Code: Select all
#!/usr/bin/env python3
from vlc import *
import time
mlp = MediaListPlayer()
mp = MediaPlayer()
mlp.set_media_player(mp)
def cb(event):
print ("cb:", event.type, event.u)
mlp_em = mlp.event_manager()
mlp_em.event_attach(EventType.MediaListPlayerNextItemSet, cb)
mp_em = mp.event_manager()
mp_em.event_attach(EventType.MediaPlayerEndReached, cb)
mp_em.event_attach(EventType.MediaPlayerMediaChanged, cb)
ml = MediaList()
ml.add_media("/home/john/jtmusic/brick1.mp3")
ml.add_media("/home/john/jtmusic/alabam.mp3")
ml.add_media("/home/john/jtmusic/brick3.mp3")
mlp.set_media_list(ml)
mp.audio_set_volume(30)
mp.audio_set_mute(False)
mlp.play()
time.sleep(600)
Code: Select all
john@d10cave:~/github/music$ ./vlc1.py
cb: EventType.MediaPlayerMediaChanged <vlc.EventUnion object at 0x7ff751c1f2f0>
cb: EventType.MediaListPlayerNextItemSet <vlc.EventUnion object at 0x7ff751c1f2f0>
cb: EventType.MediaPlayerEndReached <vlc.EventUnion object at 0x7ff751c1f2f0>
cb: EventType.MediaPlayerMediaChanged <vlc.EventUnion object at 0x7ff751c1f2f0>
cb: EventType.MediaListPlayerNextItemSet <vlc.EventUnion object at 0x7ff751c1f2f0>
cb: EventType.MediaPlayerEndReached <vlc.EventUnion object at 0x7ff751c1f2f0>
cb: EventType.MediaPlayerMediaChanged <vlc.EventUnion object at 0x7ff751c1f2f0>
cb: EventType.MediaListPlayerNextItemSet <vlc.EventUnion object at 0x7ff751c1f2f0>
cb: EventType.MediaPlayerEndReached <vlc.EventUnion object at 0x7ff751c1f2f0>
john@d10cave:~/github/music$
JT