ios 流 mp3 并录制声音

发布于 2024-12-08 01:59:13 字数 2128 浏览 0 评论 0原文

问题:通过 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]);
      }

problem: cannot record sound after streaming audio over http.

The problem which I am having is that I can no longer record sound after streaming mp3 using this guide: http://cocoawithlove.com/2008/09/streaming-and-playing-live-mp3-stream.html

I can record sound perfectly fine before i stream any mp3. only after i stream mp3 using the guide that my ios app can no longer record sound.

I was wondering if any of you might have run into this issue before or have any hunch of why this problem occur? I'll go ahead and post my code for recording, just in case any of you would need to look at it.

before i stream any mp3, audioRecorderDidFinishRecording always fire after a record has been done.

after i stream mp3, audioRecorderDidFinishRecording never fire after a record has been done.

Thank you in advance for your help.

    // #########################
    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]);
      }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

十级心震 2024-12-15 01:59:13

尝试此

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

参考iPhone SDK:AVAudioRecorder在通话后不会录音[AVPlayer播放]

Try this

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文