Wasim Makwana
Wasim Makwana

Reputation: 55

Add activity indicator in AVPLayerViewController ? (Note: When video is in fullscreen mode)

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

Upvotes: 1

Views: 1031

Answers (2)

Som Nai
Som Nai

Reputation: 91

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

Upvotes: 0

Abhijit
Abhijit

Reputation: 173

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)

Upvotes: 1

Related Questions