vicwomg / pikaraoke

Youtube-based Karaoke machine for Raspberry Pi, OSX, Windows, and Linux
511 stars 135 forks source link

VLC fails to output audio to headphone jack and only supports HDMI [RaspberryPi3] #74

Closed scottackerson closed 3 years ago

scottackerson commented 3 years ago

Using VLC via --force-vlc on a Raspberry Pi does not allow audio to output to the headphone jack and only works on the HDMI audio output. I have configured the Raspberry Pi to default to audio output to Headphones (raspi-config) and running VLC from the command line plays the output on the headphone jack and HDMI output. When playing a file from pikaraoke, the output is only to the HDMI output with the following logging info:

[2020-12-22 20:28:40] INFO: Playing video in VLC: Bad To The Bone - George Thorogood _ Karaoke Version _ KaraFun
Command: ['/usr/bin/vlc', '-f', '--play-and-exit', '--extraintf', 'http', '--http-port', '5002', '--http-password', '0LJwDTFuVYv2yssEXiCL7Jaztpy3XaG6', '--no-embedded-video', '--no-keyboard-events', '--no-mouse-events', '--mouse-hide-timeout', '0', '--video-on-top', '--no-video-title', '--mouse-hide-timeout', '0', '/usr/lib/pikaraoke/songs/Bad To The Bone - George Thorogood _ Karaoke Version _ KaraFun---fDjkjA2UnCE.mp4']
VLC media player 3.0.11 Vetinari (revision 3.0.11-0-gdc0c5ced72)
[01658560] vlcpulse audio output error: PulseAudio server connection failure: Connection refused
[0166d280] dbus interface error: Failed to connect to the D-Bus session daemon: Unable to autolaunch a dbus-daemon without a $DISPLAY for X11
[0166d280] main interface error: no suitable interface module
[015dcb58] main libvlc error: interface "dbus,none" initialization failed
[0166d280] [http] lua interface: Lua HTTP interface
[0167cb18] main interface error: no suitable interface module
[015dcb58] main libvlc error: interface "globalhotkeys,none" initialization failed
[015dcb58] main libvlc: Running vlc with the default interface. Use 'cvlc' to use vlc without interface.
error: XDG_RUNTIME_DIR not set in the environment.

When playing the same file using the same command line parameters, the file plays appropriately on the headphone jack and the logging info producing:

pi@raspberrypi:/usr/lib/pikaraoke/songs $ /usr/bin/vlc -f --play-and-exit --extraintf http --http-port 5002 --http-password 0LJwDTFuVYv2yssEXiCL7Jaztpy3XaG6 --no-embedded-video --no-keyboard-events --no-mouse-events --mouse-hide-timeout 0 --video-on-top --no-video-title --mouse-hide-timeout 0 '/usr/lib/pikaraoke/songs/Bad To The Bone - George Thorogood _ Karaoke Version _ KaraFun---fDjkjA2UnCE.mp4'
VLC media player 3.0.11 Vetinari (revision 3.0.11-0-gdc0c5ced72)
[007023d0] [http] lua interface: Lua HTTP interface
[0070e188] main interface error: no suitable interface module
[0067ab58] main libvlc error: interface "globalhotkeys,none" initialization failed
[007023d0] [http] main interface error: socket bind error: Address already in use
[0067ab58] main libvlc: Running vlc with the default interface. Use 'cvlc' to use vlc without interface.
[007023d0] [http] main interface error: socket bind error: Address already in use
[007023d0] [http] main interface error: cannot create socket(s) for HTTP host
[007023d0] [http] lua interface error: Error loading script /usr/lib/arm-linux-gnueabihf/vlc/lua/intf/http.luac: lua/intf/http.lua:336: Failed to create HTTP host
[0070e188] skins2 interface error: cannot initialize OSFactory

The difference here being that vlcPulse audio is being pulled in when using pikaraoke and not when using VLC via command line.

vicwomg commented 3 years ago

That's strange, this was tested extensively. I wonder if the behavior changed recently in Raspbian. Are you running from Raspbian desktop or a raw command line? What version?

vicwomg commented 3 years ago

I also feel like this might be some kind of audio driver access issue when running pikaraoke as sudo vs running vlc as the logged in desktop user: https://unix.stackexchange.com/questions/445386/pulseaudio-server-connection-failure-connection-refused-debian-stretch

scottackerson commented 3 years ago

I'm running Buster... but it might be due to an extremely old device that I have. It's been through some rough physical trauma over the years. I had found that other link and tried that with no success. I'm going to try with a new device tonight and retest. I'll report back after that. Thanks!

vicwomg commented 3 years ago

Hm yeah, buster is quite old. Not sure I've fully tested there in a while.

If you still see this after upgrade, try running the command manually both with/without sudo and see if there's a difference. I'll bet one of them doesn't have the proper access to PulseAudio under certain conditions

scottackerson commented 3 years ago

I was able to test on a Raspberry Pi 4 and I'm still not getting audio out of the headphone jack, even with then raspi-config change to the audio output to be headphone.

Running 10.7

vicwomg commented 3 years ago

What about my other questions:

Knowing this would definitely save me time in troubleshooting

scottackerson commented 3 years ago

sorry, I could have done those steps days ago!

Running Rasbian lite CLI. It does work not using sudo and DOES work without sudo.

vicwomg commented 3 years ago

I can confirm this issue. With sudo, vlc has no audio.

sudo:

VLC media player 3.0.11 Vetinari (revision 3.0.11-0-gdc0c5ced72)
[01263d28] vlcpulse audio output error: PulseAudio server connection failure: Connection refused
[0126ff50] dbus interface error: Failed to connect to the D-Bus session daemon: Unable to autolaunch a dbus-daemon without a $DISPLAY for X11
[0126ff50] main interface error: no suitable interface module
[011e4b58] main libvlc error: interface "dbus,none" initialization failed
[01266590] main interface error: no suitable interface module
[011e4b58] main libvlc error: interface "globalhotkeys,none" initialization failed
[011e4b58] main libvlc: Running vlc with the default interface. Use 'cvlc' to use vlc without interface.
error: XDG_RUNTIME_DIR not set in the environment.
[01266590] skins2 interface error: cannot initialize OSFactory
[01266590] [cli] lua interface: Listening on host "*console".
VLC media player 3.0.11 Vetinari
Command Line Interface initialized. Type `help' for help.
> [b394ab48] mmal_codec decoder: VCSM init succeeded: CMA
error: XDG_RUNTIME_DIR not set in the environment.
error: XDG_RUNTIME_DIR not set in the environment.
[ad043598] gles2 generic error: parent window not available
[ad042f80] mmal_xsplitter vout display error: Failed to open Xsplitter:opengles2 module
[ad043598] xcb generic error: window not available
[ad042f80] mmal_xsplitter vout display error: Failed to open Xsplitter:xcb_x11 module
[b394ab48] main decoder error: buffer deadlock prevented

no sudo:

VLC media player 3.0.11 Vetinari (revision 3.0.11-0-gdc0c5ced72)
[01872ce8] vlcpulse audio output error: PulseAudio server connection failure: Connection refused
[018a86a0] main interface error: no suitable interface module
[017f7b58] main libvlc error: interface "globalhotkeys,none" initialization failed
[017f7b58] main libvlc: Running vlc with the default interface. Use 'cvlc' to use vlc without interface.
[018a86a0] skins2 interface error: cannot initialize OSFactory
[018a86a0] [cli] lua interface: Listening on host "*console".
VLC media player 3.0.11 Vetinari
Command Line Interface initialized. Type `help' for help.
> [b0314e48] mmal_codec decoder: VCSM init succeeded: CMA
[b0314e48] main decoder error: buffer deadlock prevented
[b0362aa8] gles2 generic error: parent window not available
[b0372840] mmal_xsplitter vout display error: Failed to open Xsplitter:opengles2 module
[b0362aa8] xcb generic error: window not available
[b0372840] mmal_xsplitter vout display error: Failed to open Xsplitter:xcb_x11 module
vicwomg commented 3 years ago

This seemed to fix it for me:

edit: /boot/config.txt And remove the "#" sign infront of the line "#hdmi_drive=2"

reboot, try again. Let me know if that works for you, and I'll try to add it to the raspberry pi setup script

source: https://www.raspberrypi.org/forums/viewtopic.php?t=154981

edit: Sadly this seems to break vlc for non-sudo. You can't have both, but since sudo is required for CLI-only raspbian lite that might not be an issue. But I can't make it a universal change

scottackerson commented 3 years ago

Changing the boot/config/txt didn't seem to work for me, VLC would still default to HDMI using sudo. I did resolve the issue by changing the default audio device in alsa.conf using the information in the last post here: https://raspberrypi.stackexchange.com/questions/39928/unable-to-set-default-input-and-output-audio-device-on-raspberry-jessie.

vicwomg commented 3 years ago

Thanks so much for finding that. I was spinning my wheels on this too long. This is what did it for me:

sudo nano /usr/share/alsa/alsa.conf

defaults.ctl.card 1
defaults.pcm.card 1

I'll probably just add it to the readme. I don't think this is something I can easily automate.