Skip to content

Commit

Permalink
visibility notification
Browse files Browse the repository at this point in the history
  • Loading branch information
priore committed Jun 24, 2017
1 parent a172164 commit 5ea988c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion AVPlayerOverlay.podspec
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'AVPlayerOverlay'
s.version = '1.9'
s.version = '1.10'
s.summary = 'AVPlayer with custom controls and full screen features.'
s.license = 'MIT'
s.authors = { 'Danilo Priore' => 'support@prioregroup.com' }
Expand Down
1 change: 1 addition & 0 deletions AVPlayerOverlay/AVPlayer/AVPlayerVC.h
Expand Up @@ -5,6 +5,7 @@
// Copyright © 2016 Prioregroup.com. All rights reserved.
//
#define AVPlayerVCSetVideoURLNotification @"avplayervcsetvideourl"
#define AVPlayerVCVisibilityNotification @"avplayervcvisibility"
#define kAVPlayerVCSubtitleURL @"subtitles"

#import "AVPlayerOverlayVC.h"
Expand Down
20 changes: 20 additions & 0 deletions AVPlayerOverlay/AVPlayer/AVPlayerVC.m
Expand Up @@ -13,6 +13,8 @@

@interface AVPlayerVC ()

@property (nonatomic, strong) NSTimer *timerVisibility;

@end

@implementation AVPlayerVC
Expand Down Expand Up @@ -86,6 +88,22 @@ - (void)viewDidLoad
[_overlayVC addTarget:_pipOverlayVC action:@selector(showControls) forEvents:AVPlayerOverlayEventDidPIPBecomeActive];
[_overlayVC addTarget:_pipOverlayVC action:@selector(hideControls) forEvents:AVPlayerOverlayEventWillPIPDeactivation];
}

// visibility notification
_timerVisibility = [NSTimer timerWithTimeInterval:0.5 repeats:YES block:^(NSTimer * _Nonnull timer) {
static BOOL visibility = NO;
CGRect rect = [self.view.window convertRect:self.view.frame fromView:self.view];
if (rect.size.width > 0 && rect.size.height > 0) {
if (CGRectContainsRect(self.view.window.frame, rect) && !visibility) {
visibility = YES;
[[NSNotificationCenter defaultCenter] postNotificationName:AVPlayerVCVisibilityNotification object:@(YES)];
} else if (!CGRectContainsRect(self.view.window.frame, rect) && visibility) {
visibility = NO;
[[NSNotificationCenter defaultCenter] postNotificationName:AVPlayerVCVisibilityNotification object:@(NO)];
}
}
}];
[[NSRunLoop currentRunLoop] addTimer:_timerVisibility forMode:NSRunLoopCommonModes];
}

- (void)viewDidAppear:(BOOL)animated
Expand Down Expand Up @@ -191,6 +209,8 @@ - (void)dealloc
[_overlayVC removeFromParentViewController], _overlayVC = nil;
[_pipOverlayVC removeFromParentViewController], _pipOverlayVC = nil;

[_timerVisibility invalidate], _timerVisibility = nil;

[self.player pause], self.player = nil;
}

Expand Down

0 comments on commit 5ea988c

Please sign in to comment.