Last active
August 29, 2015 14:07
-
-
Save takopom/cabb63746bb3e0f3d0df to your computer and use it in GitHub Desktop.
AVAudioPlayerNodeでループ再生
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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