Skip to content

Get audio sessions and control them #96

Description

@lil-aleks

Summary

Add AudioSession with functions like get_vol() and set_vol(vol: u8) to set the volume of an application or other running audio sessions.

Target crate(s)

volumecontrol-core, volumecontrol (wrapper), volumecontrol-linux, volumecontrol-windows, volumecontrol-macos

Platform scope

All platforms

Motivation & use case

It is very usefull to not only change the output volume of the devices but to change the output volume of each audio session.

Proposed API or behavior

There should be a AudioSession trait similar to AudioDevice with which a user can control the current audio sessions.

How it could look like:

Change volume of every current session to 50%:

use volumecontrol::{AudioSession, SessionInfo, AudioError};

let session_infos: Result<Vec<SessionInfo>, AudioError> = AudioSession::list();

for session_info in sessions.unwrap().into_inter() {
    let session: AudioSession = AudioSession::from_id(&session_info.id).unwrap();
    session.set_vol(50).unwrap();

    println!("Volume of '{}' is now set to {}%.", session.name(), session.get_vol().unwrap());
}

Example output:

Volume of 'Discord.exe' is now set to 50%.
Volume of 'chrome.exe' is now set to 50%.
Volume of 'Spotify.exe' is now set to 50%.

On linux the session name could look different (without .exe at the end).

Acceptance criteria

  • New struct SessionInfo added.
  • New trait AudioSession with all required methods added.
  • Implemented for Windows (WASAPI) backend
  • Implemented for Linux (PulseAudio) bachend
  • Implemented for macOS (CoreAudio) backend
  • Unit tests added for each platform
  • Every new trait, struct and method is documented + usage examples.

Implementation hints

These is everything I could find to this topic:

  • WASAPI: IAudioSessionManager2, IAudioSessionEnumerator and IAudioSessionControl2 interfaces.
  • PulseAudio: Sink Input 's are App Audio Streams (the audio sessions). pa_context_get_sink_input_info_list, pa_context_get_sink_input_info, pa_context_set_sink_input_volume, pa_context_set_sink_input_mute and (PA_SUBSCRIPTION_MASK_SINK_INPUT) could be needed functions

Breaking change?

Yes — new trait method (requires major version bump)

Alternatives considered

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions