digimezzo / dopamine

The audio player that keeps it simple
https://digimezzo.github.io/site/
GNU General Public License v3.0
1.55k stars 111 forks source link

[BUG] MacOS Focus Lost After Manually Skipping Songs in Gapless Playback #715

Open fr-eed opened 3 weeks ago

fr-eed commented 3 weeks ago

When the "Gapless playback" feature is enabled, Dopamine loses media focus after manually skipping a few songs using the "Now Playing" feature in macOS Control Center or multimedia keys. Once Dopamine loses focus, pressing the multimedia keys (play/pause, next/previous) defaults to controlling Apple Music instead of Dopamine.

Steps to Reproduce:

Enable "Gapless playback" in Dopamine.
Restart the app.
Play any song.
Skip a song using multimedia keys or via the macOS Control Center.
Unfocus or close the Dopamine main window.
Skip a song again using multimedia keys or Control Center.
Observe that media focus is lost, and multimedia keys no longer control Dopamine.
Press multimedia keys again, and Apple Music takes over media control.

MacOS version: macOS 15.0.1 Dopamine: 3.0.0-preview.36

digimezzo commented 3 weeks ago

@fr-eed Thank you for the bug report. I'll investigate this.

fr-eed commented 3 weeks ago

Also to note. Currently Dopamine works weirdly with the Control Center Now Playing widget, after switching a song it disappears for a moment and then appears

digimezzo commented 3 weeks ago

@fr-eed Does this also happen when gapless playback is disabled?

fr-eed commented 3 weeks ago

@fr-eed Does this also happen when gapless playback is disabled?

Yes

https://github.com/user-attachments/assets/2541e789-8e7b-4b08-861e-0048bbde4fdb

digimezzo commented 3 weeks ago

@fr-eed Keep an eye in this build: https://github.com/digimezzo/dopamine/actions/runs/11468241556

It's currently building. As soon as it has artifacts, could you try it out? I tried to fix the problem in it. Thanks!

fr-eed commented 3 weeks ago

@fr-eed Keep an eye in this build: https://github.com/digimezzo/dopamine/actions/runs/11468241556

It's currently building. As soon as it has artifacts, could you try it out? I tried to fix the problem in it. Thanks!

So, gapless playback doesn't cause initial bug but now:

Behavior shown in my video still persists

Maybe MacOS doesn't need the gapless feature at all?

digimezzo commented 2 weeks ago

@fr-eed Thanks for the info. This seems more complicated than I thought. I'll test it out here on a macOS Virtual Machine.

fr-eed commented 2 weeks ago

@digimezzo Expected behavior for reference

https://github.com/user-attachments/assets/ac123faa-23a9-46bd-9980-6cbc7e5632a4

digimezzo commented 2 weeks ago

@fr-eed Could you try out this build? https://github.com/digimezzo/dopamine/actions/runs/11548036703 Thank you.

fr-eed commented 2 weeks ago

@fr-eed Could you try out this build? https://github.com/digimezzo/dopamine/actions/runs/11548036703 Thank you.

Works good without gapless playback. Now Playing widget integration works as intended but sometimes author gets updated slower than the music title

With gapless playback original bug still exists but not as consistent. I need to use app for some time for it to appear. It's easier to trigger if you have second player running in the background

Also that still exists with gapless playback on:

After selecting any song/skipping, it starts playing for 200 ms and then restarts from the beginning causing it to repeat a sequence.

digimezzo commented 2 weeks ago

@fr-eed Thanks for testing out. Is it possible to make a video of the 200ms problem? I'm not sure how I should reproduce that. Thanks

fr-eed commented 2 weeks ago

@fr-eed Thanks for testing out. Is it possible to make a video of the 200ms problem? I'm not sure how I should reproduce that. Thanks

It's an audio issue. I can share a recording later.

After some more testing I've found out that this bug occurs only with wireless headphones. Most likely system wants to sync it with wireless delay and your app overrides it

fr-eed commented 1 day ago

https://github.com/user-attachments/assets/a606ab76-4894-436c-8331-b7313a239f48

It sounds like this with gapeless playback on with bluetooth headphones connected as main audio output.

Tested on this build: https://github.com/digimezzo/dopamine/actions/runs/11619031390