views:

105

answers:

1

I'm trying to use a sound callback function to show a button once my sound file completes playing.

//defining the callback
AudioServicesAddSystemSoundCompletion (soundID, NULL, NULL, AudioPlaybackComplete, self.nextButton);

Here's the callback function:

static void AudioPlaybackComplete(SystemSoundID  ssID, void *clientData)

{

NSLog(@"Show those darn buttons");
AudioServicesRemoveSystemSoundCompletion (ssID);

//show the buttons so you can switch to the next animal
[nextButton setHidden:YES];

}

I've got nextButton defined as an outlet in the header file and referenced properly. I get the following error when the [nextButton setHidden:YES]; tries to execute: "error: 'nextButton' undeclared (first use in this function)".

I believe because this is a static function it's having problems referencing the instance variable form this file. Any thoughts on how I can have this method not be static, or have it reference the button properly?

Thanks

A: 

Ah I figured it out. The trick was to pass in the button to the callback function.

    //defining the callback    
    AudioServicesAddSystemSoundCompletion (soundID, NULL, NULL, AudioPlaybackComplete, self.nextButton);

And then the callback function itself

static void AudioPlaybackComplete(SystemSoundID  ssID, void *button)
    {
        NSLog(@"Show those darn buttons");
        AudioServicesRemoveSystemSoundCompletion (ssID);

        //show the buttons so you can switch to the next animal
        [button setHidden:NO];
    }
Jamis Charles