我正在尝试构建一个可以从 URL 播放视频并同时使用前置摄像头录制视频的应用程序。我试过了,但是当相机开始拍摄时视频停止播放,反之亦然。请帮帮我。提前致谢!!这是我的代码,我正在使用 DIYCam(使用 AVFoundation)框架,它可以完美录制并使用 AVPlayer 进行播放
- (IBAction)startRecording:(id)sender {
self.cam = [[DIYCam alloc] initWithFrame:CGRectMake(0, 0, 320, 300)];
self.cam.layer.anchorPoint = CGPointMake(0.f, 0.f);
self.cam.frame = CGRectMake(0, 0, 320, 300);
self.cam.delegate = self;
[self.cam setupWithOptions:nil];
[self.cam setCamMode:DIYAVModeVideo];
self.cam.backgroundColor = [UIColor greenColor];
[self.cam captureVideoStart];
}
-(无效)播放视频{
NSURL *url = [[NSBundle mainBundle] URLForResource:@"responcevideo"
withExtension:@"mp4"
subdirectory:nil];
AVPlayer *_avPlayer;
_avPlayer = [AVPlayer playerWithURL:url] ;
AVPlayerLayer *_avPlayerLayer = [AVPlayerLayer playerLayerWithPlayer:_avPlayer];
_avPlayerLayer.frame = self.view.layer.bounds;
[self.view.layer addSublayer:_avPlayerLayer];
[_avPlayer play];
}