fix(audio-compressor): real-time behavior and duplicated audio bug #3786
No reviewers
Labels
No labels
awaiting-reply
breaking changes
bug
cannot-reproduce
dependencies
documentation
duplicate
electron-issue
enhancement
fix-available
good first issue
help wanted
invalid
javascript
need more information
need rebase
official-youtube-music-issue
plugin request
question
release
security
stale
Status: blocked
typo
wontfix
ytmd-issue
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: YTMD/youtube-music#3786
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "compressor-fix"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
I noticed the compressor doesn't activate in real-time, but until the next song starts or when restarting the whole app.
The easy fix would be to add
restartNeeded: true,
But I challenged myself to make it enable and disable in real-time.
My approximation was to make the
ensureAudioContextLoad
function because the 'ytmd:audio-can-play' event is only sent when loading a video. So it was impossible to know what song was playing at the moment the plugin was enabled.By the way, it would have been easier if the audioSource and audioContext were sent when enabling a plugin, or the 'ytmd:audio-can-play' was sent again to plugins when enabled. Nevertheless, my pull request tries to modify only the plugin code and nothing from the source code.
I hope you like it.
Edit: TL;DR
Just realized this text is huge for no reason. In summary, my pull request offers:
ADDED
FIXED
Oh, I totally forgot it. I made the fix at first because the compressor was duplicating the signal (the audioSource was still connected to the audioContext.destination). So yeah, I fixed that too.

renderer.ts
audio-compressor.ts

Edit: that was the main bug and, in fact, the original reason for the Pull Request. Everything else came later.
@ -1,26 +1,133 @@
import { createPlugin } from '@/utils';
Use camelCase instead of snake_case
Pull Request Overview
This PR fixes real-time behavior and audio duplication issues in the audio compressor plugin. Previously, the compressor would only activate when a new song started or the app restarted, requiring users to manually trigger audio events to enable compression.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
@ -1,26 +1,133 @@
import { createPlugin } from '@/utils';
The event listener is added with
once: true
, which means it will only trigger once and then be automatically removed. This conflicts with the manual removal in thestop()
method at line 130, and will prevent the compressor from working on subsequent songs.@ -3,0 +103,4 @@
playerApi.getCurrentTime(),
playerApi.getUserPlaybackQualityPreference(),
);
};
The magic number
1
should be replaced with a named constant. This appears to represent a specific player state but lacks clarity for future maintainers.