我有一个东西,它使用SystemSoundID来播放声音,然后用一个C函数作为声音完成回调来重复,然后传递函数
(void *)self
(因为它必须是一个空指针),然后如果AlarmPlaying bool ivar of self为真,我想再次播放声音,否则删除声音完成并处理ssid(提供一个实例方法将AlarmPlaying设置为否)。正确的方法是什么
self
以一个空指针的形式,并得到它的警报播放ivar?如果我不需要的话,使用属性是没有意义的。我一直在出错
Request for member 'alarmPlaying' in something not a structure or union
以及取消引用void指针警告。我的功能是:
static void alarmSoundDidComplete(SystemSoundID soundID, void *myself) {
// ******* How do I access alarmPlaying from a 'self' casted to a void * ? *******
if((MidnightViewController *)myself->alarmPlaying) {
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[NSThread sleepForTimeInterval:kAlarmBeepInterval];
AudioServicesPlaySystemSound(soundID);
} else {
AudioServicesRemoveSystemSoundCompletion(soundID);
AudioServicesDisposeSystemSoundID(soundID);
}
}
(它在自己的线程上运行,所以我有一个kalamebeepinterval define'd)
在类的实现中,我有:
- (void)startPlayingAlarm {
SystemSoundID alarmSoundID = [Utilities createSystemSoundIDFromFile:@"beep"
ofType:@"caf"];
AudioServicesAddSystemSoundCompletion(alarmSoundID, NULL, NULL,
alarmSoundDidComplete, (void *)self);
alarmPlaying = YES;
AudioServicesPlaySystemSound(alarmSoundID);
}
- (void)stopPlayingAlarmAndDisposeSystemSoundID {
alarmPlaying = NO;
}
谢谢。