Re: API for switching audio output device or disabling output altogether
Re: API for switching audio output device or disabling output altogether
- Subject: Re: API for switching audio output device or disabling output altogether
- From: William Stewart <email@hidden>
- Date: Fri, 11 Dec 2009 12:53:05 -0800
On Dec 10, 2009, at 10:49 PM, tahome izwah wrote:
Not sure if this helps but you can get the current default system
output device via
AudioDeviceID currentDevice;
UInt32 propsize = sizeof(AudioDeviceID);
OSStatus err = AudioHardwareGetProperty
(kAudioHardwarePropertyDefaultOutputDevice,
&propsize, ¤tDevice);
In order to find the built-in device you iterate through all audio
devices calling
UInt32 transportType;
UInt32 propsize=sizeof(AudioDeviceID);
OSStatus err = AudioDeviceGetProperty(deviceID, 0, false,
kAudioDevicePropertyTransportType, &propsize, &transportType);
on each device. The built-in audio hardware has transportType ==
kIOAudioDeviceTransportTypeBuiltIn. You can set it system wide via
this call when required:
OSStatus err = AudioHardwareSetProperty
(kAudioHardwarePropertyDefaultOutputDevice,
sizeof(AudioDeviceID), &outputDevice);
So you should be able to switch your device as required. Whether or
not this is good practice from a user experience POV I do not know -
It is not. Applications should not be setting the default device as
this is something the user controls.
It is also completely irrelevant to the question that was asked.
I
would think that Apple has a good reason for switching devices when
plugging in cables so I probably would not interefere with this.
We actually don't, unless the user has set a device to be default,
then removes it, then plugs it back in - in which case we switch to
it. Otherwise, we don't.
After all you can still play through the built-in device in your app
if you don't use the system output for playback.
HTH
--th
2009/12/11 Roger Thornhill <email@hidden>:
When an optical cable is inserted into the audio output port on an
iMac, a
hardware switch is triggered and the sound output device is
automatically
changed to "Digital Out". I'd like to know if there's a way to
prevent this
from happening by programmatically disabling or enabling the
optical output.
Right now the only way to switch from optical out to internal
speakers is
to physically disconnect the cable from the optical output port.
Yes - this is the default behaviour - the gesture is interpreted by
the system as a deliberate request by the user to route the audio to
what they've just plugged in.
The real question then is why would you NOT want this to switch?
Bill
I'd like
to figure out if there's a method to do this through software. If
there's
no public API to do this, if anyone can point me in the direction
of where I
might look for private API calls, that would be useful as well.
Roger
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden