开发者

Use of undeclared identifier 'completionCallback'

开发者 https://www.devze.com 2023-02-27 01:23 出处:网络
I am attempting to identify when a sound has finished playing by using the AudioServicesAddSystemSoundCompletion met开发者_Go百科hod.The 4th parameter expects a C function, which I have implemented be

I am attempting to identify when a sound has finished playing by using the AudioServicesAddSystemSoundCompletion met开发者_Go百科hod. The 4th parameter expects a C function, which I have implemented below. I recieve the error message,

Use of undeclared identifier 'completionCallback' (first use in this function) when referencing it. None of the online examples I've seen has ever used [self completionCallback], and they have no issues.

Where am I going wrong?

-(void)playAndRelease{
    AudioServicesAddSystemSoundCompletion (_soundID,NULL,NULL,completionCallback,(void*) self);
    AudioServicesPlaySystemSound(_soundID);
}

void completionCallback (SystemSoundID  mySSID, void* myself) {
    //NSLog(@"completion Callback");
    AudioServicesRemoveSystemSoundCompletion (mySSID);
    [(SoundEffect*)myself release];
}


Well, yes. Sometimes, an error messaqge means exactly what it says. completionCallback needs to be defined above playAndRelease.

First option: declare, but don't implement, completionCallback.

void completionCallback (SystemSoundID  mySSID, void* myself);

-(void)playAndRelease{
    AudioServicesAddSystemSoundCompletion (_soundID,NULL,NULL,completionCallback,(void*) self);
    AudioServicesPlaySystemSound(_soundID);
}

void completionCallback (SystemSoundID  mySSID, void* myself) {
    //NSLog(@"completion Callback");
    AudioServicesRemoveSystemSoundCompletion (mySSID);
    [(SoundEffect*)myself release];
}

Or define it fully ahead of time:

static void completionCallback (SystemSoundID  mySSID, void* myself) {
    //NSLog(@"completion Callback");
    AudioServicesRemoveSystemSoundCompletion (mySSID);
    [(SoundEffect*)myself release];
}

-(void)playAndRelease{
    AudioServicesAddSystemSoundCompletion (_soundID,NULL,NULL,completionCallback,(void*) self);
    AudioServicesPlaySystemSound(_soundID);
}

See also:

  • Wikipedia: Function prototype
0

精彩评论

暂无评论...
验证码 换一张
取 消