IOS records video and plays MP3 at the same time

I need to record video from an iPhone camera and play an MP3 file at the same time.

I started with the AVCam sample code, which I'm sure you all have. It works great for recording videos.

However, I added the following code to play MP3s. This MP3 code works in another application, but when I paste it into this sample code, the MP3 not only does not play, the AVCamCaptureManagerDidFinishToOutputFileURL record is never called, so the video will never be saved.

This is similar to a conflicting audio playback code with a video capture code. Any ideas?

Here is the sound code that I entered in AVCam:

AVAudioPlayer *audioPlayer = nil; NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/soundeffect.mp3", [[NSBundle mainBundle] resourcePath]]]; audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error]; [audioPlayer setVolume:1.0]; [audioPlayer prepareToPlay]; [m_audioPlayer play]; 

Pretty simple code here. Not sure why this sound code causes a DidFinishToOutputFileURL entry to never be called ...

Thanks for any ideas.

+4
source share
1 answer

I realized: I just had to remove some code in AVCam that allocated AVCaptureDeviceInput - audioInput. This was redundant and contrary to my sound code.

+5
source

Source: https://habr.com/ru/post/1379311/


All Articles