使用 AVAudioRecorder 在后台录制语音(当我点击主页按钮时) [英] Record voice in background(when i tapped home button) using AVAudioRecorder

查看:53
本文介绍了使用 AVAudioRecorder 在后台录制语音(当我点击主页按钮时)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 IOS 开发的新手.我正在尝试使用 AVAudioRecorder 在后台录制用户语音,但我向 UIBackgroundModes 添加了音频",但这无济于事.顺便说一句,一切都在前台工作完美.在后台时,计时器工作正常,但没有录制声音.我如何从背景中的麦克风录音?这可能吗?

I'm new in IOS development.I'm trying to record user voice in background using AVAudioRecorder but I add "audio" to UIBackgroundModes but this don't help. By the way, Everything works perfect in foreground.When in the background the timer works fine but voice is not recording. How can i record from microphone from background ? Is this possible?

推荐答案

可以.Skype 做到了这一点.

You can. Skype does this.

你大概需要在Info.plist中设置UIBackgroundModesaudio,你需要在您切换应用程序之前确保音频会话处于活动状态/正在运行/无论什么情况(假设您不会突然开始录制/播放音乐/当您的应用程序处于后台时).

You presumably need to set <key>UIBackgroundModes</key><array><string>audio</string></array> in Info.plist, and you need to make sure that the audio session is active/running/whatever before you switch apps (the assumption is that you won't suddenly start recording/playing music/whatever when your app is in the background).

文档说音频"可以让您在后台播放音频,但大概这也适用于录制音频.如果它不起作用,您可以尝试以下几种方法:

The docs say that "audio" lets you play audio in the background, but presumably this also applies to recording audio. If it doesn't work, there are a few things you could try:

  • 同时设置voip"和audio".
  • 播放静音(这可能是使用 Audio Queue API 最容易做到的).

此材料来自此处:用于录音应用程序的 iOS 多任务处理

额外资料见:只要我按下HOME"按钮,他的录音就会停止构建背景感知应用程序

这篇关于使用 AVAudioRecorder 在后台录制语音(当我点击主页按钮时)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