Skip to content

Instantly share code, notes, and snippets.

@takopom
Last active August 29, 2015 14:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save takopom/cabb63746bb3e0f3d0df to your computer and use it in GitHub Desktop.
Save takopom/cabb63746bb3e0f3d0df to your computer and use it in GitHub Desktop.
AVAudioPlayerNodeでループ再生
NSError *error = nil;
AVAudioFile *audioFile = [[AVAudioFile alloc]initForReading:url error:&error];
if (error) {
NSLog(@"%@", error);
}
// 注:fileFormatではなくprocessingFormatの方を使う!
AVAudioFormat *format = audioFile.processingFormat;
AVAudioFrameCount length = (AVAudioFrameCount)audioFile.length;
AVAudioPCMBuffer *buffer = [[AVAudioPCMBuffer alloc]initWithPCMFormat:format frameCapacity:length];
[audioFile readIntoBuffer:buffer error:&error];
if (error) {
NSLog(@"%@", error);
}
// フラグを指定するだけでループ再生してくれる。
[playerNode scheduleBuffer:buffer atTime:nil options:AVAudioPlayerNodeBufferLoops completionHandler:nil];
[playerNode play];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment