视频 iOS 11/xcode 9 [英] video iOS 11/ xcode 9
问题描述
我使用此代码启动视频(非全屏).人们可以按'全屏'按钮切换到全屏.但是,在 iOS 11 测试版中,视频在全屏模式下变黑,我无法将其反转或再次播放.
I use this code to start a video (not full screen). People can press the 'full screen' button to switch to full screen. However in iOS 11 beta the video turns black in full screen and I can't reverse it or get it playing again.
是否有简单的修复方法可以更新我的 iOS 11 代码?或者有谁知道在哪里可以找到这个样本.我搜索了,但还没有找到任何东西.非常感谢,梅格
Is there an easy fix to update my code for iOS 11? Or does anyone know where to find a sample for this. I searched, but didn't find anything yet. Thanks a lot, Meg
-(void)viewDidLoad {
[super viewDidLoad];
// grab a local URL to our video
NSURL *videoURL = [[NSBundle mainBundle]URLForResource:@"pres 2" withExtension:@"m4v"];
// create an AVPlayer
AVPlayer *player = [AVPlayer playerWithURL:videoURL];
// create a player view controller
self.controller = [[AVPlayerViewController alloc]init];
controller.player = player;
[player play];
// show the view controller
[self addChildViewController:controller];
[self.view addSubview:controller.view];
controller.view.frame = CGRectMake(0,25, 750, 422);
}
-(void)playerItemDidReachEnd:(NSNotification *) notification{
//remove the player
}
-(void) viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
[controller.player replaceCurrentItemWithPlayerItem:nil];
}
-(void) viewDidDisappear:(BOOL)animated{
[super viewDidDisappear:animated];
[controller.player replaceCurrentItemWithPlayerItem:nil];
}
推荐答案
@Oliver Hu奥利弗,从苹果那里得到了一个非常友好的回答.它不是错误,而是代码中缺少的一行.前面提到的调用 Allen 也应该添加到 viewdidload 中!这是苹果的回答:
@Oliver Hu Hi Oliver, got a very kind answer from Apple. Its not a bug, but a missing line in the code. Also the call Allen mentioned earlier should be added to the viewdidload! Here is Apple's answer:
如果您需要在视图控制器被解除但未释放时拆卸,您应该将调用包装在 -[UIViewController isBeingDismissed] 中,如下所示:
if you need to teardown when the view controller is dismissed but not deallocated, you should wrap the calls in -[UIViewController isBeingDismissed], like so:
-(void) viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
if ([self isBeingDismissed])
{
[controller.player replaceCurrentItemWithPlayerItem:nil];
}
}
-(void) viewDidDisappear:(BOOL)animated{
[super viewDidDisappear:animated];
if ([self isBeingDismissed])
{
[controller.player replaceCurrentItemWithPlayerItem:nil];
}
}
你也应该在嵌入时调用 [controller didMoveToParentViewController:self]
.
Also you should call [controller didMoveToParentViewController:self]
when embedding it.
这篇关于视频 iOS 11/xcode 9的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!