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.

sumitkm
  • 111
  • 4

0 Answers0