Requesting help on Raspbian for python vlc playing audio -

*nix specific usage questions
theodore_dream
New Cone
New Cone
Posts: 5
Joined: 16 Aug 2020 00:44

Requesting help on Raspbian for python vlc playing audio -

Postby theodore_dream » 16 Aug 2020 22:37

Hello,

I'll share replication steps at the bottom but moreso just wanted to share general complaints about what a nightmare it has been to try to understand how to use libvlc / vlc in python3 implementation for running a script to play any ICY webcast / http stream. Just hoping for some guidance on how this could be setup for a simple implementation to play audio.

I've been debugging this for over a week now, I've reviewed all the following sources, giving some notes. I'll note that I am using VLC 3.0.11-0+deb10u1+rpt2 [from apt install vlc] Raspbian 5.4.51+ which is based on Debian. I'm using alsa for audio. I do understand that this is meant to be cross-platform with lots of support for different OS and different coding languages and that the python implementation is only managed by one volunteer. So these complaints may not be fair but I'm just throwing this out into the ether hoping someone has some more experience with this.

This works perfectly on command line "out of the box" all I have to do is run [apt install vlc]: --but hitting tons of modules issues in python script. I think the main thing is that its using pulseaudio even if I set output to alsa.

vlc -I dummy http://s1.voscast.com:8652/

A bit more detailed query: how can I do a simple implementation of vlc in python on Raspberry Pi in a python script, and ensure that I am loading all needed modules? The biggest issue that I've run into is that there are a lot of conflicting information about how to build and manage the vlc package dependencies/modules and configure them, and I haven't seen one single clear example of how to do it from start to finish. Whatever I'm doing, its not properly pulling in needed submodules like http and demuxers for audio and whatnot. More notes on information out there:

https://pypi.org/project/python-vlc/
- just says to use apt to install it, ok I tried that
https://wiki.videolan.org/python_bindings
- links to other locations such as below
https://git.videolan.org/?p=vlc/binding ... es;hb=HEAD
- these "helpful examples" are extremely technical and its unclear if these are meant to be sub-scripts that then you can call on for other functionality, or if these are actual examples of the implementation. Obviously I'm not a full time python developer and it seems that's the only target audience, because this is unreadable to anyone who isn't an expert already
https://git.videolan.org/?p=vlc/binding ... README.rst
- information on building from source, the VLC package on Raspbian
https://github.com/oaubert/python-vlc
- the github repo of the project owner for python vlc, I've read through the main docs on his site as well as many of the issues sections here, some halfway decent examples but nothing that provides a full clear example

So I've tried:
- multiple version of libvlc, vlc, libvlc-dev, etc, moving vlc.py into the same directory as my main script... tons of different command line options... nothing.

Seems all I should have to do is:
# apt install vlc
# sudo apt install python3-pip
# pip3 install python-vlc
Then I should have access to all the libvlc stuff from python-vlc module... but not sure if its working.

