本地记录文件为空 [agora.io] Swift

Posted

技术标签:

【中文标题】本地记录文件为空 [agora.io] Swift【英文标题】:Local record file is empty [agora.io] Swift 【发布时间】:2021-09-08 18:34:12 【问题描述】:

我正在从 AgoraKit 的示例中创建一个音频调用应用程序,并且我正在尝试为其添加录音功能,但我遇到了问题。我的录音文件每次都是空的。 AgoraKit 创建了一个录音文件,但似乎无法填充数据。

func initializeAgoraEngine() 
    // Initializes the Agora engine with your app ID.
    agoraKit = AgoraRtcEngineKit.sharedEngine(withAppId: AppID, delegate: self)
    let documentsDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
    let audioURL = documentsDirectory.appendingPathComponent("agorasdk.log")

    agoraKit.setLogFile(audioURL.path)


func joinChannel() 
    // Allows a user to join a channel.
    agoraKit.joinChannel(byToken: Token, channelId: "demoChannel", info: nil, uid: nil)  [unowned self] (sid, uid, elapsed) -> Void in
        // Joined channel "demoChannel"
        self.agoraKit.setEnableSpeakerphone(true)
        UIApplication.shared.isIdleTimerDisabled = true

        let documentsDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
        let audioURL = documentsDirectory.appendingPathComponent("audio.aac")

        let config = AgoraAudioRecordingConfiguration()
        config.filePath = audioURL.path
        config.recordingQuality = .medium
        config.recordingPosition = .mixedRecordingAndPlayback //tried other options no luck
        config.recordingSampleRate = 16000//tried 32000 and 44100
        let result = agoraKit.startAudioRecording(withConfig: config) //result always 0 according to documentation that is success
    

毕竟我调用了 stopAudioRecording() 并且它也返回 0。所以根据文档,一切都很好,但是文件是空的。

【问题讨论】:

【参考方案1】:

我刚刚在本地尝试过,它对我来说没问题,这是我的设置,我使用的文档目录有点不同,但看不出为什么会改变任何东西:

AgoraRtcEngine_ios (3.5.0.3)

let documentsDirectory = try! FileManager.default.url(
  for: .documentDirectory,
  in: .userDomainMask, appropriateFor: nil,
  create: true
)
let baseDirectory = documentsDirectory.appendingPathComponent(
  "Audio/", isDirectory: true
)
try! FileManager.default.createDirectory(
  atPath: baseDirectory.path,
  withIntermediateDirectories: true
)
let audioURL = baseDirectory.appendingPathComponent(
  "test.aac", isDirectory: false
)

// start recording is the same as your settings

我还在 Info.plist 中添加了这些属性,以便文件浏览更容易:

【讨论】:

以上是关于本地记录文件为空 [agora.io] Swift的主要内容,如果未能解决你的问题,请参考以下文章

Agora.io 音频正常但视频不传输

Agora - 无法将视频 .ts 文件合并为一个视频文件

如何获得频道中所有用户的“静音”状态? [agora.io]

Agora.io 从 LiveStream 录制音频

错误:包 io.agora.rtm 不存在

在 Agora IO 中与参与者共享屏幕共享控件