我有一个应用视频的应用,然后显示预览。
拍摄视频并发送到预览的代码部分如下:
if(!self.camera.isRecording) {
self.segmentedControl.hidden = YES;
self.flashButton.hidden = YES;
self.switchButton.hidden = YES;
self.snapButton.layer.borderColor = [UIColor redColor].CGColor;
self.snapButton.backgroundColor = [[UIColor redColor] colorWithAlphaComponent:0.5];
// start recording
NSURL *outputURL = [[[self applicationDocumentsDirectory]
URLByAppendingPathComponent:@"test1"] URLByAppendingPathExtension:@"mov"];
[self.camera startRecordingWithOutputUrl:outputURL];
}
else {
self.segmentedControl.hidden = NO;
self.flashButton.hidden = NO;
self.switchButton.hidden = NO;
self.snapButton.layer.borderColor = [UIColor whiteColor].CGColor;
self.snapButton.backgroundColor = [[UIColor whiteColor] colorWithAlphaComponent:0.5];
[self.camera stopRecording:^(LLSimpleCamera *camera, NSURL *outputFileUrl, NSError *error) {
VideoViewController *vc = [[VideoViewController alloc] initWithVideoUrl:outputFileUrl];
[self.navigationController pushViewController:vc animated:YES];
}];
}
然后,视频被发送到名为VideoViewController的活动:
@import AVFoundation;
@interface VideoViewController ()
@property (strong, nonatomic) NSURL *videoUrl;
@property (strong, nonatomic) AVPlayer *avPlayer;
@property (strong, nonatomic) AVPlayerLayer *avPlayerLayer;
@property (strong, nonatomic) UIButton *cancelButton;
@property (strong, nonatomic) UIButton *sendButton;
@end
@implementation VideoViewController
-(instancetype)initWithVideoUrl:(NSURL *)url {
self = [super init];
if(self) {
_videoUrl = url;
}
return self;
}
-(void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
// the video player
self.avPlayer = [AVPlayer playerWithURL:self.videoUrl];
self.avPlayer.actionAtItemEnd = AVPlayerActionAtItemEndNone;
self.avPlayerLayer = [AVPlayerLayer playerLayerWithPlayer:self.avPlayer];
//self.avPlayerLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(playerItemDidReachEnd:)
name:AVPlayerItemDidPlayToEndTimeNotification
object:[self.avPlayer currentItem]];
CGRect screenRect = [[UIScreen mainScreen] bounds];
self.avPlayerLayer.frame = CGRectMake(0, 0, screenRect.size.width, screenRect.size.height);
[self.view.layer addSublayer:self.avPlayerLayer];
根据xcode,错误在self.avPlayer = [AVPlayer playerWithURL:self.videoUrl];
部分。当我构建项目时出现self VideoViewController * 0x146b91d0
我该怎么办才能解决这个错误?