【问题标题】:AVAudioRecorder hasn't soundAVAudioRecorder 没有声音
【发布时间】:2016-02-01 08:41:26
【问题描述】:

我在某些情况中遇到AVAudioPlayer 的问题。 首先,我的录音机工作正常。但是在 VOIP 通话并从built_in_Speaker 播放铃声并与音频会话一起工作后,挂断电话后,我无法先录制带声音的音频!但第二次一切正常。 问题

在我提到我的音频已录制但没有声音的情况下!

我想知道在什么情况下可能会发生?

 self.audioSession = [AVAudioSession sharedInstance];
NSError *err = nil;
[self.audioSession setCategory :AVAudioSessionCategoryPlayAndRecord error:&err];
if(err){
    NSLog(@"audioSession: %@ %d %@", [err domain], [err code], [[err userInfo] description]);
    return;
}

BOOL preparedToRecord = [self.audioRecorder prepareToRecord];
__block BOOL recordStarted = NO;

err = nil;
[self.audioSession setActive:YES error:&err];
if(err){
    NSLog(@"audioSession: %@ %d %@", [err domain], [err code], [[err userInfo] description]);
    return;
}

if (preparedToRecord){
    recordStarted = [self.audioRecorder record];
}

【问题讨论】:

    标签: ios objective-c avaudiorecorder avaudiosession


    【解决方案1】:

    已解决

    我找到了这个问题的原因。 我有 addObserve 我自己来捕捉 AVAudioSession 的通知,并检查AudioSession 中断/RoutChanging! 问题是在我打电话后我尝试将音频路由更改为扬声器,但是为 AudioRoutChanging 通知添加观察的类试图阻止这种情况。所以音频会话路由每秒都在变化,无法录制音频。

    结论 你应该这样做来录制音频:

    1) 确定权限

    2)[self.audioSession setActive:YES error:&err];
    
    3)[self.audioSession setCategory :AVAudioSessionCategoryPlayAndRecord error:&err];
    

    4) 确定您的路线在录制过程中不要改变。

    4)确定你的目标补丁

    【讨论】:

      【解决方案2】:

      录音音频需要来自用户的明确权限。第一次同时使用一个类别,使记录您的应用程序的音频会话尝试使用音频输入路线,系统会自动提示用户授予权限。你可以明确地问早些时候通过调用requestRecordPermission:方法。直到用户授予您的应用程序权限的记录,您的应用程序可以记录只有沉默。 P>

      这里指: https://developer.apple.com/library/prerelease/ios/documentation/AVFoundation/Reference/AVAudioSession_ClassReference/index.html

      【讨论】:

      • 我已经得到许可,首家推出应用程序,和我提到我在调用中使用的音频会话,它工作正常!我解决我很快就在这里说明了问题。 TNX您的回复! SPAN>
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-08-21
      • 1970-01-01
      • 2012-11-24
      • 2011-08-04
      • 1970-01-01
      • 2017-03-16
      • 2017-10-19
      相关资源
      最近更新 更多