ios - Novocaine - 如何循环播放文件? (iOS)

标签 ios core-audio

我正在使用 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/

相关文章:

ios - 如何在iOS模拟器上将应用启动到后台?

ios - 在 Swift Playground 中创建 UIManagedDocument - 信号 SIGABRT 错误

ios - NSMutableURLRequest 设置授权头

iphone - 使用 AudioQueue 读取音频缓冲区数据

ios - Adobe AIR AppStore 上传错误 : Invalid Code Signing Entitlements. .. 'get-task-allow' (

php - 使用 Objective-C 从服务器获取数据

c - Learning Core Audio 第 8 章示例未运行

c - 如何从外部音频接口(interface)访问具有核心音频的各个 channel

ios - 是否可以检查音频缓冲区的填充量?

c - 核心音频录制的声音失真且有噪音