I can easily replicate by following this blog post [https://linuxconfig.org/how-to-play-aud ... -in-python] and at this point I'm thinking
- I'm hitting a raspberry Pi specific issue
- using python vlc is **NOT** the same thing as just using vlc in the command line, but I don't understand how/why

More logs in next post...
Last edited by theodore_dream on 17 Aug 2020 20:02, edited 5 times in total.

theodore_dream
New Cone
New Cone
Posts: 5
Joined: 16 Aug 2020 00:44

Re: Using python vlc implementation for streaming online radio - is a nightmare, poor example documentation

Postby theodore_dream » 16 Aug 2020 22:39

POST PART 2 OF 3 One example of replication of the issue:

Code: Select all

import vlc def stream(): url = "http://s1.voscast.com:8652/" i = vlc.Instance("-I dummy --no-video --aout=alsa --file-logging --logfile=vlc-log.txt --verbose 3") player = i.media_player_new() Media = i.media_new(url) player.set_media(Media) player.play() stream()
Debug logs example of trying a script like this:
To help you, we need messages, to completely understand what your problems is.

From windows command line or linux or macos terminal, launch vlc with options -vv and --logfile=file

  • Windows example: vlc.exe -vv --logfile=c:\vlclog.txt
  • Linux example: vlc -vv --logfile=vlclog.txt, or vlc -vv 2>&1 > logfile.txt
Then paste the full resulting log here between [​code]and[​/code] (or use Pastebin.com if it's too long)

Also don't forget to name your Operating System and provide the VLC media player version.

theodore_dream
New Cone
New Cone
Posts: 5
Joined: 16 Aug 2020 00:44

Re: Using python vlc implementation for streaming online radio - is a nightmare, poor example documentation

Postby theodore_dream » 16 Aug 2020 22:43

Here is pastebin of debug logs: https://pastebin.com/Q3MGVnha

This is what I see when I run the command:

python3 test.py
[01830360] vlcpulse audio output error: PulseAudio server connection failure: Connection refused
[01847e10] vlcpulse audio output error: PulseAudio server connection failure: Connection refused

Then the logs go into vlc-log.txt, see Pastebin above.

Next steps for me, I guess:
- try to stop PulseAudio from being called, maybe play with /home/pi/.config/vlc/vlcrc
- try reinstall and then try one at a time: vlc with pip3 vlc installed, then remove all that and try again with libvlc-dev, then try again with libvlc, maybe make sure I'm importing properly into my python script... maybe having vlc.py in the same directory as my main script is calling to wrong file location for vlc ... just really weird to me that it works perfectly with command line but this python implementation is not working the same and I can't understand

Edited update:
- updating this post to say that I entirely re-imaged my OS and re-set up _everything_ and I'm able to replicate the issue with only vlc package and pip3 module python-vlc installed, which *should* work according to most information online..

If anyone has read through all this, thank you very much, hoping someone can help guide me .. sorry if this is rambly. I can provide any further details that may be helpful.

theodore_dream
New Cone
New Cone
Posts: 5
Joined: 16 Aug 2020 00:44

Re: Requesting help on Raspbian for python vlc playing audio -

Postby theodore_dream » 17 Aug 2020 21:02

One more update to say that I am using the following as a workaround, running vlc with the subprocess Popen and shell=True as a workaround and its working ok so I'll probably just use this ... even if it doesn't give me as much control over the vlc command and managing it - at least it works...

Code: Select all

#!/usr/bin/python3 import subprocess from subprocess import Popen from subprocess import check_call cmd = ['vlc -I dummy --no-video --aout=alsa --alsa-audio-device default --file-logging --logfile=vlc-log.txt --verbose 3 http://s1.voscast.com:8652'] p = subprocess.Popen(cmd, shell=True) assert not p.poll() check_call(cmd)

peppy.player
Blank Cone
Blank Cone
Posts: 38
Joined: 10 Nov 2017 00:07

Re: Requesting help on Raspbian for python vlc playing audio -

Postby peppy.player » 18 Aug 2020 05:10

Hi theodore_dream,

I've been using python-vlc for a long time with ALSA and never faced the issues which you described. I install it the same way (with 'sudo' for apt-get):

Code: Select all

sudo apt-get install vlc sudo apt-get install python3-pip pip3 install python-vlc
I use the following startup parameters:

Code: Select all

--aout=alsa --alsa-audio-device=hw --verbose=-1
and it works fine with web radio and audio files. You can find the player code here:
https://github.com/project-owner/Peppy/ ... cclient.py

You can also install the Headless disk image of the Peppy Player:
https://github.com/project-owner/PeppyP ... isk-Images
It has everything installed and configured (vlc and python-vlc). It runs on the latest Raspberry Pi OS. You can ignore the Peppy player and play with vlc and python-vlc. Or play with the Peppy player code. It's up to you. Feel free to ask any questions.

Good luck!

theodore_dream
New Cone
New Cone
Posts: 5
Joined: 16 Aug 2020 00:44

Re: Requesting help on Raspbian for python vlc playing audio -

Postby theodore_dream » 18 Aug 2020 18:28

Thank you peppy ! I may use some of that :) and thanks to Olivier Aubert (discussed in Github issues) this is resolved. I needed the python3-vlc package from apt. For some reason the pip3 module didn't work and I wasn't aware of the apt package. Here's the steps:

# sudo apt install vlc python3-vlc

then run in python

import vlc
p = vlc.MediaPlayer('http://s1.voscast.com:8652')
p.play()

Works perfectly. This thread can be marked solved/closed... !

robotman68
New Cone
New Cone
Posts: 1
Joined: 05 Sep 2020 03:08

Re: Requesting help on Raspbian for python vlc playing audio -

Postby robotman68 » 05 Sep 2020 03:15

I have been ignoring "[01830360] vlcpulse audio output error: PulseAudio server connection failure: Connection refused" error.
All I really want to do is push a button or turn a rotary encoder and have the next playlist, stream or file play.
I feel your pain, examples for many things are super basic and then way to difficult to figure out. I am slowly learning. Good Luck.


Return to “VLC media player for Linux and friends Troubleshooting”

Who is online

Users browsing this forum: No registered users and 9 guests