Snap example with audio-playback and play (sox) command

I am trying to enable audio playback to my snap and so far without success. My application is just executing available command line play command to play mp3 files. I know that I should use audio-playback interface instead of deprecated pulseaudio interface and that audio-playback enables only pulseaudio and not ALSA. For ALSA support there are additional more complex steps. As my application is not using ALSA interface directly and it executes only play command then it would be sufficient to do any play command which can play directly through pulseaudio. Originally I used ‘play’ command which is in fact SoX player. It supports multiple sound backends as well as pulseaudio. For that I added additional packages:
- sox
- libsox-fmt-mp3
- libsox-fmt-pulse
- libpulse0
See for full snap configuration.
When play command is executed then it reports “/snap/c-evo/3/usr/bin/play FAIL sox: Sorry, there is no default audio device configured”.
So I guess I am still missing some pulseaudio configuration in my snap so SoX can’t connect to pulseaudio.

Basically I need simple way to play mp3 files inside snap. Another requirement would be to not make snap much bigger so some low space demanding solution would be nice. There are other players which could be used. But for example ffplay would probably take too much libraries with itself. Another play tool is mpg123/mpg321.

Are there some example snaps which can play audio files through pulseaudio and don’t take too much space? Thanks to github ability to search in specified files we can see some examples but usually there are too complex and not doing simply what I need.

Do snaps using audio-playback need some explicit configuration so applications supporting pulseaudio work?

I was not able to get it working yet but I have found other useful links:

According this topic Audio-playback interface in snaps running in daemon mode it may be needed to set some env variables like PULSE_SERVER.

I have also find snap which is for older pulseaudio interface but it has also snapcraft.yaml which contains also:
So perhaps snap which uses pulseaudio needs additional env variables. By default libraries are searched for only in $SNAP/usr/lib/$SNAPCRAFT_ARCH_TRIPLET ?
Here somebody is trying to use this snap But it doesn’t play sound for me on Ubuntu 21.04.

This is also useful hint:
Although I see some pid and native files in /run/user/1000/pulse, sox is still not able to connect to pulseaudio.

This looks to be a desktop application or game, so the best way to get everything functional is to use the gnome-3-38 extension (because it’s based on core20 - for core18 you would want either gnome-3-28 or gnome-3-34):

    command: usr/share/c-evo/c-evo
    desktop: usr/share/applications/c-evo.desktop
    extensions: [gnome-3-38]
      - home
      - audio-playback

Thanks for the replay. But how that can help me to resolve sound support? Are there some commands included to play sound files?
My latest finding is that standard sox package from Ubuntu probably won’t work with pulseaudio in snap because needed sox libs are placed in different directory like /usr/lib/sox. But in snap they are located in $SNAP/usr/lib/sox. So sox won’t find them and report missing formats and device drivers. So perhaps sox can be recompiled for snap package but that would be kind of overkill to rebuild another application during snapcraft build just to be able to use play command.

I’ve tried gnome-3-38, gnome-3-34 but I’ve got linking errors from FPC. I don’t know what is exactly problem here but Lazarus/FPC probably expects different version of those libraries. And currently GTK applications need to be built with Gtk2 and not GTK 3 or 4. So perhaps there are some libraries missing in those gnome extension for Gtk2. Or it is just version mismatch.

/snap/gnome-3-34-1804-sdk/current/usr/bin/ld.bfd: warning: link.res contains output sections; did you forget -T?
/snap/gnome-3-34-1804-sdk/current/usr/lib/x86_64-linux-gnu/ undefined reference to pango_font_get_hb_font' /snap/gnome-3-34-1804-sdk/current/usr/lib/x86_64-linux-gnu/ undefined reference to g_utf8_validate_len’
/snap/gnome-3-34-1804-sdk/current/usr/lib/x86_64-linux-gnu/ undefined reference to g_source_set_dispose_function' /snap/gnome-3-34-1804-sdk/current/usr/lib/x86_64-linux-gnu/ undefined reference to pango_coverage_get_type’
/snap/gnome-3-34-1804-sdk/current/usr/lib/x86_64-linux-gnu/ undefined reference to pango_font_description_get_variations' /snap/gnome-3-34-1804-sdk/current/usr/lib/x86_64-linux-gnu/ undefined reference to g_ref_count_init’
/snap/gnome-3-34-1804-sdk/current/usr/lib/x86_64-linux-gnu/ undefined reference to g_ref_count_inc' /snap/gnome-3-34-1804-sdk/current/usr/lib/x86_64-linux-gnu/ undefined reference to pango_font_description_set_variations’
/snap/gnome-3-34-1804-sdk/current/usr/lib/x86_64-linux-gnu/ undefined reference to g_spawn_async_with_fds' /snap/gnome-3-34-1804-sdk/current/usr/lib/x86_64-linux-gnu/ undefined reference to g_ref_count_dec’
/snap/gnome-3-34-1804-sdk/current/usr/lib/x86_64-linux-gnu/ undefined reference to g_unix_get_passwd_entry' /snap/gnome-3-34-1804-sdk/current/usr/lib/x86_64-linux-gnu/ undefined reference to g_canonicalize_filename’
/snap/gnome-3-34-1804-sdk/current/usr/lib/x86_64-linux-gnu/ undefined reference to g_atomic_ref_count_init' /snap/gnome-3-34-1804-sdk/current/usr/lib/x86_64-linux-gnu/ undefined reference to g_atomic_ref_count_dec’
/snap/gnome-3-34-1804-sdk/current/usr/lib/x86_64-linux-gnu/ undefined reference to `g_atomic_ref_count_inc’

I also tried gnome-3-28 and it compiled correctly but during run it reports error so no luch with this as well.

(2048:23724): GLib-GObject-WARNING **: 20:21:38.303: specified class size for type ‘IBusIMContext’ is smaller than the parent type’s ‘GtkIMContext’ class size
malloc(): memory corruption
Neúspěšně ukončen (SIGABRT)

I may be one of first developers which are trying to package Lazarus app with snap. I have create a new wiki tutorial here for this purpose. But so far it was kind of paintful and time consuming experience. There are still so many issues which need to be solved so the snap application can run with same user experience as with native deb package. At least publishing snap package is much easier than dealing with Debian rules for inclusion deb packages in the distribution.