Done button click event in AVPlayerViewController

前端 未结 9 863
广开言路
广开言路 2020-12-03 17:40

I want to play local video in AVPlayerViewController but did not find click event of Done button.

My video is able to play in AVPlayerViewController but I did not fi

9条回答
  •  Happy的楠姐
    2020-12-03 17:59

    Objective c version: (Based on vmchar answer)

    - (void)viewDidLoad
    {
        [super viewDidLoad];
            NSURL *url = [NSURL fileURLWithPath:path];
            AVPlayer *player = [AVPlayer playerWithURL:url];
            AVPlayerViewController *AVPlayerVc = [[AVPlayerViewController alloc] init];
            if (AVPlayerVc) {
                [self presentViewController:AVPlayerVc animated:YES completion:^{
                    [player play];
                    AVPlayerVc.player = player;
                    [AVPlayerVc addObserver:self forKeyPath:@"view.frame" options:(NSKeyValueObservingOptionNew | NSKeyValueObservingOptionInitial) context:nil];
                }];
    
            }
    }
    
    - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
        if ([keyPath isEqualToString:@"view.frame"]) {
            CGRect newValue = [change[NSKeyValueChangeNewKey]CGRectValue];
            CGFloat y = newValue.origin.y;
            if (y != 0) {
                  NSLog(@"Video Closed");
            }
         }
    }
    

提交回复
热议问题