您首先设置AVAudioSession
及其类别。例如在viewDidLoad
方法中,
AVAudioSession *session = [AVAudioSession sharedInstance];
[session setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionMixWithOthers|AVAudioSessionCategoryOptionDefaultToSpeaker error:nil];
因此,您可以播放 BGM
self.player = [[AVAudioPlayer alloc] initWithContentsOfURL:music_url error:nil];
[self.player setDelegate:self];
[self.player play];
并录制电影
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];