问题描述
我正在尝试在我的视图启动时显示视频。但是我一直让应用程序试图在目标(我的视图控制器)上呈现一个 nil 模态视图控制器。
这是我的代码。
@property (nonatomic,retain) AVPlayerViewController *moviePlayer;
-(void) viewWillAppear:(BOOL)animated{
NSString *documentsDirectory31 = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES) objectAtIndex:0];
NSString *documentaryDirectory23 = [documentsDirectory31 stringByAppendingPathComponent:@"ChildOne.txt"];
if([[NSFileManager defaultManager] fileExistsAtPath: documentaryDirectory23]) {
self.user.text =[NSString stringWithContentsOfFile:documentaryDirectory23 encoding:NSUTF8StringEncoding error:NULL];
}
self.sharingtext.hidden = YES;
AVAudioSession *session = [AVAudioSession sharedInstance];
[session setCategory:AVAudioSessionCategoryPlayback error:nil];
[session setActive:YES error:nil];
NSString *audioName = [myDictionary objectForKey:@"photoVideokey"];
NSArray *pathsa = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,YES);
NSString *documentsDirectorya = [pathsa objectAtIndex:0];
NSString *slash = [documentsDirectorya stringByAppendingPathComponent:@"/"];
NSString *documentsDirectory1 = [slash stringByAppendingPathComponent:self.user.text];
//Get a full path to the image in the documents directory.
NSString *fullPath = [documentsDirectory1 stringByAppendingPathComponent:@"/Movie"];
NSString *fullPatha = [fullPath stringByAppendingPathComponent:audioName];
url = [NSURL fileURLWithPath:fullPatha];
NSLog(@"fullPatha:%@",fullPatha);
NSData *videoData = [[NSData alloc] initWithContentsOfURL:url];
AVPlayerItem* playerItem = [AVPlayerItem playerItemWithURL:url];
AVPlayer* playVideo = [[AVPlayer alloc] initWithPlayerItem:playerItem];
self.sharingImage = [UIImage imageWithData:videoData];
//AVPlayerViewController *playerViewController = [AVPlayerViewController new];
// frame must match parent view
[self.view insertSubview: [moviePlayer view]atIndex:4];
if([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone){
if([UIScreen mainScreen].bounds.size.height == 568.0){
moviePlayer.view.frame = CGRectMake(0,320,568);
}
else if([UIScreen mainScreen].bounds.size.height == 667.0){
moviePlayer.view.frame = CGRectMake(0,375,667);
}
else if([UIScreen mainScreen].bounds.size.height == 736.0){
moviePlayer.view.frame = CGRectMake(0,414,736);
}
else if([UIScreen mainScreen].bounds.size.height == 812.0){
//11pro76*1.17,3*1.69 OK!
NSLog(@"THIS IS BEING CALLED 11 pro/12mini/SE2");
moviePlayer.view.frame = CGRectMake(0,self.view.frame.size.width,self.view.frame.size.height);
}
else if([UIScreen mainScreen].bounds.size.height == 896.0){
NSLog(@"THIS IS BEING CALLED 11");
//1176*1.29,3*1.867 OK!
moviePlayer.view.frame = CGRectMake(0,self.view.frame.size.height);
}
else if([UIScreen mainScreen].bounds.size.height == 844.0){
NSLog(@"THIS IS BEING CALLED 12/pro");
//1176*1.29,self.view.frame.size.height);
}
else if([UIScreen mainScreen].bounds.size.height == 926.0){
NSLog(@"THIS IS BEING CALLED 12PROMAX");
//1176*1.29,self.view.frame.size.height);
}
else {
[[moviePlayer view] setFrame:[self.view bounds]];
}
}
moviePlayer.player = playVideo;
[self presentViewController:moviePlayer animated:YES completion:^{
[self->moviePlayer.player play];
}];
}
我知道该文件存在于路径中,因为当我拍摄并保存它时,我可以将其共享到 iMovie。
我不确定为什么模态视图为零。
谁能帮帮我。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)