AVAudioPlayer not looping
- by Nick
Hey guys,
I have this code:
- (id<SelfReleasingSound>) initWithFilepath: (NSString *) filepath {
self = [super init];
if(self != nil){
NSData * soundFileData = [NSData dataWithContentsOfFile: filepath];
NSError * error;
player = [[AVAudioPlayer alloc] initWithData: soundFileData error: &error];
if(error != nil){
JNLogAlert(@"Failed to load sound(%@)", filepath);
}
volume = 1.0;
loops = 0;
player.volume = volume;
player.numberOfLoops = loops;
[player prepareToPlay];
}
return self;
}
- (void) play {
player.numberOfLoops = loops;
JNLogString(@"PLAYING: %D LOOPS", player.numberOfLoops);
[player play];
}
JNLogString is a wrapper for NSLog, and while my program says this:
2010-03-24 03:39:40.882 Bubbleeh[50766:207] JNSoundFile.m:40 PLAYING: 5 LOOPS
It actually only plays 1 time, as if numberOfLoops were 0.
Am I doing something wrong?
Thanks in advance,