-
Notifications
You must be signed in to change notification settings - Fork 189
Implement music attenuation on Linux #1117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
All of this in paper sounds good to me, will just take a while to get to reviewing it and making sure the protocol is implemented properly. Thanks for the PR! |
Re: #820 static std::atomic<bool> g_isPlaying = false;
static void UpdateActiveStatus() {
g_isPlaying = std::ranges::any_of(
g_activePlayers,
[](std::string name) { return g_playerStatus[name] == PlaybackStatus::Playing; }
);
} |
Okay wait, I noticed something about how chrome works. I don't know if it's an implemention detail of this, but even if I have chrome play 2 different media, it has only 1 entry in |
At this point, perhaps it would be. I kind of wanted it to be more consistent to Windows but if clients of this are so misbehaved maybe it's not even worth it. After trying this more it appears maybe the Discord bug shouldn't really be catered for. Not only is using it there not as common, it only seems to happen if you click off a YouTube video while it's still playing. Getting rid of it is as simple as refreshing the page. ...or, your most recent post came through just as I was typing this, because it appears browsers share the same MPRIS2 instance and not just Chrome (as you've just encountered), playing media in another tab resets the state too. |
So playing around with it,
|
I don't think there is anything around this. I think chrome itself just ties a single MPRIS instance to the most recent tab with a playing media. I don't think there is anything that can be done otherwise. Interestingly, firefox works differently.
At least firefox and chrome have seperate insances from eachother (I tested) |
Oh, I see. Thanks for noticing that. Do you have the Discord desktop application? I'd be interested to know if Electron creates an MPRIS instance, and if whatever "start YouTube embed but switching away says still Playing" issue somehow happens there. |
Alright, great! That's quite a lot of weight off our shoulders if Electron doesn't, especially with the whole notification sound thing earlier. I suppose Steam also ought to be checked given it's extensive use of CEF nowadays too. Reading again though:
Assuming by "this implementation" you mean mine, as you have playerctl there's a chance playerctld is running and preferred from the moment it's encountered, which is why you'd be experiencing them to have the same behaviour. Still a bit torn between which method should be employed without playerctld present though. I also don't really want the chance of anybody reporting any "music doesn't play" issues :P |
I Also until testing about an hour ago, I did not have |
I also booted up steam, went to a random game page and played the trailer... nothing. Attenuation did not kick in |
Hmm, running |
That probably explains the calls to I'm mostly new to MPRIS, so does "name ownership" basically mean something similar to what I described as MPRIS "binding" to a tab? |
And to clairify what I mean by "this implementation" I'm mostly talking about how you maintain I'm not talking about how you only check the first element I still thing checking every Take the individual result from the chrome only and firefox only tests, then if either result in the playing status, attenuation turns on, if they are both paused or stopped, then attentuation turns off. |
logging the MPRISPropertiesChanged method, changing tabs only seems to triger a D-Bus is weird :( |
Perhaps. I'm no longer in the position to check the exact bus behaviour at the moment so I can't confirm much. With D-Bus, the name ownership signal is sent and used to detect when something has appeared, disappeared, or changed names on the bus. There is also the concept of a unique name (usually something like
I'm feeling more confident with that now that things have been tested more.
Yeah... it is. Be thankful this is only checking if something's playing or not, and not listening for other changes. Another time I tried to use this to listen to metadata changes to print current song in the chat of something, players had differing behaviours, such as Spotify emitting duplicate signals, and I think players not even emitting PropertiesChanged to indicate that metadata had changed at all. |
I already have a commit ready. I can either make a pull request to your repo. That being said, I would like to have my contribution be seen in the form of a commit, but I won't insist on it. |
I could make a patch to the repo but mention you in it, as you did provide valuable testing. I made a review on your PR a bit ago but annoyingly this repository makes them invisible until approved, here's what it said (under the
(Not mentioned is since every connect would increase the reference count it could potentially overflow at a certain point anyway) The only true fix for that would be to only connect once upon start, but what I do with spawning a new thread is much less intrusive and should remove the performance impact of doing all those blocking calls on the main thread. |
if (!g_activePlayers.empty()) | ||
g_activeStatus = g_playerStatus[g_activePlayers.front()]; | ||
else | ||
g_activeStatus = PlaybackStatus::Stopped; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You'd be making a copy of each string by it not being a reference, no?
At this point the whole queue system could just be removed if we're doing this.
Oh ya, that PR was made BEFORE I even knew about this PR, as well as at the time, only learned about the library like 2 hours beforehand. At the time, it was mostly just a curiosity if it could be done on my part. My commit, is just a minimal change to what you already have, which is significantly better designed as a base. Basically matching the "suggested changes" from the above "review" |
Okay so I made a new commit, I unfortunately can't make a PR to your repo because my branch has all of the updated commits since your main branch last forked :( Compleltely gets rid of the I can still provide a patch |
This is implemented by listening for event changes from MPRIS2 clients over D-Bus. Unfortunately there is no good API for this nor a good way to identify current player as there is on Windows, and as such we have to track and queue them manually just to get a seemingly good enough result. This also gives us the issue of needing to guess and manually prioritise which player to use when we first start, as we cannot determine when something before us started. playerctld is preferred to be read on systems that have it available, however that has the behaviour of setting its status to the most recent change. Those who use this and have media key scripts use it would likely be expecting such behaviour though. (All my editors were eager to fix inconsistent CRLF's in the CMakeLists, sorry)
Right, I'll pull so you can PR and hope it doesn't explode, one moment. Also fell into the damn review thing again, I was meant to reply this to you earlier:
|
PR made |
There we go, thank you! |
This is implemented by listening for event changes from MPRIS2 clients over D-Bus. Unfortunately there is no good API for this nor a good way to identify current player as there is on Windows, and as such we have to track and queue them manually just to get a seemingly good enough result. This also gives us the issue of needing to guess and manually prioritise which player to use when we first start, as we cannot determine when something before us started.
playerctld is preferred to be read on systems that have it available, however that has the behaviour of setting its status to the most recent change. Those who use this and have media key scripts use it would likely be expecting such behaviour though.
GLib's GIO library is used for D-Bus as it is much more sane to parse messages with. This doesn't introduce any new dependencies as nativefiledialog-extended has GTK3 as a dependency, which depends on GLib and GIO.
This should close #820.
(All my editors were eager to fix inconsistent CRLF's in the CMakeLists, sorry)
Edit:
The new commit by @AlexOxorn removes the queue system which originally made it more similar to Windows, after it was deduced that it may not work as well on this platform. Instead, it checks to see if anything is playing before attenuating, instead of what was attempted to be deemed the "active" player.