-
Notifications
You must be signed in to change notification settings - Fork 568
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
Audio compressor plugin #288
Conversation
It looks like you are watching any changes in the video element, including volume change / pause etc or can this be applied only once on load? if that doesn't work then maybe only when each song load? const applyCompressor = (videoElement) => {
...
const source = audioContext.createMediaElementSource(this)
...
}
document.querySelector('video').addEventListener("canplay", applyCompressor); or maybe im completely wrong 🙃
|
You're right - DOMContentLoaded isn't very reliable in our case a possible solution is having a timeout to check if video is loaded (even with load event it takes a few more milliseconds) checkVideoLoaded()
// or if it gets reset on page reload (unlikely from what i've observed)
window.addEventListener('load', checkVideoLoaded)
function checkVideoLoaded() {
const video = document.querySelector("video");
if (video) {
applyCompressor(video); // or video.addEventListener("canplay", applyCompressor) if it doesn't persist
} else {
setTimeout(checkVideoLoaded, 500);
}
}
this is pretty much exactly what happens in precise-volume plugin, which also modify the video element youtube-music/plugins/precise-volume/front.js Lines 94 to 107 in 177ad2c
from #275 |
or the even shorter version that im using in the new Chromecast plugin: module.exports = function checkVideoLoaded() {
const video = document.querySelector("video");
video ? setup(video) : setTimeout(checkVideoLoaded, 500);
} |
I personally don't like using |
And I dont like watching a whole dom element when you don't care about any of the changes 😝 Speaking of, I think there is a memory leak in youtube-music/plugins/playback-speed/front.js Lines 43 to 80 in 61e7124
First dom watcher is just unnecessary, I hope i'm reading it wrong somehow..
@th-ch Am I wrong or should this be fixed? |
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.
Looks good, thanks for the contribution!
Am I wrong or should this be fixed?
Nice catch, it looks like it's the case indeed, and observing/watching the menu should only be needed when the page/music changes so there is probably room for improvement indeed for the playback speed plugin!
This plugin adds DynamicsCompressorNode onto the audio that is being played which should help with the case where there are two videos with different volume in the video's audio itself.
Example:
vid1 (which is loud) compared to
vid2
without the plugin:
with the plugin: