iphone - ios流mp3并录制声音

标签 iphone ios stream avaudioplayer avaudiorecorder

问题:通过 http 流式传输音频后无法录制声音。

我遇到的问题是使用本指南流式传输 mp3 后我无法再录制声音:http://cocoawithlove.com/2008/09/streaming-and-playing-live-mp3-stream.html

在播放任何 mp3 之前,我可以完美地录制声音。只有在我使用指南流式传输 mp3 后,我的 ios 应用程序才能再录制声音。

我想知道你们中是否有人可能以前遇到过这个问题,或者有任何预感为什么会出现这个问题?我将继续发布我的记录代码,以防万一你们需要查看它。

在我流式传输任何 mp3 之前,audioRecorderDidFinishRecording 总是在录制完成后触发。

在我流式传输 mp3 后,audioRecorderDidFinishRecording 在录制完成后永远不会触发。

预先感谢您的帮助。

    // #########################
    NSURL *soundFileUrl = [NSURL fileURLWithPath:self.recordFilePath];

    NSDictionary *recordSettings = [NSDictionary dictionaryWithObjectsAndKeys:
                              [NSNumber numberWithInt:kAudioFormatLinearPCM], AVFormatIDKey,
                              [NSNumber numberWithInt:AVAudioQualityMax], AVEncoderAudioQualityKey,
                              [NSNumber numberWithInt:24], AVEncoderBitRateKey,
                              [NSNumber numberWithInt:1], AVNumberOfChannelsKey,
                              [NSNumber numberWithFloat:22050.0f], AVSampleRateKey,
                              nil];

     NSError *error = nil;
     self.recorder = [[AVAudioRecorder alloc] initWithURL:soundFileUrl settings:recordSettings error:&error];

     if (error)  {
       NSLog(@"%@", error);
     } else{    
       self.recorder.delegate = self;
       [self.recorder  prepareToRecord];    
       [self.recorder record];

       self.recordCountdown = [NSTimer scheduledTimerWithTimeInterval:(1.0/1.0) target:self selector:@selector(updateLabelCountdown) userInfo:nil repeats:YES]; 
     }

    // delegate for finish recording with success and failure
    - (void) audioRecorderDidFinishRecording:(AVAudioRecorder *)recorder successfully:(BOOL)flag {  
        NSLog(@"record did finish flag - %d", flag);
      }

    - (void) audioRecorderEncodeErrorDidOccur:(AVAudioRecorder *)recorder error:(NSError *)error   {
        NSLog(@"error record - %@", [error localizedDescription]);
      }

最佳答案

试试这个

[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord error:nil];

引用 iPhone SDK: AVAudioRecorder will not record after calling [AVPlayer play]

关于iphone - ios流mp3并录制声音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7650641/

相关文章:

ios - Passbook 通行证可以适用多天吗?

javascript - 局部变量到全局javascript

c# - 内存流与文件流 : Document Viewer rendering document from filestream successfully but not memorystream?

ios - 如何在 Swift 中将 NSSet 转换为 NSMutableSet

android - 当应用程序有加载时间时如何最大化用户体验

iphone - 像滑动菜单一样推文

iphone - 以编程方式确定 VoiceOver 读取 UIView 项目的顺序

ios - 如何在发布应用程序之前获取 iTunes Connect ID?

iphone - 关于 iPhone 应用程序下载计数

ios - 如何在swift中使用for in循环递减条件?