iOS同时录制视频和播放MP3
我需要从 iPhone 摄像头录制视频,并同时播放 MP3 文件。
我从 AVCam 示例代码开始,我相信你们都有。它非常适合录制视频。
不过,我随后添加了以下代码来播放 MP3。这个 MP3 播放代码在我的另一个应用程序中工作,但是当我将其插入到此示例代码中时,MP3 不仅无法播放,而且 AVCamCaptureManager 的 reportingDidFinishToOutputFileURL 永远不会被调用,因此视频永远不会被保存。
就像音频播放代码与视频捕获代码冲突一样。有什么想法吗?
这是我放入 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];
这里的代码非常简单。不知道为什么这个音频播放代码会导致recordingDidFinishToOutputFileURL永远不会被调用...
感谢您的任何想法。
I need to record video from the iPhone camera, and play an MP3 file at the same time.
I started with AVCam sample code, which I'm sure you all have. It works great for recording video.
However, I then added the following code to play an MP3. This MP3-playing code works in a different app of mine, but when I insert it into this sample code the MP3 not only does not play, the AVCamCaptureManager's recordingDidFinishToOutputFileURL never gets called, so the video never gets saved out.
It's like the audio playing code conflicts with the video capture code. Any ideas?
Here's the audio playing code I put into 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 audio playing code causes recordingDidFinishToOutputFileURL to never get called...
Thanks for any ideas.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想通了:我只需删除 AVCam 中分配 AVCaptureDeviceInput - audioInput 的一些代码即可。这是不必要的,并且与我的音频播放代码相冲突。
I figured it out: I just had to remove some code within AVCam that allocated AVCaptureDeviceInput - audioInput. That was unnecessary and conflicted with my audio playback code.