在iOS上录制音频而不停止音乐播放 [英] Recording Audio on iOS Without Stopping Music Playback

查看:993
本文介绍了在iOS上录制音频而不停止音乐播放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 AVAudioSession 录制音频时,音乐应用程序或其他人的音频播放将停止。音频会话文档中对此进行了描述:

When recording audio with an AVAudioSession audio playback from the music app or others is stopped. This is described in the audio session documentation:


AVAudioSessionCategoryRecord

用于录制音频;此类别使播放音频静音。

For recording audio; this category silences playback audio.

有没有办法更改此行为并执行以下操作之一?

Is there any way to change this behavior and do one of the following?

1)继续播放其他应用的音频并允许手机录制正在播放的音频。

1) Continue playing other apps' audio and allow the phone to record the audio that is being played.

2)恢复其他应用'简短录音完成后的音频。当音频中断开始或结束时,应用程序可以响应通知。是否有一些特定的东西必须为其他应用程序接收这些通知?

2) Resume other apps' audio once a brief recording is finished. There are notifications apps can respond to when audio interruptions begin or end. Is there something specific that must be done for other apps to receive these notifications?

推荐答案

从24小时的勤奋搜索和零碎的东西在一起,这非常简单:

from 24 hours of diligent searching and piecemealing things together, this is surprisingly simple:

let session = AVAudioSession.sharedInstance()
session.setCategory(AVAudioSessionCategoryPlayAndRecord, with: [.mixWithOthers, .allowBluetoothA2DP])

对于仍在搜索如何执行此操作的人来说,这就是它。

And that's it for anyone still searching how to do this.

这篇关于在iOS上录制音频而不停止音乐播放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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