我创建了处理声音的类。但我有问题停止声音?我无法将变量从 playSound 发送到 stopSound AudioServicesDisposeSystemSoundID(soundID)。如何处理?我真的不想实例化它还是我必须实例化它?
@implementation SoundPlayer
+(void)playSound:(NSString *)filename ofType:(NSString *)extension {
SystemSoundID soundID;
NSString *soundFile = [[NSBundle mainBundle] pathForResource:filename ofType:extension];
AudioServicesCreateSystemSoundID((__bridge CFURLRef)[NSURL fileURLWithPath:soundFile], &soundID);
AudioServicesPlaySystemSound(soundID); // error - soundID is undeclared
}
+(void)stopSound
{
AudioServicesDisposeSystemSoundID(soundID);
}
@end