• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How to programmatically change the default sound output device?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to programmatically change the default sound output device?


  • Subject: Re: How to programmatically change the default sound output device?
  • From: "Mikael Hakman" <email@hidden>
  • Date: Sat, 19 Jan 2008 12:41:20 +0100
  • Organization: Datakonsulten AB

I'm taking in device name from command line. I loop over device ids exactly as you described. For each device id I get its name by:

CFStringRef name;
UInt32 size = sizeof(name);
AudioDeviceGetProperty(id,0,false,kAudioObjectPropertyName,&size,&name);

Then I compare current name with the specified name. If they match I set the device to default. I hope device names stay the same across (un)plugging and reboots. I tested it so far with 2 USB audio interface devices - they keep their names. I'll remember that device ids may change, as you point out.

Thanks/Mikael

--- Thorrin <email@hidden> wrote:

NP.

I will say that you will need to test your app for USB
devices and/or firewire devices.  Unplugging a set of
USB headphones and then re-inserting it will give you
a new device ID (IIRC).

-T

--- Mikael Hakman <email@hidden> wrote:

A lot of thanks T for very clear and to the point
information! This works
like a breeze. I couldn't find this information in
the reference because the
reference doesn't have the usual bar on the left
with "Functions by Task"
etc. headers. Anyhow, following your example, I made
a small shell tool that
takes name of an output device on command line and
sets it to default. I don't
know whether it is appropriate or customary to post
the source here.

BTW AudioDeviceGet/SetProperty calls remind me of
UNIX IOCTL calls very
much, which is good for someone coming from that
place.

Thanks again/Mikael

Thorrin wrote:

> Take a look at these functions:
> AudioHardwareGetPropertyInfo
> AudioHardwareGetProperty
> AudioHardwareSetProperty
>
> AudioDeviceSetPropertyInfo
> AudioDeviceGetProperty
> AudioDeviceSetProperty
>
> To get a list of devices on the system, do
something
> like this (this is Carbon, BTW):
>
> UInt32 size;
> UInt32 number_of_devices_on_system;
> AudioDeviceID *dev_array;
>

AudioHardwareGetPropertyInfo(kAudioHardwarePropertyDevices,&size,
> NULL);
>

AudioHardwareGetProperty(kAudioHardwarePropertyDevices,
> &size, dev_array);
>
> number_of_devices_on_system = (size / sizeof
> (AudioDeviceID));
>
> You can use a for loop to get the device IDs from
> dev_array.
>
> To set the default output to one of those devices,
do
> this:
>
> UInt32 dev_to_set_to;
> dev_to_set_to = (whatever device number you want
from
> array above)
>

AudioHardwareSetProperty(kAudioHardwarePropertyDefaultOutputDevice,
> sizeof (UInt32), &dev_to_set_to);
>
> I think that will do it.  There are other things
you
> can get with the functions above like device
names,
> types (usb, builtin, etc) and stuff like that.
>
> Lol, hope I explained it ok ;)
> -T
>
> --- Mikael Hakman <email@hidden> wrote:
>
>> Hello,
>>
>> How do I programmatically change the default
sound
>> output device? I'm
>> building an application that on user request will
>> change audio, display and
>> some other settings. Then the user will run
whatever
>> media applications
>> he/she likes. By another user request all these
>> settings will be restored to
>> values before change. For display I use the
Quartz
>> calls but I can not
>> figure out what API to use for changing the
default
>> sound output. Any help
>> would be appreciated.
>>
>> Thanks/Mikael
>>
>>  _______________________________________________
>> 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
>>
>
>
> "Everyone is allergic to giant rocks hitting them
in the head!"
> -Thorrin's elf chick after casting a 'meteor
swarm' spell ;)
>
>
>
>

____________________________________________________________________________________
> Be a better friend, newshound, and
> know-it-all with Yahoo! Mobile.  Try it now.
>

http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
>
> __________ NOD32 2802 (20080117) Information
__________
>
> Detta meddelande är genomsökt av NOD32 Antivirus.
> http://www.nod32.com
>
>




"Everyone is allergic to giant rocks hitting them in the head!"
-Thorrin's elf chick after casting a 'meteor swarm' spell ;)



____________________________________________________________________________________
Looking for last minute shopping deals?
Find them fast with Yahoo! Search. http://tools.search.yahoo.com/newsearch/category.php?category=shopping


__________ NOD32 2805 (20080118) Information __________

Detta meddelande är genomsökt av NOD32 Antivirus.
http://www.nod32.com



_______________________________________________ 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
References: 
 >Re: How to programmatically change the default sound output device? (From: Thorrin <email@hidden>)

  • Prev by Date: Re: the format flag kLinearPCMFormatFlagIsPacked
  • Next by Date: OT: I/O device with multiple *independent* SPDIF ports?
  • Previous by thread: Re: How to programmatically change the default sound output device?
  • Next by thread: Re: How to programmatically change the default sound output device?
  • Index(es):
    • Date
    • Thread