Posts: 1
Joined: Sun Jan 19, 2020 9:30 am

PHP script pulseaudio playback to bluetooth speaker not working

Sun Jan 19, 2020 9:50 am

hi, i am developing my home automation system and need to control mp3 playback throught php

system description:

1) rasbian buster (2019-09-26-raspbian-buster-lite.img)
2) Raspberry PI connected to TV (hdmi)
3) pulseaudio running under user "pi"
4) apache webserver running under user "pi" (when i try command "whoami" in php script i get "pi")
5) connected bluetooth speaker

when i try as user "pi" in commad line this:

Code: Select all

paplay -d bluez_sink.XY_XY_XY_XY_XY_XY.a2dp_sink /usr/share/sounds/alsa/Front_Center.wav
audio is playing in bluetooth speaker

but, when i try same command in PHP script, i get error
ERROR: Connection failure: Connection refused pa_context_connect() failed: Connection refused
this, error, as i know, indicate problem with permission to access pulseaudio, but why? when in php i am user "pi"

and next thing: when i try in PHP play mp3 with this command:

Code: Select all

mpg123 file.mp3
playback starts on connected TV, even default pulseaudio sink is "bluez_sink.XY_XY_XY_XY_XY_XY.a2dp_sink" (on command line is file played in bluetooh speaker)

thank for help

Return to “Troubleshooting”