1

enter image description hereHow to Add activity indicator in the center of AVPLayerViewController when it is in fullscreen mode?

Community
  • 1
  • 1

2 Answers2

1

You can add your custom indicator view in centre of AVPLayerViewController by adding custom view on main key window.

UIApplication.shared.keyWindow?.addSubview(your custom indicator view)

You can set centre of your custom indicator view as below.

activity.center = CGPoint.init(x: UIScreen.main.bounds.size.width/2.0, y: UIScreen.main.bounds.height/2.0)
Abhijit
  • 173
  • 1
  • 7
  • Brother I want indicator on center of AVplayerviewController when AVplayerviewController is in full screen mode – Wasim Makwana Dec 29 '17 at 12:15
  • ok. can you please share screen shot so it's for me to find out how do you want it? – Abhijit Jan 01 '18 at 04:55
  • Ok brother I had added sc can you please refer it – Wasim Makwana Jan 02 '18 at 05:55
  • Thanks for screen shot. It seems your build target is less than iOS 8. Can you please paste your code to play this video? Also can you please tell on which version of iOS you are playing this video? – Abhijit Jan 02 '18 at 09:02
  • I am running video in IOS 10. At time when screen is in fullscreen mode at that time i want to just display activity indicator in centre of the fullscreen. Thanks in advance. – Wasim Makwana Jan 03 '18 at 09:04
  • Your code is working but when video is not in full screen at that time also indicator is displaying.Here we doesn't have fullscreen button action event as it is default. – Wasim Makwana Jan 04 '18 at 07:44
  • Can you tell me that how can i get the front view in AVPlayervViewController? As because i want to add activity indicator in that view. Thanks in advance. – Wasim Makwana Jan 04 '18 at 10:07
  • Anything you add on main key window will get added on top layer. – Abhijit Jan 04 '18 at 12:47
0

add this code when user press play button

if(playerViewController.view.subviews.count != 0)
{
  UIView *AVTouchIgnoringView = playerViewController.view.subviews[0].subviews.lastObject;
  activityIndicatorBuffer.center = playerViewController.view.center;
  [AVTouchIgnoringView addSubview:activityIndicatorView];
  [AVTouchIgnoringView bringSubviewToFront:activityIndicatorView];
}

and Don't forget to add below methods

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [playerViewController addObserver:self forKeyPath:@"videoBounds" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld context:nil];
}
-(void)viewDidDisappear:(BOOL)animated
{
     [super viewDidDisappear:animated];
     [playerViewController removeObserver:self forKeyPath:@"videoBounds"];
}
-(void)observeValueForKeyPath:(NSString )keyPath ofObject:(id)object change:(NSDictionary )change context:(void *)context
{
     if ([keyPath isEqualToString:@"videoBounds"])
     {
        float height = playerViewController.contentOverlayView.bounds.size.height;
        float width = playerViewController.contentOverlayView.bounds.size.width;
        if (height == SCREEN_HEIGHT && width == SCREEN_WIDTH)
        {
            activityIndicatorBuffer.center = playerViewController.contentOverlayView.center;
        }
        else
        {
            activityIndicatorBuffer.center = playerViewController.view.center;    
        }
     }
}

and don't forget to start animating when buffering. click here this link for check AVPlayer is buffering

Som Nai
  • 91
  • 1
  • 6