Is there a way in Java (+ - JNA) to establish a reliable master system level in XP + Vista + Windows 7?

It appears that the java sound API works well for single streams and even for setting microphone input, but not for setting the volume level in Vista / Windows 7.

refs:

Java Sound API for accessing the system / master volume controller in Vista and Win 7

How to adjust speaker volume from a Java program?

Changing the master level  works only on XP for the main volume

Does anyone have something that will work for everyone (without compatibility mode or mouse control to increase the volume level [like a robot]).

0
source share
2 answers

, , , , - jna " ":

https://superuser.com/questions/82229/how-to-control-master-volume-in-windows-7/86227#86227

, dll, , "vista volume aware", , , jna.

ffi/jna/jnr/jacob ( IAudioEndpointVolume ..) . (, jna COM?) ffi .

java COM-, . - bridj jacob

0

JNI , . , , - , , , , JNI . ++, , :

#include <WinSDKVer.h>
#define _WIN32_WINNT _WIN32_WINNT_VISTA
#include <SDKDDKVer.h>

#define WIN32_LEAN_AND_MEAN
// Windows Header Files:
#include <windows.h>
#include <tchar.h>

#include <mmdeviceapi.h>
#include <endpointvolume.h> 

int APIENTRY _tWinMain(HINSTANCE hInstance,
                 HINSTANCE hPrevInstance,
                 LPTSTR    lpCmdLine,
                 int       nCmdShow)
{
double newVolume = _ttof(lpCmdLine);

CoInitialize(NULL);

IMMDeviceEnumerator* deviceEnumerator = NULL;
if(CoCreateInstance(__uuidof(MMDeviceEnumerator), NULL, CLSCTX_INPROC_SERVER, __uuidof(IMMDeviceEnumerator), (LPVOID *)&deviceEnumerator) == S_OK) {
    IMMDevice* defaultDevice = NULL;
    if(deviceEnumerator->GetDefaultAudioEndpoint(eRender, eConsole, &defaultDevice) == S_OK) {
        IAudioEndpointVolume* endpointVolume = NULL;
        if(defaultDevice->Activate(__uuidof(IAudioEndpointVolume), CLSCTX_INPROC_SERVER, NULL, (LPVOID *)&endpointVolume) == S_OK) {
            endpointVolume->SetMasterVolumeLevelScalar((float)newVolume, NULL);
            endpointVolume->Release();
        }
        defaultDevice->Release();
    }
    deviceEnumerator->Release();
}

CoUninitialize();

return 0;
}

, .

+1

Source: https://habr.com/ru/post/1784386/


All Articles