NSWindow not being shown on Intel Mac

  • I have written a program to mute the volume if headphones aren't plugged in,
    or if the user attempts to unmute the volume without headphones for a lab
    setting.  When the user attempts to change the volume or unplugs the
    headphones, a window appears saying Sound is disabled, please use
    headphones.
    This all works great on PPC macs, but for some reason on an intel iMac, the
    windows doesn't appear when the headphones are unplugged, only if the user
    attempts to change the volume.  I know the if statement is being called
    because it mutes the volume when the headphones are unplugged, it just
    doesn't show the window.  This is also only happening on the intel macs.
    Here is my code:

    if([self usingInternalSpeakers] && ![self soundIsMuted])

    {

    [self muteSound];

    //this makes sure our window is on top

    [NSApp activateIgnoringOtherApps:YES];

    //show the window

    [alertWindow makeKeyAndOrderFront:nil];

    }

    alertWindow is an NSWindow, and it works fine if the user attempts to change
    the volume, just not when headphones are unplugged.  My listener code is
    here:

    FourCharCode dataSource;

    UInt32 size = sizeof(dataSource);

    OSStatus err = AudioDeviceGetProperty(defaultSystemOutputDeviceID, 0, 0,
    kAudioDevicePropertyDataSource, &size, &dataSource);

    NSCAssert((err == noErr), @"AudioDeviceGetProperty failed to get the
    kAudioDevicePropertyDataSource property");

    //'ispk' == internal speakers

    //'hdpn' == headphones

    return dataSource == 'ispk';

    Do intel macs work differently for kAudioDeviceGetProperty, or
    makeKeyAndOrderFront?

    Thanks-

    Ryan
  • On Nov 2, 2007, at 1:37 PM, Ryan Harter wrote:

    > I have written a program to mute the volume if headphones aren't
    > plugged in,
    > or if the user attempts to unmute the volume without headphones for
    > a lab
    > setting.  When the user attempts to change the volume or unplugs the
    > headphones, a window appears saying Sound is disabled, please use
    > headphones.
    > This all works great on PPC macs, but for some reason on an intel
    > iMac, the
    > windows doesn't appear when the headphones are unplugged, only if
    > the user
    > attempts to change the volume.  I know the if statement is being
    > called
    > because it mutes the volume when the headphones are unplugged, it just
    > doesn't show the window.  This is also only happening on the intel
    > macs.
    > Here is my code:
    >
    > if([self usingInternalSpeakers] && ![self soundIsMuted])
    >
    > {
    >
    > [self muteSound];
    >
    > //this makes sure our window is on top
    >
    > [NSApp activateIgnoringOtherApps:YES];
    >
    > //show the window
    >
    > [alertWindow makeKeyAndOrderFront:nil];
    >
    > }
    >
    >
    > alertWindow is an NSWindow, and it works fine if the user attempts
    > to change
    > the volume, just not when headphones are unplugged.  My listener
    > code is
    > here:
    >
    >
    > FourCharCode dataSource;
    >
    > UInt32 size = sizeof(dataSource);
    >
    > OSStatus err = AudioDeviceGetProperty(defaultSystemOutputDeviceID,
    > 0, 0,
    > kAudioDevicePropertyDataSource, &size, &dataSource);
    >
    > NSCAssert((err == noErr), @"AudioDeviceGetProperty failed to get the
    > kAudioDevicePropertyDataSource property");
    >
    > //'ispk' == internal speakers
    >
    > //'hdpn' == headphones
    >
    > return dataSource == 'ispk';
    >
    >
    > Do intel macs work differently for kAudioDeviceGetProperty, or
    > makeKeyAndOrderFront?

    The first thing that comes to my mind is if this is a byte-swapping
    issue on those four-char-codes.

    Also, please don't cross-post.  This response is only going to cocoa-
    dev.

    ___________________________________________________________
    Ricky A. Sharp        mailto:<rsharp...>
    Instant Interactive(tm)  http://www.instantinteractive.com
previous month november 2007 next month
MTWTFSS
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30    
Go to today