Electron Audio on Ubuntu Core

Hi,

I’m trying to get audio working for my Electron-based application running as a kiosk app on Ubuntu Core.

The Electron Kiosk tutorial includes a pulseaudio plug, but the pulseaudio interface appears to have been deprecated by the audio-playback interface.

I tried adding the audio-playback interface to my snapcraft.yaml and have the pulseaudio snap installed but I’m not getting audio output via HDMI or the headphone socket on the Raspberry Pi 3. The documentation says that the audio-playback interface auto-connects, but the plug of my application doesn’t seem to have connected to anything.

Do I need to use the alsa interface perhaps? Or is there another staging snap or package I need to install?

Thanks

Are you able to play audio using the commands from the pulseaudio snap i.e. pulseaudio.paplay with a sample mp3 file or something ? It could be that the pulseaudio snap is not working

The pulseaudio snap needs to be updated to provide the audio-playback and audio-record slots, it currently only provides pulseaudio so there is nothing for your snap to plugs audio-playback to.

I’m not even sure how I would do that? The /snap/bin/pulseaudio.pactl binary only seems to have limited commands and /snap/bin/pulseaudio.pactl upload-sample foo.mp3 fails to open a file I scp to the device. How can I test it?

Ah OK. I noticed that you replaced the pulseaudio interface with the audio-playback interface in the snapcraft-desktop-helpers examples and said that audio-playback now “only manually connects pulseaudio”. So what do I need to do to get audio output from Electron?

Thanks

For the moment, you need to plugs pulseaudio (feel free to continue to plugs audio-playpack), then when you install, use snap connect <your snap name>:pulseaudio.

But really the snap needs to be updated. Not sure who is owning that these days, @awe, @abeato , @kenvandine or @Wimpress, can you comment?

Thank you for the suggestion, but I already tried this. With the pulseaudio plug defined in snapcraft.yaml and pulseaudio installed, my application auto-connects the :pulseaudio plug as follows:

$ snap connections | grep krellian-kiosk:pulseaudio
pulseaudio             krellian-kiosk:pulseaudio              pulseaudio:service       -

Unfortunately I still don’t get any audio output from web content in Electron, via either the HDMI or headphone output.

Is this a bug, or is there something else I need to install/configure?

Is your application starting as a daemon? I suspect you’ll get output if it is, as the daemon and pulseaudio snaps will both be running as (confined) root, rather than as your user.

Hi @popey, yes the application is running as a daemon.

I spotted these errors in the snap’s logs, which suggest Electron is trying to access raw ALSA playback:

Jul 13 11:17:17 Unknown-b8-27-eb-f2-7b-0b-3 krellian-kiosk.krellian-kiosk[4492]: ALSA lib conf.c:3916:(snd_config_update_r) Cannot access file /usr/share/alsa/alsa.conf
Jul 13 11:17:17 Unknown-b8-27-eb-f2-7b-0b-3 krellian-kiosk.krellian-kiosk[4492]: ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM default
Jul 13 11:17:17 Unknown-b8-27-eb-f2-7b-0b-3 krellian-kiosk.krellian-kiosk[4492]: ALSA lib conf.c:3916:(snd_config_update_r) Cannot access file /usr/share/alsa/alsa.conf
Jul 13 11:17:17 Unknown-b8-27-eb-f2-7b-0b-3 krellian-kiosk.krellian-kiosk[4492]: ALSA lib pcm.c:2495:(snd_pcm_open_noupdate) Unknown PCM plug:default
^C

I replaced the audio-playback plug with an alsa plug and manually connected it with:

$ snap connect krellian-kiosk:alsa :alsa

Unfortunately I still get the same errors.

Edit: I tried installing the alsa-utils snap and running the speaker test (with sudo) and I do get audio output from that. So the problem does seem to be with whatever Electron is trying to do.

The MAINTAINERS file lists @morphis, but there have been no changes since November 2017. I don’t think anyone is actively maintaining the snap at this point.

if you use the pulse interface you usually need to include libpulse in your snap as a stage package …

since libpulse lives in a subdir in /usr/lib you need to extend your LD_LIBRARY_PATH …

if you use one of the desktop helpers the library path mangling is usually happening automatically though …

1 Like

This worked for me with ffplay only using audio-playback plug. Same Cannot access file /usr/share/alsa/alsa.conf error.

...
layout:
  /usr/share/alsa:
    bind: $SNAP/usr/share/alsa
...
1 Like

Hi @ogra,

Thanks for the tips.

I don’t currently have that included in my snapcraft.yaml as the Electron Kiosk tutorial I followed didn’t include it.

How do I do that?

I do have a desktop-gtk3 part which is adapter from snapcraft-desktop-helpers as per the tutorial. Would you have expected that to do fix the library path?

yep, i think it does …

but it does not automatically include libpulse0 (and probably also libpulse-mainloop-glib0)

Thanks for this suggestion, this got past the alsa.conf error, but then I just had a bunch more errors.

Bingo! Once I added libpulse0 to stage-packages audio output started working.

I have now removed the alsa plug and added both the audio-playback and pulseaudio plugs back and it seems to work. It also seems to autoconnect the pulseaudio plug which is not what the documentation suggests.

Here is the working snapcraft.yaml for reference.

1 Like

This is because that page is talking about the implicit classic slot that you see on classic distro (not Ubuntu Core devices where the interface does not exist unless a snap provides it). The pulseaudio snap is providing the pulseaudio slot, and this snap allows auto-connection of the pulseaudio interface. It doesn’t provide the audio-playback and audio-record interfaces, so its pulseaudio slot was not deprecated.

Thanks very much for explaining, @jdstrand

I realise it’s tricky to document these interfaces when there are differences between implementations, but I’ve added comments on the Supported Interfaces and pulseaudio pages to suggest making this more clear in the documentation.

It also wasn’t obvious to me that I needed to install the pulseaudio snap (and stage the libpulse0 package) for this interface to work on Ubuntu Core.

(I would edit the documentation myself, but I’m not sure what the policy is on documenting differences between implementations as I guess the documentation is supposed to apply to all distros, not just Ubuntu)

Thanks

this is not core specific, you need to do this for all installations when wanting to talk to pulse … if you use somehing like the gnome-3-xx extensions (like many desktop apps do) it comes for free with the extension though …