mirror of
https://github.com/kyleneideck/BackgroundMusic
synced 2024-11-29 23:40:30 +00:00
Sync BGMDevice volume with output device correctly on BGMApp startup
The listener proc in BGMDeviceControlSync was being triggered during the initial CopyVolume call. This fix just waits until after the initial sync to register the listener proc.
This commit is contained in:
parent
5336a5a670
commit
646c00ceb6
1 changed files with 26 additions and 23 deletions
|
@ -60,6 +60,10 @@ void BGMDeviceControlSync::Activate()
|
|||
BGM_DeviceNotSetException(),
|
||||
"BGMDeviceControlSync::Activate: Both the output device and BGMDevice must be set to start synchronizing their controls");
|
||||
|
||||
// Init BGMDevice controls to match output device
|
||||
CopyVolume(mOutputDevice, mBGMDevice, kAudioObjectPropertyScopeOutput);
|
||||
CopyMute(mOutputDevice, mBGMDevice, kAudioObjectPropertyScopeOutput);
|
||||
|
||||
if(!mActive)
|
||||
{
|
||||
// Register listeners for volume and mute values
|
||||
|
@ -75,10 +79,6 @@ void BGMDeviceControlSync::Activate()
|
|||
throw;
|
||||
}
|
||||
|
||||
// Init BGMDevice controls to match output device
|
||||
CopyVolume(mOutputDevice, mBGMDevice, kAudioObjectPropertyScopeOutput);
|
||||
CopyMute(mOutputDevice, mBGMDevice, kAudioObjectPropertyScopeOutput);
|
||||
|
||||
mActive = true;
|
||||
}
|
||||
}
|
||||
|
@ -325,6 +325,8 @@ OSStatus BGMDeviceControlSync::BGMDeviceListenerProc(AudioObjectID inObjectID
|
|||
// refCon (reference context) is the instance that registered this listener proc
|
||||
BGMDeviceControlSync* refCon = static_cast<BGMDeviceControlSync*>(inClientData);
|
||||
|
||||
if(refCon->mActive)
|
||||
{
|
||||
ThrowIf(inObjectID != refCon->mBGMDevice.GetObjectID(),
|
||||
CAException(kAudioHardwareBadObjectError),
|
||||
"BGMDeviceControlSync::BGMDeviceListenerProc: notified about audio object other than BGMDevice");
|
||||
|
@ -349,6 +351,7 @@ OSStatus BGMDeviceControlSync::BGMDeviceListenerProc(AudioObjectID inObjectID
|
|||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue