[vlc-commits] macosx: automagically update the audio device list when the OS tells us to (close #8282)
Felix Paul Kühne
git at videolan.org
Sat Mar 9 21:56:50 CET 2013
vlc | branch: master | Felix Paul Kühne <fkuehne at videolan.org> | Sat Mar 9 21:56:24 2013 +0100| [59609879532da1990e8ad8cad3bd9ad603cb29cd] | committer: Felix Paul Kühne
macosx: automagically update the audio device list when the OS tells us to (close #8282)
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=59609879532da1990e8ad8cad3bd9ad603cb29cd
---
modules/gui/macosx/MainMenu.m | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/modules/gui/macosx/MainMenu.m b/modules/gui/macosx/MainMenu.m
index 35cded5..a016c61 100644
--- a/modules/gui/macosx/MainMenu.m
+++ b/modules/gui/macosx/MainMenu.m
@@ -24,6 +24,7 @@
#import "MainMenu.h"
#import <vlc_common.h>
#import <vlc_playlist.h>
+#import <CoreAudio/CoreAudio.h>
#import "intf.h"
#import "open.h"
@@ -45,6 +46,19 @@
#import "ExtensionsManager.h"
#import "ConvertAndSave.h"
+static OSStatus HardwareListener (AudioObjectID, UInt32, const AudioObjectPropertyAddress *, void *);
+
+static OSStatus HardwareListener(AudioObjectID inObjectID, UInt32 inNumberAddresses, const AudioObjectPropertyAddress inAddresses[], void*inClientData)
+{
+ VLC_UNUSED(inObjectID);
+ VLC_UNUSED(inNumberAddresses);
+ VLC_UNUSED(inAddresses);
+ // give the core some time update its internal structure for the new device setup
+ [[VLCMainMenu sharedInstance] performSelector:@selector(refreshAudioDeviceList) withObject:nil afterDelay:.5];
+
+ return noErr;
+}
+
@implementation VLCMainMenu
static VLCMainMenu *_o_sharedInstance = nil;
@@ -86,6 +100,11 @@ static VLCMainMenu *_o_sharedInstance = nil;
- (void)dealloc
{
+ AudioObjectPropertyAddress audioDevicesAddress = { kAudioHardwarePropertyDevices, kAudioObjectPropertyScopeGlobal, kAudioObjectPropertyElementMaster };
+ OSStatus err = AudioObjectRemovePropertyListener(kAudioObjectSystemObject, &audioDevicesAddress, HardwareListener, nil);
+ if (err != noErr)
+ msg_Err(p_intf, "failed to add audio hardware listener (%i)", err);
+
[[NSNotificationCenter defaultCenter] removeObserver: self];
if (b_nib_about_loaded)
@@ -263,6 +282,13 @@ static VLCMainMenu *_o_sharedInstance = nil;
[self setupExtensionsMenu];
[self refreshAudioDeviceList];
+
+ AudioObjectPropertyAddress audioDevicesAddress = { kAudioHardwarePropertyDevices,
+ kAudioObjectPropertyScopeGlobal,
+ kAudioObjectPropertyElementMaster };
+ OSStatus err = AudioObjectAddPropertyListener(kAudioObjectSystemObject, &audioDevicesAddress, HardwareListener, nil);
+ if (err != noErr)
+ msg_Err(p_intf, "failed to add audio hardware listener (%i)", err);
}
- (void)initStrings
More information about the vlc-commits
mailing list