使用AudioServicesAddSystemSoundCompletion传递参数

时间:2012-05-16 13:27:42

标签: iphone objective-c ios ipad audio

我尝试使用UILabel传递AudioServicesAddSystemSoundCompletion,但我无法操纵completionCallback方法中的值。我使用ARC和Xcode建议添加(_bridge void*)

非常感谢任何帮助。

-(void) playWordSound:(UILabel *)label
{
    NSString *path;
    SystemSoundID soundId;
    switch (label.tag)
    {
        case 1:
            ..........
            break;
    }
    NSURL *url = [NSURL fileURLWithPath:path];
    AudioServicesCreateSystemSoundID( (CFURLRef)objc_unretainedPointer( url), &soundId);
    AudioServicesPlaySystemSound(soundId);
    AudioServicesAddSystemSoundCompletion (soundId, NULL, NULL, 
                                           completionCallback,
                                           (__bridge void*) label);
}


static void completionCallback (SystemSoundID  mySSID, void* data) {
    NSLog(@"completion Callback");
    AudioServicesRemoveSystemSoundCompletion (mySSID);
    //the below line is not working
    //label.textColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:1];
}

1 个答案:

答案 0 :(得分:3)

在完成处理程序中,标签存储在data中。你需要__bridge回来使用它。

static void completionCallback (SystemSoundID  mySSID, void* data) {
    NSLog(@"completion Callback");
    AudioServicesRemoveSystemSoundCompletion (mySSID);
    UILabel *label = (__bridge UILabel*)data;
    label.textColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:1];
}