Record Streaming Audio from currently playing video in AVPlayer

核能气质少年 提交于 2020-01-01 18:55:11

问题


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:


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?



来源:https://stackoverflow.com/questions/28109516/record-streaming-audio-from-currently-playing-video-in-avplayer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!