I developed a Firefox addon to increase the output of the speaker. I used AudioContext for this.
On YouTube videos it is working fine but on other websites it is not working. So I figured out that this was because of DOM is not loaded. So I now if I am waiting for DOM to load completely, there is no sound coming out of the speakers even for YouTube which was working previously.
Here is the code, I tried putting it inside DOMReady and other methods that waits for DOM to load but Audio stops working after this.
let mVideoElement = document.querySelector('video');
let audioCtx = new AudioContext();
let source = audioCtx.createMediaElementSource(mVideoElement);
let gainNode = audioCtx.createGain();
browser.storage.onChanged.addListener((changes, area) => {
if (area === 'local' && 'value' in changes) {
increaseVolume(changes.value.newValue);
}
if (area === 'local' && 'status' in changes) {
speakerBoosterStatus(changes.status.newValue);
}
});
function increaseVolume(value) {
if (value === undefined) {
gainNode.gain.value = 1;
} else {
gainNode.gain.value = value;
}
source.connect(gainNode);
gainNode.connect(audioCtx.destination);
}
function speakerBoosterStatus(status) {
if (status === false) {
gainNode.gain.value = 1;
source.connect(gainNode);
gainNode.connect(audioCtx.destination);
window.location.reload();
} else {
browser.storage.local.get('value').then(result => increaseVolume(result.value));
}
}
browser.storage.local.get('value').then(result => increaseVolume(result.value));
browser.storage.local.get('status').then(result => speakerBoosterStatus(result.value));
Here is the Source Code for better testing.
PR are welcome. Thank you :)