m1dugh / native-sound-mixer

MIT License
25 stars 13 forks source link

Changing volume only works if the audio session is active #6

Closed fennabe closed 3 years ago

fennabe commented 3 years ago

When I try to change the volume for an application (ex. Chrome), the volume in volume mixer only changes if Chrome is actively playing audio. If the audio (in Chrome) is paused or stopped, the slider in volume mixer won't change when I try to adjust volume with this node package.

Is it possible to allow volume changes even if there is no audio playing? (but there previously was, so the session still exists)

hi019 commented 3 years ago

I'm not sure if this is related, but I found that Device.sessions only returns active (those which are currently playing audio) sessions. It's because of the second condition in this statement. Removing it will return the same devices as the volume mixer.

With that change, I'm also able to control the volume of inactive sessions:

const {default: SoundMixer, DeviceType} = require("native-sound-mixer");

function main() {
    const d = SoundMixer.getDefaultDevice(DeviceType.RENDER)    
    const sess = d.sessions.find(d => d.path == APPLICATION_PATH)

    sess.mute = false;
}

main()

@m1dugh what do you think? Should Device.sessions return inactive sessions too? I can make a PR.

m1dugh commented 3 years ago

@hi019 This could be a good change and just takes the removal of a single line of code. However, As the typescript code does not include a state value in AudioSession, we should add it. I'll be working on it.

m1dugh commented 3 years ago

I added all sessions in Device.sessions, you can now change the volumes and mute flags of inactive and expired sessions.

hi019 commented 3 years ago

Cool! I think we can close this now.