【发布时间】:2015-04-24 15:30:56
【问题描述】:
我在自定义UIViewController 的viewDidAppear 方法中创建了AVPlayerViewController 和附加的AVPlayer。但是,当我按下“完成”按钮时,我的自定义视图控制器会自动关闭。
我想拦截此操作以使用我自己的展开 Segue,但我不知道如何执行此操作。我找到了MPMoviePlayerViewController 的示例,但没有找到AVPlayerViewController。
我为MPMoviePlayerViewController 找到的代码如下:
- (void)playVideo:(NSString *)aVideoUrl {
// Initialize the movie player view controller with a video URL string
MPMoviePlayerViewController *playerVC = [[[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:aVideoUrl]] autorelease];
// Remove the movie player view controller from the "playback did finish" notification observers
[[NSNotificationCenter defaultCenter] removeObserver:playerVC
name:MPMoviePlayerPlaybackDidFinishNotification
object:playerVC.moviePlayer];
// Register this class as an observer instead
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(movieFinishedCallback:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:playerVC.moviePlayer];
// Set the modal transition style of your choice
playerVC.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
// Present the movie player view controller
[self presentModalViewController:playerVC animated:YES];
// Start playback
[playerVC.moviePlayer prepareToPlay];
[playerVC.moviePlayer play];
}
- (void)movieFinishedCallback:(NSNotification *)aNotification {
// Obtain the reason why the movie playback finished
NSNumber *finishReason = [[aNotification userInfo] objectForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey];
// Dismiss the view controller ONLY when the reason is not "playback ended"
if ([finishReason intValue] != MPMovieFinishReasonPlaybackEnded) {
MPMoviePlayerController *moviePlayer = [aNotification object];
// Remove this class from the observers
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];
// Dismiss the view controller
[self dismissModalViewControllerAnimated:YES];
}
}
我就这个问题向 Apple 询问过,他们的回答如下:
感谢您联系 Apple 开发者技术支持 (DTS)。我们的 工程师审查了您的请求并得出结论认为 鉴于没有支持的方式来实现所需的功能 目前正在发布系统配置。
【问题讨论】:
标签: ios objective-c ios8 xcode6