Python VLC Audio Player

This forum is about all development around libVLC.
jthornton
New Cone
New Cone
Posts: 3
Joined: 02 Feb 2020 13:33

Python VLC Audio Player

Postby jthornton » 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.

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

mfkl
Developer
Developer
Posts: 739
Joined: 13 Jun 2017 10:41

Re: Python VLC Audio Player

Postby mfkl » 03 Feb 2020 05:00

Can you share the logs please?
https://mfkl.github.io

jthornton
New Cone
New Cone
Posts: 3
Joined: 02 Feb 2020 13:33

Re: Python VLC Audio Player

Postby jthornton » 03 Feb 2020 14:44

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

jthornton
New Cone
New Cone
Posts: 3
Joined: 02 Feb 2020 13:33

Re: Python VLC Audio Player

Postby jthornton » 04 Feb 2020 00:53

Logging is enabled but none are created when I run my program. When I run VLC I get logs...

JT

hansdampf
New Cone
New Cone
Posts: 2
Joined: 30 May 2020 23:29
VLC version: 3.0.10
Operating System: Windows

Re: Python VLC Audio Player

Postby hansdampf » 31 May 2020 01:32

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)


Return to “Development around libVLC”

Who is online

Users browsing this forum: No registered users and 27 guests