views:

117

answers:

0

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,

PS: For whom to code is confusing, the "loops" variable is set somewhere else in the code to 5.

PPS: For some sounds it does seem to work, but the code executed is exactly the same.

PPPS: For other files, it replays the last part of the sound file over and over, whatever the numberOfLoops is set to.