Fix device selection #40
4 changed files with 66 additions and 20 deletions
|
@ -26,7 +26,8 @@
|
|||
- (id)initWithController:(OutputNode *)c;
|
||||
|
||||
- (BOOL)setup;
|
||||
- (BOOL)setOutputDevice:(AudioDeviceID)outputDevice;
|
||||
- (OSStatus)setOutputDeviceByID:(AudioDeviceID)deviceID;
|
||||
- (BOOL)setOutputDeviceWithDeviceDict:(NSDictionary *)deviceDict;
|
||||
- (void)start;
|
||||
- (void)pause;
|
||||
- (void)resume;
|
||||
|
|
|
@ -71,7 +71,8 @@ static OSStatus Sound_Renderer(void *inRefCon, AudioUnitRenderActionFlags *ioAc
|
|||
}
|
||||
|
||||
|
||||
- (OSStatus)setOutputDeviceByID:(AudioDeviceID)deviceID {
|
||||
- (OSStatus)setOutputDeviceByID:(AudioDeviceID)deviceID
|
||||
{
|
||||
OSStatus err;
|
||||
|
||||
if (deviceID == -1) {
|
||||
|
@ -85,10 +86,13 @@ static OSStatus Sound_Renderer(void *inRefCon, AudioUnitRenderActionFlags *ioAc
|
|||
err = AudioObjectGetPropertyData(kAudioObjectSystemObject, &theAddress, 0, NULL, &size, &deviceID);
|
||||
|
||||
if (err != noErr) {
|
||||
ALog(@"THERE'S NO DEFAULT OUTPUT DEVICE");
|
||||
DLog(@"THERE'S NO DEFAULT OUTPUT DEVICE");
|
||||
|
||||
return err;
|
||||
}
|
||||
else {
|
||||
outputDeviceID = deviceID;
|
||||
}
|
||||
}
|
||||
|
||||
printf("DEVICE: %i\n", deviceID);
|
||||
|
@ -101,6 +105,12 @@ static OSStatus Sound_Renderer(void *inRefCon, AudioUnitRenderActionFlags *ioAc
|
|||
&deviceID,
|
||||
sizeof(AudioDeviceID));
|
||||
|
||||
if (err != noErr) {
|
||||
DLog(@"No output device with ID %d could be found.", deviceID);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
|
@ -114,6 +124,7 @@ static OSStatus Sound_Renderer(void *inRefCon, AudioUnitRenderActionFlags *ioAc
|
|||
if (err != noErr) {
|
||||
// Try matching by name.
|
||||
NSString *userDeviceName = deviceDict[@"name"];
|
||||
|
||||
[self enumerateAudioOutputsUsingBlock:
|
||||
^(NSString *deviceName, AudioDeviceID deviceID, AudioDeviceID systemDefaultID, BOOL *stop) {
|
||||
if ([deviceName isEqualToString:userDeviceName]) {
|
||||
|
@ -124,12 +135,14 @@ static OSStatus Sound_Renderer(void *inRefCon, AudioUnitRenderActionFlags *ioAc
|
|||
// Update `outputDevice`, in case the ID has changed.
|
||||
NSDictionary *deviceInfo = @{
|
||||
@"name": deviceName,
|
||||
@"deviceID": [NSNumber numberWithUnsignedInt:deviceID],
|
||||
@"deviceID": @(deviceID),
|
||||
};
|
||||
[[NSUserDefaults standardUserDefaults] setObject:deviceInfo forKey:@"outputDevice"];
|
||||
#endif
|
||||
|
||||
return;
|
||||
DLog(@"Found output device: \"%@\" (%d).", deviceName, deviceID);
|
||||
|
||||
*stop = YES;
|
||||
}
|
||||
}];
|
||||
}
|
||||
|
|
|
@ -329,6 +329,20 @@
|
|||
remoteGlobalIDString = 8D5B49AC048680CD000E48DA;
|
||||
remoteInfo = General;
|
||||
};
|
||||
3D2C77DC23FABECD00B3FAEC /* PBXContainerItemProxy */ = {
|
||||
isa = PBXContainerItemProxy;
|
||||
containerPortal = 83E6B750181612FD00D4576D /* Sparkle.xcodeproj */;
|
||||
proxyType = 2;
|
||||
remoteGlobalIDString = EA4311EA229D651300A5503D;
|
||||
remoteInfo = bsdiff;
|
||||
};
|
||||
3D2C77DE23FABECD00B3FAEC /* PBXContainerItemProxy */ = {
|
||||
isa = PBXContainerItemProxy;
|
||||
containerPortal = 83E6B750181612FD00D4576D /* Sparkle.xcodeproj */;
|
||||
proxyType = 2;
|
||||
remoteGlobalIDString = EA4311A0229D5FBC00A5503D;
|
||||
remoteInfo = ed25519;
|
||||
};
|
||||
566D321A0D538550004466A5 /* PBXContainerItemProxy */ = {
|
||||
isa = PBXContainerItemProxy;
|
||||
containerPortal = 566D32160D538550004466A5 /* APL.xcodeproj */;
|
||||
|
@ -1758,6 +1772,8 @@
|
|||
8319A68B1F79E99300C168D6 /* generate_appcast */,
|
||||
835C888622CC1853001B4B3F /* generate_keys */,
|
||||
835C888822CC1853001B4B3F /* sign_update */,
|
||||
3D2C77DD23FABECD00B3FAEC /* libbsdiff.a */,
|
||||
3D2C77DF23FABECD00B3FAEC /* libed25519.a */,
|
||||
);
|
||||
name = Products;
|
||||
sourceTree = "<group>";
|
||||
|
@ -1943,7 +1959,6 @@
|
|||
LastUpgradeCheck = 1100;
|
||||
TargetAttributes = {
|
||||
8D1107260486CEB800E47090 = {
|
||||
DevelopmentTeam = 4S876G9VCD;
|
||||
ProvisioningStyle = Automatic;
|
||||
};
|
||||
};
|
||||
|
@ -2152,6 +2167,20 @@
|
|||
remoteRef = 17F5622D0C3BD8FB0019975C /* PBXContainerItemProxy */;
|
||||
sourceTree = BUILT_PRODUCTS_DIR;
|
||||
};
|
||||
3D2C77DD23FABECD00B3FAEC /* libbsdiff.a */ = {
|
||||
isa = PBXReferenceProxy;
|
||||
fileType = archive.ar;
|
||||
path = libbsdiff.a;
|
||||
remoteRef = 3D2C77DC23FABECD00B3FAEC /* PBXContainerItemProxy */;
|
||||
sourceTree = BUILT_PRODUCTS_DIR;
|
||||
};
|
||||
3D2C77DF23FABECD00B3FAEC /* libed25519.a */ = {
|
||||
isa = PBXReferenceProxy;
|
||||
fileType = archive.ar;
|
||||
path = libed25519.a;
|
||||
remoteRef = 3D2C77DE23FABECD00B3FAEC /* PBXContainerItemProxy */;
|
||||
sourceTree = BUILT_PRODUCTS_DIR;
|
||||
};
|
||||
566D321B0D538550004466A5 /* APL.bundle */ = {
|
||||
isa = PBXReferenceProxy;
|
||||
fileType = wrapper.cfbundle;
|
||||
|
|
|
@ -9,18 +9,21 @@
|
|||
[self setSelectsInsertedObjects:NO];
|
||||
|
||||
NSDictionary *defaultDevice = [[[NSUserDefaultsController sharedUserDefaultsController] defaults] objectForKey:@"outputDevice"];
|
||||
NSString *defaultDeviceName = defaultDevice[@"name"];
|
||||
NSNumber *defaultDeviceIDNum = defaultDevice[@"deviceID"];
|
||||
AudioDeviceID defaultDeviceID = [defaultDeviceIDNum unsignedIntValue];
|
||||
|
||||
[self enumerateAudioOutputsUsingBlock:
|
||||
^(NSString *deviceName, AudioDeviceID deviceID, AudioDeviceID systemDefaultID, BOOL *stop) {
|
||||
NSDictionary *deviceInfo = @{
|
||||
@"name": deviceName,
|
||||
@"deviceID": [NSNumber numberWithUnsignedInt:deviceID],
|
||||
@"deviceID": @(deviceID),
|
||||
};
|
||||
[self addObject:deviceInfo];
|
||||
|
||||
if (defaultDevice) {
|
||||
if (([[defaultDevice objectForKey:@"deviceID"] isEqualToNumber:[deviceInfo objectForKey:@"deviceID"]]) ||
|
||||
([[defaultDevice objectForKey:@"name"] isEqualToString:[deviceInfo objectForKey:@"name"]])) {
|
||||
if ((deviceID == defaultDeviceID) ||
|
||||
([deviceName isEqualToString:defaultDeviceName])) {
|
||||
[self setSelectedObjects:[NSArray arrayWithObject:deviceInfo]];
|
||||
// Update `outputDevice`, in case the ID has changed.
|
||||
[[NSUserDefaults standardUserDefaults] setObject:deviceInfo forKey:@"outputDevice"];
|
||||
|
|
Loading…
Reference in a new issue