Fixed problem where the volume was not really muted when reaching zero
This commit is contained in:
parent
7ed174907f
commit
f25fe72046
|
|
@ -38,27 +38,55 @@
|
|||
return defaultOutputDeviceID;
|
||||
}
|
||||
|
||||
- (void) setCurrentVolume:(double)currentVolume
|
||||
- (void)setCurrentVolume:(double)currentVolume
|
||||
{
|
||||
AudioDeviceID defaultOutputDeviceID = [self getDefaultOutputDevice];
|
||||
|
||||
|
||||
AudioObjectPropertyAddress volumePropertyAddress = {
|
||||
kAudioHardwareServiceDeviceProperty_VirtualMasterVolume,
|
||||
kAudioHardwareServiceDeviceProperty_VirtualMainVolume,
|
||||
kAudioDevicePropertyScopeOutput,
|
||||
kAudioObjectPropertyElementMaster
|
||||
};
|
||||
|
||||
Float32 volume = (Float32)(currentVolume/100.);
|
||||
UInt32 volumedataSize = sizeof(volume);
|
||||
|
||||
OSStatus result = AudioObjectSetPropertyData(defaultOutputDeviceID,
|
||||
&volumePropertyAddress,
|
||||
0, NULL,
|
||||
volumedataSize, &volume);
|
||||
|
||||
if (result != kAudioHardwareNoError) {
|
||||
NSLog(@"No volume set for device 0x%0x", defaultOutputDeviceID);
|
||||
}
|
||||
|
||||
AudioObjectPropertyAddress mutePropertyAddress = {
|
||||
kAudioDevicePropertyMute,
|
||||
kAudioDevicePropertyScopeOutput,
|
||||
kAudioObjectPropertyElementMaster
|
||||
};
|
||||
|
||||
Float32 volume = (Float32)(currentVolume / 100.);
|
||||
UInt32 dataSize;
|
||||
|
||||
if (volume == 0) {
|
||||
// Mute the device
|
||||
UInt32 mute = 1;
|
||||
dataSize = sizeof(mute);
|
||||
OSStatus result = AudioObjectSetPropertyData(defaultOutputDeviceID,
|
||||
&mutePropertyAddress,
|
||||
0, NULL,
|
||||
dataSize, &mute);
|
||||
if (result != noErr) {
|
||||
NSLog(@"Failed to mute device 0x%0x", defaultOutputDeviceID);
|
||||
}
|
||||
} else {
|
||||
// Unmute the device
|
||||
UInt32 mute = 0;
|
||||
dataSize = sizeof(mute);
|
||||
AudioObjectSetPropertyData(defaultOutputDeviceID,
|
||||
&mutePropertyAddress,
|
||||
0, NULL,
|
||||
dataSize, &mute);
|
||||
|
||||
// Set the volume
|
||||
dataSize = sizeof(volume);
|
||||
OSStatus result = AudioObjectSetPropertyData(defaultOutputDeviceID,
|
||||
&volumePropertyAddress,
|
||||
0, NULL,
|
||||
dataSize, &volume);
|
||||
if (result != noErr) {
|
||||
NSLog(@"Failed to set volume for device 0x%0x", defaultOutputDeviceID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (bool) isMuted
|
||||
|
|
@ -91,7 +119,7 @@
|
|||
AudioDeviceID defaultOutputDeviceID = [self getDefaultOutputDevice];
|
||||
|
||||
AudioObjectPropertyAddress volumePropertyAddress = {
|
||||
kAudioHardwareServiceDeviceProperty_VirtualMasterVolume,
|
||||
kAudioHardwareServiceDeviceProperty_VirtualMainVolume,
|
||||
kAudioDevicePropertyScopeOutput,
|
||||
kAudioObjectPropertyElementMaster
|
||||
};
|
||||
|
|
|
|||
|
|
@ -350,7 +350,7 @@
|
|||
isa = PBXProject;
|
||||
attributes = {
|
||||
BuildIndependentTargetsInParallel = YES;
|
||||
LastUpgradeCheck = 1610;
|
||||
LastUpgradeCheck = 1640;
|
||||
TargetAttributes = {
|
||||
65996C54267EA86A0080A9A5 = {
|
||||
CreatedOnToolsVersion = 12.5;
|
||||
|
|
@ -442,6 +442,7 @@
|
|||
COPY_PHASE_STRIP = NO;
|
||||
DEAD_CODE_STRIPPING = YES;
|
||||
DEBUG_INFORMATION_FORMAT = dwarf;
|
||||
DEVELOPMENT_TEAM = 9V3X7C8VCK;
|
||||
ENABLE_STRICT_OBJC_MSGSEND = YES;
|
||||
ENABLE_TESTABILITY = YES;
|
||||
ENABLE_USER_SCRIPT_SANDBOXING = YES;
|
||||
|
|
@ -503,6 +504,7 @@
|
|||
COPY_PHASE_STRIP = NO;
|
||||
DEAD_CODE_STRIPPING = YES;
|
||||
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
|
||||
DEVELOPMENT_TEAM = 9V3X7C8VCK;
|
||||
ENABLE_NS_ASSERTIONS = NO;
|
||||
ENABLE_STRICT_OBJC_MSGSEND = YES;
|
||||
ENABLE_USER_SCRIPT_SANDBOXING = YES;
|
||||
|
|
@ -531,7 +533,6 @@
|
|||
CODE_SIGN_STYLE = Automatic;
|
||||
COMBINE_HIDPI_IMAGES = YES;
|
||||
DEAD_CODE_STRIPPING = YES;
|
||||
DEVELOPMENT_TEAM = 9V3X7C8VCK;
|
||||
ENABLE_HARDENED_RUNTIME = YES;
|
||||
FRAMEWORK_SEARCH_PATHS = (
|
||||
"$(inherited)",
|
||||
|
|
@ -544,7 +545,7 @@
|
|||
"@loader_path/../Frameworks",
|
||||
);
|
||||
MACOSX_DEPLOYMENT_TARGET = 11.0;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = net.alberti42.VolumeControl;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = it.alberti42.VolumeControl;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
PROVISIONING_PROFILE_SPECIFIER = "";
|
||||
};
|
||||
|
|
@ -560,7 +561,6 @@
|
|||
CODE_SIGN_STYLE = Automatic;
|
||||
COMBINE_HIDPI_IMAGES = YES;
|
||||
DEAD_CODE_STRIPPING = YES;
|
||||
DEVELOPMENT_TEAM = 9V3X7C8VCK;
|
||||
ENABLE_HARDENED_RUNTIME = YES;
|
||||
FRAMEWORK_SEARCH_PATHS = (
|
||||
"$(inherited)",
|
||||
|
|
@ -573,7 +573,7 @@
|
|||
"@loader_path/../Frameworks",
|
||||
);
|
||||
MACOSX_DEPLOYMENT_TARGET = 11.0;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = net.alberti42.VolumeControl;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = it.alberti42.VolumeControl;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
PROVISIONING_PROFILE_SPECIFIER = "";
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Scheme
|
||||
LastUpgradeVersion = "1610"
|
||||
LastUpgradeVersion = "1640"
|
||||
version = "1.7">
|
||||
<BuildAction
|
||||
parallelizeBuildables = "YES"
|
||||
|
|
|
|||
Loading…
Reference in New Issue