Flatpak no audio output | [ALSOFT] (EE) Failed to set real-time priority for thread: Operation not permitted (1)

My app is using gstreamer to play audio & its MPRIS compatible. Locally, it runs fine as long as gstreamer, gst-plugins-base & gst-plugins-good are installed. But in flatpak sandbox there’s no audio output although the track in the app is progressing & is seekable

When run it & play a audio track from the app following errors occur

❯ env -i DISPLAY=:0 flatpak run com.github.KRTirtho.Spotube                           

(spotube:2): dbind-WARNING **: 08:31:27.958: Couldn't connect to accessibility bus: Failed to connect to socket /run/user/1000/at-spi/bus: No such file or directory
Gtk-Message: 08:31:28.080: Failed to load module "canberra-gtk-module"
Gtk-Message: 08:31:28.101: Failed to load module "canberra-gtk-module"
[ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: SocketException: Connection failed (OS Error: No such file or directory, errno = 2), address = /run/user/1000/bus, port = 0
#0      _NativeSocket.startConnect (dart:io-patch/socket_patch.dart:682)
#1      _NativeSocket.connect (dart:io-patch/socket_patch.dart:948)
#2      _RawSocket.connect (dart:io-patch/socket_patch.dart:1805)
#3      RawSocket.connect (dart:io-patch/socket_patch.dart:21)
#4      DBusClient._openSocket (package:dbus/src/dbus_client.dart:768)
#5      DBusClient._connect (package:dbus/src/dbus_client.dart:788)
#6      DBusClient.registerObject (package:dbus/src/dbus_client.dart:674)
#7      new _MprisMediaPlayer2 (package:spotube/services/LinuxAudioService.dart:14)
#8      new LinuxAudioService (package:spotube/services/LinuxAudioService.dart:690)
#9      new Playback (package:spotube/provider/Playback.dart:77)
#10     main.<anonymous closure> (package:spotube/main.dart:45)
#11     _NotifierProvider.create (package:flutter_riverpod/src/change_notifier_provider/base.dart:107)
#12     ProviderElementBase._buildState (package:riverpod/src/framework/provider_base.dart:481)
#13     ProviderElementBase.mount (package:riverpod/src/framework/provider_base.dart:382)
#14     _StateReader._create (package:riverpod/src/framework/container.dart:104)
#15     _StateReader.getElement (package:riverpod/src/framework/container.dart:92)
#16     ProviderContainer.readProviderElement (package:riverpod/src/framework/container.dart:506)
#17     ProviderElementBase.watch (package:riverpod/src/framework/provider_base.dart:732)
#18     ChangeNotifierProvider.create (package:flutter_riverpod/src/change_notifier_provider/base.dart:71)
#19     ProviderElementBase._buildState (package:riverpod/src/framework/provider_base.dart:481)
#20     ProviderElementBase.mount (package:riverpod/src/framework/provider_base.dart:382)
#21     _StateReader._create (package:riverpod/src/framework/container.dart:104)
#22     _StateReader.getElement (package:riverpod/src/framework/container.dart:92)
#23     ProviderContainer.readProviderElement (package:riverpod/src/framework/container.dart:506)
#24     ProviderContainer.listen (package:riverpod/src/framework/container.dart:327)
// ..... (unneeded probably) //
#858    Timer._createTimer.<anonymous closure> (dart:async-patch/timer_patch.dart:18)
#859    _Timer._runTimers (dart:isolate-patch/timer_impl.dart:398)
#860    _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:429)
#861    _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:192)

AudioPlayers: Could not query current position.
AudioPlayers: Could not query current position.
AudioPlayers: Could not query current duration.
AudioPlayers: Could not query current position.
AudioPlayers: Could not query current duration.
[ALSOFT] (EE) Failed to set real-time priority for thread: Operation not permitted (1)

Here’s the latest manifest if anyone needs it

# yaml-language-server: $schema=https://raw.githubusercontent.com/flatpak/flatpak-builder/main/data/flatpak-manifest.schema.json

app-id: com.github.KRTirtho.Spotube
runtime: org.gnome.Platform
runtime-version: "42"
sdk: org.gnome.Sdk
command: spotube
finish-args:
  - --socket=fallback-x11
  - --socket=wayland
  - --socket=pulseaudio
  - --share=network
  - --share=ipc
  - --device=dri
  - --filesystem=xdg-download
  - --filesystem=xdg-documents
  - --talk-name=org.freedesktop.Notifications

modules:
  - name: spotube
    buildsystem: simple
    build-commands:
      - install -Dm644 spotube/com.github.KRTirtho.Spotube.appdata.xml /app/share/appdata/com.github.KRTirtho.Spotube.appdata.xml
      - desktop-file-edit spotube/spotube.desktop --set-key=Exec --set-value="spotube
        %u" --set-icon=com.github.KRTirtho.Spotube
      - install -Dm644 spotube/spotube-logo.png /app/share/icons/hicolor/128x128/apps/com.github.KRTirtho.Spotube.png
      - install -Dm644 spotube/spotube.desktop /app/share/applications/com.github.KRTirtho.Spotube.desktop
      - install -dm755 /app/bin /app/spotube
      - cp -R spotube/ /app
      - ln -s /app/spotube/spotube /app/bin/spotube
    sources:
      - type: archive
        path: Spotube-linux-x86_64.tar.xz
        dest: spotube
        sha256: <needs fill up>

Download the archive from here and extract it & move Spotube-linux-x86_64.tar.xz in the same directory as the manifest & get a sha256sum of the Spotube-linux-x86_64.tar.xz & past the sha256 hash in the manifest

Please help

Well, after trying different solutions for 13 hours finally I’ve managed to get the App Work again perfectly just like it should

Turns out as my application is using Gstreamer which uses Gnome’s GVFS which an virtual filesystem by Gnome which is designed to work with the I/O abstraction of GIO, it needs access to that. Since gvfs is a virtual filesystem I need permissions to access it from my application

This stupid line has cost me 13 hours🤦

  - --filesystem=xdg-run/gvfs

Summary, your app needs permissions to play Audio from Gstreamer when being used inside Flatpak. Just append --filesystem=xdg-run/gvfs to finish-args of your manifest

BTW, if your app uses Dbus MPRIS than you’ve to also use --own-name=org.mpris.MediaPlayer2.<you-app-name> in the finish-args

GVFS access permission are documented here:

https://docs.flatpak.org/en/latest/sandbox-permissions.html#gvfs-access

1 Like