Record Audio/Video with AVCaptureSession and Playback Audio simultaneously?

给你一囗甜甜゛ 提交于 2019-12-03 03:55:54

You first set the AVAudioSession and its category. For example in viewDidLoad method,

AVAudioSession *session = [AVAudioSession sharedInstance];
[session setCategory:AVAudioSessionCategoryPlayAndRecord  withOptions:AVAudioSessionCategoryOptionMixWithOthers|AVAudioSessionCategoryOptionDefaultToSpeaker error:nil];

Therefore you can play BGM

    self.player = [[AVAudioPlayer alloc] initWithContentsOfURL:music_url error:nil];
    [self.player setDelegate:self];
    [self.player play];

and record the movie

    self.captureSession = [[AVCaptureSession alloc] init];
    /* ... addInput AVCaptureDeviceInput AVMediaTypeVideo & AVMediaTypeAudio */
    /* ... addOutput */
    [self.captureSession startRunning];
    AVCaptureMovieFileOutput *m_captureFileOutput =[self.captureSession.outputs objectAtIndex:0];
    [m_captureFileOutput startRecordingToOutputFileURL:saveMovieURL recordingDelegate:self];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!