【问题标题】:AVAudioSession record while playing weird issue播放奇怪问题时的 AVAudioSession 记录
【发布时间】:2014-06-18 02:05:46
【问题描述】:

对于我正在制作的应用程序的一部分,我需要录制来自用户的音频。我选择使用AVAudioRecorder 来执行此操作。

问题是当我开始录制音频时,设备上播放的所有音频都暂停了。然后我在 Apple 文档中查找 AVAudioSession 并将录制选项设置为:AVAudioSessionCategoryOptionMixWithOthers

问题是,每当我开始录制时,设备上播放的任何音频都会从主外部扬声器切换到小型电话(通话)扬声器。

我的目标是录制音频,同时仍允许设备中的所有其他音频通过主扬声器输出。

我怎样才能做到这一点?

这是我目前的代码:

AVAudioSession *audioSession = [AVAudioSession sharedInstance];
    [audioSession setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionMixWithOthers error:&error];
    [audioSession setActive:YES error:&error];

    recorder = [[AVAudioRecorder alloc] initWithURL:url settings:settings error:&error];

    if(recorder != nil){
        [recorder prepareToRecord];
        recorder.meteringEnabled = YES;
        [recorder record];
        levelTimer = [NSTimer scheduledTimerWithTimeInterval:0.03 target:self selector:@selector(levelTimerCallback:) userInfo:nil repeats:YES];
    }else{
        NSLog(@"Error: %@",[error description]);
    }//end if

谢谢!

【问题讨论】:

    标签: ios iphone audio avaudiorecorder avaudiosession


    【解决方案1】:

    也许您可以尝试使用AVAudioSessionCategoryOptionDefaultToSpeaker。根据AVAudioSession参考:

    当使用此选项并且没有其他可用的音频路由(例如耳机)时,会话音频将通过设备的内置扬声器播放。如果不使用此选项,并且没有其他可用的音频输出可用或未选择,音频将通过接收器(旨在贴在耳朵上的扬声器)播放。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-09-05
      • 1970-01-01
      • 1970-01-01
      • 2011-05-09
      • 2013-01-05
      • 1970-01-01
      • 1970-01-01
      • 2012-05-31
      相关资源
      最近更新 更多