iPhone 开发 - AudioQueue 服务在后台录制
我已经构建了一个录音应用程序(例如苹果的“SpeakHere”演示),我想知道如何修改它以在背景上工作。
每次我进入后台时,AudioQueue 回调就会冻结,并且我没有收到任何音频字节。
我发现 iPhone 上的语音备忘录应用程序可以在后台录音。
这是我的回调,它在后台不起作用:
OSStatus AQRecorder::BufferFilled_callback(
void * inUserData,
SInt64 inPosition,
UInt32 requestCount,
const void * buffer,
UInt32 * actualCount) {
AQRecorder *aqr = (AQRecorder *)inUserData;
NSLog(@"THIS METHOD IS NOT CALLED ON BACKGROUND");
int fd = open(aqr->mWriteFile, O_WRONLY|O_CREAT|O_APPEND, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
if (fd) {
*actualCount = (int)write( fd, buffer, requestCount);
close(fd);
[aqr->mi setToread:[aqr->mi toread] + requestCount];
} else {
perror("Fopen");
}
return 0;
有什么想法吗?
I've built an audio recording app (like 'SpeakHere' demo from apple), and I was wondering how can I modify it to work on BACKGROUND.
Every time I enter background, the AudioQueue callback freezes, and I did not receive a single audio byte.
I've seen that the Voice Memos app on the iPhone can record in background.
Here is my callback that does not work in background:
OSStatus AQRecorder::BufferFilled_callback(
void * inUserData,
SInt64 inPosition,
UInt32 requestCount,
const void * buffer,
UInt32 * actualCount) {
AQRecorder *aqr = (AQRecorder *)inUserData;
NSLog(@"THIS METHOD IS NOT CALLED ON BACKGROUND");
int fd = open(aqr->mWriteFile, O_WRONLY|O_CREAT|O_APPEND, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
if (fd) {
*actualCount = (int)write( fd, buffer, requestCount);
close(fd);
[aqr->mi setToread:[aqr->mi toread] + requestCount];
} else {
perror("Fopen");
}
return 0;
Any thoughts?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否使用应用程序的 info.plist“所需后台模式”键下的适当值启用后台录制?
Did you enable background recording using the appropriate value under your app's info.plist "Required background modes" key?