Reputation: 400
I created class for handling sounds. But I've problem to stop sound? I can't send variable from playSound to stopSound AudioServicesDisposeSystemSoundID(soundID). How to handle this? I really don't want instantiate it or I've to?
@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
Upvotes: 0
Views: 86
Reputation: 1121
You can create soundID as ivar, something like:
@interface SoundPlayer(){
SystemSoundID soundID;
}
@end
Other way use it as global variable
Upvotes: 0
Reputation: 5665
You'll either have to pass the id to stopSound (the same as when you play sound), or else if your audio player only plays 1 sound at a time, store the soundID as a static param on the class when you play.
Upvotes: 1