2012-10-06 10 views
1

이 방법으로 보내는 사운드를 반복하고 싶습니까?어떻게 시스템 사운드를 반복 할 수 있습니까?

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

    }else{ 
     AudioServicesPlaySystemSound(soundID); 
    } 
} 

numberOfRepeats를 사용하여 어떻게 작성했는지에 대한 답변을 보았습니다. 하지만 내 코드에 맞지 않습니다.

답변

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]; 
    } 
} 
관련 문제