我正在使用 alexbw 的 Novocaine Novocaine对于我的音频项目。
我正在使用此处的示例代码来读取文件。 文件播放没有问题。我想用循环之间的间隙循环播放这段录音 - 关于如何做到这一点有什么建议吗?
谢谢。
码头。
// AUDIO FILE READING OHHH YEAHHHH
// ========================================
NSArray *pathComponents = [NSArray arrayWithObjects:
[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject],
@"testrecording.wav",
nil];
NSURL *inputFileURL = [NSURL fileURLWithPathComponents:pathComponents];
NSLog(@"URL: %@", inputFileURL);
fileReader = [[AudioFileReader alloc]
initWithAudioFileURL:inputFileURL
samplingRate:audioManager.samplingRate
numChannels:audioManager.numOutputChannels];
[fileReader play];
[fileReader setCurrentTime:0.0];
//float duration = fileReader.getDuration;
[audioManager setOutputBlock:^(float *data, UInt32 numFrames, UInt32 numChannels)
{
[fileReader retrieveFreshAudio:data numFrames:numFrames numChannels:numChannels];
NSLog(@"Time: %f", [fileReader getCurrentTime]);
}];
最佳答案
这对我有用:
[audioManager setOutputBlock:^(float *data, UInt32 numFrames, UInt32 numChannels)
{
if( ![fileReader playing] ){
// [fileReader release]; // for some reason this is causing an error, but I assume if you don´t do it, it will eventually cause a memory problem
// fileReader = nil;
[self playSound];
} else {
[fileReader retrieveFreshAudio:data numFrames:numFrames numChannels:numChannels];
NSLog(@"Time: %f", [fileReader getCurrentTime]);
}
}];
- (void) playSound
{
NSArray *pathComponents = [NSArray arrayWithObjects:
[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject],
@"testrecording.wav",
nil];
NSURL *inputFileURL = [NSURL fileURLWithPathComponents:pathComponents];
NSLog(@"URL: %@", inputFileURL);
fileReader = [[AudioFileReader alloc]
initWithAudioFileURL:inputFileURL
samplingRate:audioManager.samplingRate
numChannels:audioManager.numOutputChannels];
[fileReader play];
[fileReader setCurrentTime:0.0];
//float duration = fileReader.getDuration;
}
关于ios - Novocaine - 如何循环播放文件? (iOS),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13189251/