Closed Bug 1688841 Opened 5 years ago Closed 5 years ago

Media keys working even in the background

Categories

(Core :: Audio/Video: Playback, defect)

Firefox 84
defect

Tracking

()

RESOLVED WONTFIX

People

(Reporter: yogurt4dev, Unassigned)

Details

User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:84.0) Gecko/20100101 Firefox/84.0

Steps to reproduce:

I press media keys on my keyboard, like Play, or Pause.

As the input fields don't have these options, some additional info:
Firefox 84.0.2 x64, Windows, on Windows 10 Professional 20H2 (19042.746) with Windows Feature Experience Pack 120.2212.551.0

Actual results:

Firefox starts to play a video on a non-top tab, even when the entire Firefox is in the background (e.g., minimised).

Expected results:

If Firefox is not the top-level app thus it doesn't have the keyboard focus, it should not capture media keys as it does not capture other key presses or keyboard shortcuts. It's even more true for tabs in the background. A non-visible tab must not receive (or capture...) any input.

(As a side note, background tabs should not start/play anything at all, unless requested by the site [like a push notification]. I would even swap these tab pages to disk instead of using CPU and memory.)

If multiple video tabs (like YouTube) are open, the video only on the last-opened one is started. It doesn't have to be the last tab or the latest tab though.

Bugbug thinks this bug should belong to this component, but please revert this change in case of error.

Component: Untriaged → Audio/Video: Playback
Product: Firefox → Core

I believe this is the intended behavior based on https://support.mozilla.org/en-US/kb/control-audio-or-video-playback-your-keyboard, but I Alastor should know for certain.

Flags: needinfo?(alwu)

(In reply to Jon Bauman [:jbauman:] from comment #3)

If a background application's non-visible tab captures keyboard events intentionally then it's a bad intention, IMO.

The last sentence of the linked support page is just plain garbage. "If this happens, try to close any other apps that are trying to control your media control keys." Cannot use a music player if Firefox is running? Seriously? Or should I close VLC and not watch a movie just because Firefox is way too aggressive?

This is intended behavior and all other browsers have same behavior as well. When enabling media control, we treat Firefox as a media player, which should own the ability to control any playing media even if it's on background. In addition, it's very common for a background tab to listen to media keys, eg. using Spotify web player, users won't always put it on foreground, they would switch to other tabs and simply control the music by pressing media keys.

(In reply to Yogurt4 from comment #4)

The last sentence of the linked support page is just plain garbage. "If this happens, try to close any other apps that are trying to control your media control keys." Cannot use a music player if Firefox is running? Seriously? Or should I close VLC and not watch a movie just because Firefox is way too aggressive?

You can definitely use those applications along with the Firefox, you just need to know how does the audio focus management happen on the desktop. On desktop, the media key events would be delivered to the lastest application that require the media key focus. So if you want to control other applications, you just need to simply start playing from their interface, which should make them start requesting media focus again if they implement this part well.

However, when doing this on desktop, another issue happens, which is two applications would play at the same time. (if you don't pause Firefox before starting another application) That is because desktop OS (Windows/MacOS/Linux) don't have a good centralized audio focus management control, which would automatically pause previous playing application first, before starting another new playing application. Therefore, the solution for that is user have to aware of this OS rule. That HAPPENS on all media player-ish application on desktop. For mobile OS, they usually have a good mechanism for that, which is OS-level audio focus management would handle that and won't let multiple application playing at the same time (if the application implements the audio focus correctly)

My personal workaround for this issue is that, because desktop OS won't handle audio competition, I use Firefox as a platform to manage that for me. I enable the pref media.audioFocus.management, which would help to handle the audio competition automatically inside Firefox. (pause previous playing tab when another new playing tab starts). That works well for me, my use case is that, instead of using Spotify desktop application, I use Spotify web player, so that Firefox can handle all audio competition for me.

Making Firefox being able to receive media keys when it's in background and for no matter foreground or background tabs is necessary, and all other browsers are doing thing like that.

(In reply to Yogurt4 from comment #1)

If multiple video tabs (like YouTube) are open, the video only on the last-opened one is started. It doesn't have to be the last tab or the latest tab though.

If tabs are unvisted, then we would postpone to autoplay them until they first time enters to foreground. (if you don't block autoplay) For media keys, if you don't enable audio focus management on Firefox, media key would control the latest playing tab. If you enable that, so that there would only one tab is allowed to play at the same time, which would be controlled by media keys.

Status: UNCONFIRMED → RESOLVED
Closed: 5 years ago
Flags: needinfo?(alwu)
Resolution: --- → WONTFIX

I'm on desktop, you see, and I don't give the smallest flick about behaviour on mobile phones without mouse, keyboard and with a (basically) single and definite top app. So please don't use those devices as an argument.
And YOUR use case is quite different from mine. YOU don't like to use a music player desktop app but I do. I play my local music files with a desktop app.

What is even more annoying is when while one plays music (by a desktop app), opens a new tab in Firefox that has an embedded video - like an interview or commentary. Now if you press the Play/Pause key on the keyboard, the music player pauses but Firefox starts the video. When you press the key again, Firefox pauses and the music player starts. So there's no way to get silenced using the keyboard. It's very nice when a phone call arrives.

For further reference, one can disable Media Keys in Firefox (that was introduced in FF81).
Under about:config, set media.hardwaremediakeys.enabled to false.

(In reply to Yogurt4 from comment #6)

I'm on desktop, you see, and I don't give the smallest flick about behaviour on mobile phones without mouse, keyboard and with a (basically) single and definite top app. So please don't use those devices as an argument.
And YOUR use case is quite different from mine. YOU don't like to use a music player desktop app but I do. I play my local music files with a desktop app.

What is even more annoying is when while one plays music (by a desktop app), opens a new tab in Firefox that has an embedded video - like an interview or commentary. Now if you press the Play/Pause key on the keyboard, the music player pauses but Firefox starts the video. When you press the key again, Firefox pauses and the music player starts. So there's no way to get silenced using the keyboard. It's very nice when a phone call arrives.

Sorry about that, I know this feature isn't suite for everyone, because like your said, if you don't treat Firefox as a media player, then it would simply intefere other players which users are using.

You can disable this feature in about:preferences->Control media via keyboard, headset, or virtual interface, or by changing the pref.

You need to log in before you can comment on or make changes to this bug.