1

I am trying to setup an audio player in Python using vlc.py bindings, but the simplest of code seems to throw an error. I want it running headless so I am trying all my experiments over SSH.

Code

import os
import sys  
import vlc  

p = vlc.MediaPlayer("iwyb.mp3")  
p.play()  

while(1):  
    continue  

I have also tried

import os
import sys
import vlc
if __name__ == '__main__':
    filepath = "iwyb.mp3"
    movie = os.path.expanduser(filepath)
    if 'http://' not in filepath:
        if not os.access(movie, os.R_OK):
            print ( 'Error: %s file is not readable' % movie )
            sys.exit(1)
        instance = vlc.Instance() # <-- what goes here?
        try:
            media = instance.media_new(movie)
        except NameError:
            print ('NameError: % (%s vs Libvlc %s)' % (sys.exc_info()[1],
                       vlc.__version__, vlc.libvlc_get_version()))
            sys.exit(1)
        player = instance.media_player_new()
        player.set_media(media)
        player.play()
while(1):
    continue

Error (in both cases)

[01a7f9a0] pulse audio output error: PulseAudio server connection failure: Connection refused
[019f0978] pulse audio output error: PulseAudio server connection failure: Connection refused
[019f0978] alsa audio output error: cannot commit hardware parameters: Invalid argument
[019f0978] core audio output error: module not functional
[b4d114d8] core decoder error: failed to create audio output

However if I run the vlc player command line version I get the following errors but the song plays

cmd

cvlc iwyb.mp3

Output

VLC media player 2.2.1 Terry Pratchett (Weatherwax) (revision 2.2.1-0-ga425c42)   
[005196a8] pulse audio output error: PulseAudio server connection failure: Connection refused
[00527ca8] core interface error: no suitable interface module
[0048a8f8] core libvlc error: interface "globalhotkeys,none" initialization failed
[00527d10] dbus interface error: Failed to connect to the D-Bus session daemon: Unable to autolaunch a dbus-daemon without a $DISPLAY for X11
[00527d10] core interface error: no suitable interface module
[0048a8f8] core libvlc error: interface "dbus,none" initialization failed
[00527ce8] dummy interface: using the dummy interface module...

aplay -l gives the following

**** List of PLAYBACK Hardware Devices ****
card 0: sndrpijustboomd [snd_rpi_justboom_dac], device 0: JustBoom DAC HiFi pcm512x-hifi-0 []
Subdevices: 1/1
Subdevice #0: subdevice #0

I guess, I am missing a magic string here somewhere. I have seen in the wild people pass around strings to the Instance constructor so my question is what is this magic string and where can I find more information about it? Apart from the sparse API documentation I haven't made much progress.

  • Minor progress in the morning. Initializing Interface with magic string "--aout=alsa" removes the pulse audio errors. Which is obvious because the Justboom DAC is an alsa device. Now to figure out how to specify codec or decoder or whatever else is missing. – sumitkm Mar 11 '17 at 11:56
  • I have, for now, given up the quest of "vlc magic strings". PyGame's music api seems sufficient enough for my needs at the moment and seems to work with my setup painlessly! pygame.org/docs/ref/music.html – sumitkm Mar 12 '17 at 3:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.