Cocoa Mac OSX应用程序关闭声音

时间:2014-09-29 14:04:45

标签: macos cocoa audio libvlc

我已经面临过,女巫简单的quoestion,我在谷歌或任何论坛都找不到。如何关闭应用音频/声音?喜欢静音?我不想让复选框控制应用声音。

我很感激详细的定义

1 个答案:

答案 0 :(得分:0)

source code

尝试此操作
- (void)setDefaultAudioDevice
{
    UInt32 propertySize = 0;
    OSStatus status = noErr;
    AudioObjectPropertyAddress propertyAOPA;

    propertyAOPA.mElement = kAudioObjectPropertyElementMaster;
    propertyAOPA.mScope = kAudioObjectPropertyScopeGlobal;
    propertyAOPA.mSelector = kAudioHardwarePropertyDefaultOutputDevice;
    propertySize = sizeof(AudioDeviceID);

    status = AudioHardwareServiceGetPropertyData(kAudioObjectSystemObject, &propertyAOPA, 0, NULL, &propertySize, &outputDeviceID); 

    if(status) 
    {
        // Error
        return;
    }
}

- (void)muteHardwareVolume
{
    UInt32 propertySize = 0;
    OSStatus status = noErr;
    AudioObjectPropertyAddress propertyAOPA;

    [self setDefaultAudioDevice];

    propertyAOPA.mElement = kAudioObjectPropertyElementMaster;
    propertyAOPA.mScope = kAudioDevicePropertyScopeOutput;

    propertyAOPA.mSelector = kAudioDevicePropertyMute;

    propertySize = sizeof(UInt32);
    UInt32 mute = 1;
    status = AudioHardwareServiceSetPropertyData(outputDeviceID, &propertyAOPA, 0, NULL,    propertySize, &mute);

    if(status) 
    {
        // Error
        return;
    }
}
相关问题