Page 1 of 1

Python VLC Audio Player

Posted: 02 Feb 2020 14:02
by jthornton
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.

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)
The terminal output

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$
Thanks
JT

Re: Python VLC Audio Player

Posted: 03 Feb 2020 05:00
by mfkl
Can you share the logs please?

Re: Python VLC Audio Player

Posted: 03 Feb 2020 14:44
by jthornton
Your message contains 139069 characters.
The maximum number of allowed characters is 5998.

I don't see an option to attach a file, the logfile is bigger than allowed.

JT

Re: Python VLC Audio Player

Posted: 04 Feb 2020 00:53
by jthornton
Logging is enabled but none are created when I run my program. When I run VLC I get logs...

JT

Re: Python VLC Audio Player

Posted: 31 May 2020 01:32
by hansdampf
To avoid misunderstandings.
In this context, I understood sound as music.

I could run this Python program on my Windows 10 laptop and on my Raspberry Pi 4 and it works fine. :wink:
Only some messages from vlc.
I used Python 3.8.2 in Windows and Python 3.7.3 on my Raspberry Pi 4.

In the past, I have also got a lot of trouble with Bluetooth speakers and PulseAudio/alsa. :evil:
Therefore I deactivate BT and uninstalled PulseAudio, using alsa for audio output (analog connection).

Maybe the following could be helpful to tell VLC/Raspberry Pi to be quiet and use alsa.

Code: Select all

#!/usr/bin/env python3 import time import platform import vlc from vlc import EventType if platform.system() == 'Windows': instance = vlc.Instance('--quiet') path = 'd:/' else: instance = vlc.Instance('--quiet', '--aout=alsa') path = '/home/pi/' mlp = instance.media_list_player_new() mp = instance.media_player_new() # 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 = instance.media_list_new() ml.add_media(path + 'song1.mp3') ml.add_media(path + 'song2.mp3') ml.add_media(path + 'song1.mp3') # ... and much more for 10 minutes playtime mlp.set_media_list(ml) mp.audio_set_volume(30) mp.audio_set_mute(False) mlp.play() time.sleep(600)
Good luck. 8)