mirror of
https://github.com/kyleneideck/BackgroundMusic
synced 2024-11-26 14:10:16 +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,28 +325,31 @@ OSStatus BGMDeviceControlSync::BGMDeviceListenerProc(AudioObjectID inObjectID
|
|||
// refCon (reference context) is the instance that registered this listener proc
|
||||
BGMDeviceControlSync* refCon = static_cast<BGMDeviceControlSync*>(inClientData);
|
||||
|
||||
ThrowIf(inObjectID != refCon->mBGMDevice.GetObjectID(),
|
||||
CAException(kAudioHardwareBadObjectError),
|
||||
"BGMDeviceControlSync::BGMDeviceListenerProc: notified about audio object other than BGMDevice");
|
||||
|
||||
for(int i = 0; i < inNumberAddresses; i++)
|
||||
if(refCon->mActive)
|
||||
{
|
||||
AudioObjectPropertyScope scope = inAddresses[i].mScope;
|
||||
ThrowIf(inObjectID != refCon->mBGMDevice.GetObjectID(),
|
||||
CAException(kAudioHardwareBadObjectError),
|
||||
"BGMDeviceControlSync::BGMDeviceListenerProc: notified about audio object other than BGMDevice");
|
||||
|
||||
switch(inAddresses[i].mSelector)
|
||||
for(int i = 0; i < inNumberAddresses; i++)
|
||||
{
|
||||
case kAudioDevicePropertyVolumeScalar:
|
||||
// Update the output device
|
||||
CopyVolume(refCon->mBGMDevice, refCon->mOutputDevice, scope);
|
||||
break;
|
||||
|
||||
case kAudioDevicePropertyMute:
|
||||
// Update the output device. Note that this also runs when you change the volume (on BGMDevice)
|
||||
CopyMute(refCon->mBGMDevice, refCon->mOutputDevice, scope);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
AudioObjectPropertyScope scope = inAddresses[i].mScope;
|
||||
|
||||
switch(inAddresses[i].mSelector)
|
||||
{
|
||||
case kAudioDevicePropertyVolumeScalar:
|
||||
// Update the output device
|
||||
CopyVolume(refCon->mBGMDevice, refCon->mOutputDevice, scope);
|
||||
break;
|
||||
|
||||
case kAudioDevicePropertyMute:
|
||||
// Update the output device. Note that this also runs when you change the volume (on BGMDevice)
|
||||
CopyMute(refCon->mBGMDevice, refCon->mOutputDevice, scope);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue