4

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?

Oren
  • 5,055
  • 3
  • 34
  • 52

2 Answers2

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.

Rhythmic Fistman
  • 34,352
  • 5
  • 87
  • 159
  • That's what I've been thinking I needed to do but was hoping I wouldn't have to go down the road of working with such low-level frameworks. I found this article (http://venodesigns.net/2014/01/08/recording-live-audio-streams-on-ios/) which seems to do exactly what I want but I know I'll run into major issues so was hoping there would be an easier option. – Oren Oct 08 '15 at 05:46
  • Check out matt's answer above, it should be much easier, if you don't mind discarding `AVPlayer` – Rhythmic Fistman Oct 08 '15 at 05:47
  • Should AVAudioFile work with files hosted on the web? (i commented to Matt'a answer...see below) – Oren Oct 08 '15 at 18:59
0

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

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • See https://github.com/mattneub/Programming-iOS-Book-Examples/blob/master/bk2ch14p655AVAudioEngineTest/AVAudioEngineTest/ViewController.swift for an example. – matt Oct 08 '15 at 02:04
  • Am I able to use AVAudioEngine if the file isn't embedded? Whenever I try to create an `AVAudioFile` from an mp3 online it crashes instantly. I found this but no answers: http://stackoverflow.com/questions/30862664/stream-data-from-network-in-avaudioengine-is-it-possible – Oren Oct 08 '15 at 18:58
  • Sorry, missed that in your question. I doubt you can do it; you'll have to resort to your other options...! – matt Oct 08 '15 at 19:17