简体   繁体   中英

Recording audio and video after having played video with audio

I'm building an app in which I can record video with audio input.

It works well: I use AVCaptureSession with two AVCaptureDeviceInput , one for video, one for audio. I then record the movie with AVCaptureMovieFileOutput . Until now, no problem, my video gets recorded, and audio is present.

But I have a problem if I try to record this video with audio input after a video (with audio) has been played (with AVPlayer ). Indeed, the video gets recorded, but there is no audio!

Three things:

I have tried to put [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryRecord error:nil]; before recording, it doesn't change anything.

Any AVPlayer instance is paused before trying to record anything.

The AVPlayer instance, even if paused, is still present when I try to record (is it a problem?)

I would like to say that I have this problem on my iPhone 4, but the same app, compiled on my iPad Air, works like a charm (there is audio in my recording even after having played a video...). How is it even possible?

Fix:

Before taking video just

  [self.moviePlayer replaceCurrentItemWithPlayerItem:nil];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM