ios – 如何拦截AVPlayerViewController中的完成按钮?

ios – 如何拦截AVPlayerViewController中的完成按钮?,第1张

概述我创建一个AVPlayerViewController&在自定义UIViewController的viewDidAppear方法中附加的AVPlayer,但是当我按完成按钮时,我的自定义视图控制器将自动关闭. 我想拦截这个动作,以便我自己解开Segue,但我不知道该怎么做?我找到了MPMoviePlayerViewController但不是AVPlayerViewController .. 我找到 我创建一个AVPlayerVIEwController&在自定义UIVIEwController的vIEwDIDAppear方法中附加的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 choiceplayerVC.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 finishedNSNumber *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开发人员技术支持(DTS).我们的工程师已经审查了您的请求,并得出结论,鉴于目前的运输系统配置,没有任何支持的方式来实现所需的功能.

解决方法 我对AVPlayerVIEwController进行子类化,并从vIEwWilldisappear发布通知,以指示关闭AVPlayerVIEwController.
- (voID) vIEwWilldisappear:(BOol)animated {    [[NSNotificationCenter defaultCenter] postNotificationname:kPlayerVIEwdismissednotification object:nil];    [super vIEwWilldisappear:animated];}

这可能不是100%正确的(因为它会失败,如果你有另一个视图显示在AVPlayerVIEwController),但它为我工作,因为AVPlayerVIEwController总是在堆栈的顶部.

总结

以上是内存溢出为你收集整理的ios – 如何拦截AVPlayerViewController中的完成按钮?全部内容,希望文章能够帮你解决ios – 如何拦截AVPlayerViewController中的完成按钮?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1110747.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存