Prevent the audio of an application to be turned off by other applications

Hi.
Whenever I play music in the Media app and another application emits some audio/sound, it stops the music playback in the Media app (it happens with other music players too).
Is there any way to prevent this?
E.g. I would like the 2 apps to play audio at the same time and not stop each other.
Thanks.

1 Like

Hi, looks to my earlier bug report Playing audio file with QMediaPlayer pause Media player - #5 by karry . This behaviour is intentional as it expect that all applications are media players by default. But it is not true in many cases. You may override application “audio resource class” by setup NEMO_RESOURCE_CLASS_OVERRIDE environment variable. I believe that for your usecase, when you want to play sound from two applications simultaneously, you should setup this variable to “game” for one of these applications.

Take a look to my findings here: osmscout-sailfish/OSMScout.cpp at master · Karry/osmscout-sailfish · GitHub

    // pre-defined classes: navigator, call, camera, game, player, event ( https://github.com/qt/qtmultimedia/commit/1c5ea95 )
    // pulseaudio behaviour is configured in /etc/pulse/xpolicy.conf
    // best class should be *navigator*, but this class is routed to device speaker even when bluetooth headset is connected
    // *player* class is routed (pulse route_audio flag), but system player is paused and not resumed after voice message
    // *game* class seems to be best for car navigation
2 Likes

Thanks, that seems to work with normal apps, but I want to use this with an Android app.

I tried the following, but it doesn’t seem to change the behavior:

NEMO_RESOURCE_CLASS_OVERRIDE=navigator apkd-launcher …

Is this the correct way to set environment variables for android apps?
Thanks.

I still haven’t found a way to set the environment variable for the Android app, but I realized that setting NEMO_RESOURCE_CLASS_OVERRIDE=event on jolla-mediaplayer does the job.

However, I don’t know how to set the environment variable in the .desktop file. I tried the following, but it doesn’t work:

Exec=/usr/bin/sailjail -p jolla-mediaplayer.desktop /bin/env NEMO_RESOURCE_CLASS_OVERRIDE=event /usr/bin/jolla-mediaplayer

Any idea how I can set the environment variable in this file? Thanks.

Edit: Weirdly enough, running the following command:

env NEMO_RESOURCE_CLASS_OVERRIDE=event /usr/bin/sailjail -p jolla-mediaplayer.desktop /usr/bin/jolla-mediaplayer

from the cli works, but when I put the same line in the Exec key of the .desktop file, it doesn’t work.
What am I missing?

I’ve been able to set the environment variable (see here), but I realized that setting NEMO_RESOURCE_CLASS_OVERRIDE=event has an unintended side-effect: after the audio starts playing, the audio output will change to speaker+wired headphone.

Any idea how to avoid this behavior?

Hi. This behaviour is controled by group’s flags in /etc/pulse/xpolicy.conf file. But not sure what flag exactly control this one.

2 Likes

Ok, I’m not sure where’s the doc for this file, but I changed the following lines:

ports = droid.output.primary@equals:"true"->output-speaker+wired_headphone

to:

ports = droid.output.primary@equals:"true"->wired_headphone

and it seems to have the intended side-effect.

I have another problem, though, but it might be caused by NEMO_RESOURCE_CLASS_OVERRIDE=event instead: when playing music in the jolla media player, if I unplug and replug my headphones, the music will continue playing on the speaker. The reason I believe it might be caused by this environment variable is because that doesn’t seem to happen in other media players.

Do you know if that’s the intended behavior? Is that still something that can be configured in the xpolicy.conf file? Do you know if there’s any documentation for that file?

Thanks a lot for your help!