Record audio streamed from AVPlayer

2019-04-11 19:50发布

问题:

I'm trying to record/capture audio that's being streamed via an AVPlayer. The AVAudioRecorder only records from the microphone which may work if the audio is played via speakerphone (although quality will suffer) but it'll definitely not work if the headphones are plugged in.

I've looked everywhere for a solution but still haven't found a solution that'll work for me. Would I need to grab the audio buffer? Is there another way to capture what's being played?

回答1:

You can grab audio buffers by adding an MTAudioProcessingTap to your AVPlayer.

The process is a little convoluted, but there is some information out there.



回答2:

The easiest approach nowadays is to play and record using AVAudioEngine.