AVAudioPlayer not looping
Posted
by Nick
on Stack Overflow
See other posts from Stack Overflow
or by Nick
Published on 2010-03-24T03:10:51Z
Indexed on
2010/03/24
3:13 UTC
Read the original article
Hit count: 519
avaudioplayer
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,
© Stack Overflow or respective owner