我已经遇到过,女巫很简单,我在Google或任何论坛中都找不到。如何关闭应用程序的音频/声音?喜欢静音吗?我不想让复选框控制应用程序的声音。

我很感谢详细的定义

最佳答案

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;
    }
}

10-02 21:32