我在UIViewController
的viewDidAppear
方法中创建了AVPlayerViewController
和附加的AVPlayer
。但是,当我按下“完成”按钮时,我的自定义视图控制器会自动解除。如何拦截在AVPlayerViewController中完成按钮的敲击?
我想拦截这个动作,以便使用我自己的放松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];
}
}
我要求苹果公司对这个问题,他们已经答复如下:
感谢您的苹果开发者技术支持联系(DTS )。我们的 工程师已审核您的请求,并得出结论认为 没有支持的方式来实现 当前的运输系统配置所需的功能。
当用户按下完成按钮时,我想继续在小屏幕上播放视频,所以我需要avplayer对象,我该怎么办? – 2015-08-19 12:23:37
当您按完成时,AVPlayerViewController将停止播放并释放AVPlayer。对于你所需要的,用AVPlayer创建你自己的ViewController,当用户按下完成时,调整视图的大小。 https://developer.apple.com/library/ios/samplecode/AVPlayerDemo/Introduction/Intro.html有一个创建自己的AVPlayerViewController的例子 – dev 2015-08-19 13:18:47
如果我不想子类化AVPlayerViewController(如Apple所示:不要子类AVPlayerViewController覆盖此类的方法不受支持,并导致未定义的行为 此处:https://developer.apple.com/library/prerelease/ios/documentation/AVFoundation/Reference/AVPlayerViewController_Class/index.html)有没有办法获得通知? – 2015-08-26 09:06:46