【问题标题】:Volume too low on iPhone when playing back the recorded file播放录制文件时 iPhone 上的音量太低
【发布时间】:2011-07-04 05:38:13
【问题描述】:

我正在开发一个 iOS 应用程序,我应该能够在其中录制声音,将其保存到文件系统,然后从磁盘播放。当我尝试从磁盘播放文件时,我几乎听不到任何声音。音量太低。但我很确定我会将设备音量设置为最大。我正在使用AVAudioRecorder 和 AVAudioPlayer` 进行录制和播放。

有人可以指出可能是什么问题吗?

【问题讨论】:

    标签: iphone avaudioplayer avaudiorecorder


    【解决方案1】:

    对于大多数情况,这里的解决方案可能是使用带有AVAudioSessionCategoryPlayAndRecord 类别的 .defaultToSpeaker 选项:

    try audioSession.setCategory(AVAudioSessionCategoryPlayAndRecord, with: [.defaultToSpeaker])
    

    但对我来说,问题是我的应用程序中的另一个组件在音频会话上设置了AVAudioSessionModeMeasurement 模式,无论出于何种原因,这都会降低输出音量。

    【讨论】:

    • swift 5:试试 AVAudioSession.sharedInstance().setCategory(.playAndRecord, mode: .default, options: [.allowBluetooth, .defaultToSpeaker])
    【解决方案2】:

    使用该方法设置AVAudioSession的类别

    AVAudioSession *session = [AVAudioSession sharedInstance];
    [session setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionDefaultToSpeaker error:nil];
    

    【讨论】:

      【解决方案3】:

      试试这个代码。我认为 setMode 解决了我的问题。

      NSError * outError = nil;
      AVAudioSession * session = [AVAudioSession sharedInstance];
      [session setActive:NO error:nil];
      [ session overrideOutputAudioPort: AVAudioSessionPortOverrideSpeaker error:&outError];
      [session setCategory:AVAudioSessionCategoryPlayback error:nil];
      [session setMode:AVAudioSessionModeSpokenAudio error:nil];
      [session setActive:YES error:nil];
      if(outError){
          NSLog(@"speak error %@", outError);
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-12-05
        • 2011-12-18
        • 2012-05-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多