2
votes

Many similar questions but not Exactly the same.

I currently have my code setup to play video via an AVPlayer.

What I'm wanting to do is somehow extract the audio of the streaming video and eventually merge with the Mic Input (using AVAudioMixer?). (think Karaoke app) so when the user plays the recording it will play back the audio only from the video and the recording from the mic.

I think AVAudioEngine is the way to go but i cannot for the life of me work it out.

So my question is how do i extract or record the audio from the currently playing video in AVPlayer and importantly which is streaming with an online source (youtube).

Another way to ask the question could be as follows

I have a radio application and (think tuneIn Radio) and i want to record the streaming audio.

1
did you check all the classes from AV Foundation? I think they contain all functionality you want -> developer.apple.com/library/ios/documentation/AVFoundation/…thorb65
What kind of stream do you consume using the accepted method? And which of the two did you actually go for?Julian F. Weinert

1 Answers

3
votes

One source suggests you listen for audio routing changes when the AVPlayer and AVAudioRecorder are started at the same time. The idea is to use AudioSessionAddPropertyListener(...) and monitor kAudioSessionProperty_AudioRoute audio routes, then start the recording when you receive the AVPlayer route.

REF: Playing video with AVPlayer and recording sound with AVAudioRecorder simultaneously

Another solution is to use MTAudioProcessingTap (ref), set up a stream handler using KVObserving, and record your streaming video's audio channel.

REF: Recording Live Audio Streams on iOS

Another solution is to just start an audio session of category AVAudioSessionCategoryPlayAndRecord with a delegate, and initiate the audio recording after you have started playing the video.

REF: how can i record a song which is playing with AVPlayer and an wav file at a same time?