The audio-playback interface

The audio-playback interface allows a snap to play sounds and music, via the supporting audio service running on the system, such as PulseAudio. It’s used by many applications and utilities, and as such, is enabled by default.

Audio recording is enabled with the companion audio-record interface, and unlike audio-playback, is not enabled (auto-connected) by default.

Example

The VLC snap is a good example of an application using the audio-playback interface:

$ snap connections vlc
Interface               Plug                        Slot                     Notes
audio-playback          vlc:audio-playback          :audio-playback          -
audio-record            vlc:audio-record            -                        -

If for some reason you want to disable audio playback for a snap, use the disconnect command:

snap disconnect vlc:audio-playback

The connect command can be used to re-enable audio playback:

snap connect vlc:audio-playback
Interface documentation:

See Interface management and Supported interfaces for further details on how interfaces are used.


Developer details

Auto-connect: yes

Code examples

The snapcraft.yaml for VLC includes audio-playback configuration: https://github.com/videolan/vlc/blob/master/extras/package/snap/snapcraft.yaml

The source code for this interface is in the snapd repository: https://github.com/snapcore/snapd/blob/master/interfaces/builtin/audio_playback.go

1 Like

There’s a mismatch between https://snapcraft.io/docs/t/the-audio-playback-interface/13089 and https://snapcraft.io/docs/supported-interfaces WRT to ‘Auto-Connect’. I am unsure if it’s yes or no :slight_smile:

@cjp256 the other page is wrong, audio-playback should be auto-connected

1 Like

Yes, both were wrong, so I fixed the forum. I think this will be corrected automatically in snapcraft.io/docs given some time (@degville can confirm).

Thanks for making the fixes - and yes, snapcraft.io/docs is updated automatically.

In order for a snap to successfully connect to PulseAudio, the following needs to be done:

  1. request and connect one of pulseaudio or audio-playback (mentioned for completeness)
  2. add ${SNAP}/usr/lib/$SNAPCRAFT_ARCH_TRIPLET/pulseaudio to LD_LIBRARY_PATH
  3. point libpulse at the pulseaudio socket, e.g., in a wrapper:
    papath="$XDG_RUNTIME_DIR/../pulse/native"
    if [ ! -e "$papath" ]; then
        echo "Cannot not find '$papath'"
        exit 1
    fi
    export PULSE_SERVER="unix:$papath"

(I got this from tests/lib/snaps/test-snapd-pulseaudio/files/bin/pawrap in the snapd source, which seems to imply this is how it’s designed to work.)

1 Like

I am confused about whom is the actual provider of audio-playback interface. Snapd or PulseAudio?