1

このメソッドに送信されるサウンドを繰り返したいですか?

- (void) playSound:(CFURLRef)soundFileURLRef {
    SystemSoundID soundID;
    OSStatus errorCode = AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);
    if (errorCode != 0) {

    }else{
        AudioServicesPlaySystemSound(soundID);
    }
}

numberOfRepeats を使用してこれを作成する方法についての回答を見てきました。しかし、私のコードには収まりません。

4

1 に答える 1

0

使用してみてくださいAVAudioPlayer

- (void) playSound:(CFURLRef)soundFileURLRef {
    NSError* sndErr;        
    AVAudioPlayer *player = [[ AVAudioPlayer alloc ] initWithContentsOfURL:(NSURL *)soundFileURLRef error:(&sndErr) ];

    // at this point player has a retain count of 1. you should save it 
    // somewhere like a class member variable so you can stop the playing
    // and release the object later. Under ARC, you must have a strong reference
    // to the object so that it doesn't get released when this function goes out
    // of scope.

    if (sndErr != nil) {
        player.numberOfLoops = -1; // infinite number of loops. call stop when you want to stop.
        [player play];
    }
}
于 2012-10-06T23:18:42.333 に答える