Skip to content

Commit

Permalink
Fix deallocations
Browse files Browse the repository at this point in the history
  • Loading branch information
priore committed May 19, 2016
1 parent 6ec1a9c commit c7632f7
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 30 deletions.
2 changes: 1 addition & 1 deletion AVPlayerOverlay.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'AVPlayerOverlay'
s.version = '1.3.0'
s.version = '1.3.1'
s.summary = 'AVPlayer with custom controls and full screen features.'
s.license = 'MIT'
s.ios.platform = '7.1'
Expand Down
18 changes: 11 additions & 7 deletions AVPlayerOverlay/AVPlayer/AVPlayerOverlayVC.m
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,18 @@ - (void)viewDidLoad

- (void)dealloc
{
_volume = nil;
[NSObject cancelPreviousPerformRequestsWithTarget:self];

if (_timeObserver)
[_player removeTimeObserver:_timeObserver];
_timeObserver = nil;


_volume = nil;
_player = nil;

[_window removeFromSuperview], _window = nil;
[_mainWindow makeKeyAndVisible];

}

- (void)setPlayer:(AVPlayer *)player
Expand All @@ -104,11 +108,11 @@ - (void)setPlayer:(AVPlayer *)player
} else {

__weak typeof(self) wself = self;
self.timeObserver = [self.player addPeriodicTimeObserverForInterval:CMTimeMakeWithSeconds(1.0 / 60.0, NSEC_PER_SEC)
queue:NULL
usingBlock:^(CMTime time){
[wself updateProgressBar];
}];
self.timeObserver = [_player addPeriodicTimeObserverForInterval:CMTimeMakeWithSeconds(1.0 / 60.0, NSEC_PER_SEC)
queue:NULL
usingBlock:^(CMTime time){
[wself updateProgressBar];
}];
_videoSlider.value = 0;
_volumeSlider.value = _player.volume;
}
Expand Down
58 changes: 36 additions & 22 deletions AVPlayerOverlay/AVPlayer/AVPlayerVC.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,30 +33,22 @@ - (void)viewDidLoad
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
[[AVAudioSession sharedInstance] setActive:YES error:nil];

[[NSNotificationCenter defaultCenter] addObserverForName:UIApplicationWillResignActiveNotification
object:nil
queue:NULL
usingBlock:^(NSNotification *note) {
[self playInBackground:YES];
}];

[[NSNotificationCenter defaultCenter] addObserverForName:UIApplicationWillEnterForegroundNotification
object:nil
queue:NULL
usingBlock:^(NSNotification *note) {
[self playInBackground:NO];
}];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(applicationWillResignActiveNotification:)
name:UIApplicationWillResignActiveNotification
object:nil];

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(applicationWillEnterForegroundNotification:)
name:UIApplicationWillEnterForegroundNotification
object:nil];
}

[[NSNotificationCenter defaultCenter] addObserverForName:AVPlayerVCSetVideoURLNotification
object:nil
queue:NULL
usingBlock:^(NSNotification *note) {
self.videoURL = note.object;
}];



[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(avPlayerVCSetVideoURLNotification:)
name:AVPlayerVCSetVideoURLNotification
object:nil];

_overlayVC = [self.storyboard instantiateViewControllerWithIdentifier:_overlayStoryboardId];

[self addChildViewController:_overlayVC];
Expand Down Expand Up @@ -135,6 +127,11 @@ - (void)remoteControlReceivedWithEvent:(UIEvent *)event
- (void)dealloc
{
_overlayVC = nil;

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

[NSObject cancelPreviousPerformRequestsWithTarget:self];
[[NSNotificationCenter defaultCenter] removeObserver:self];
}

#pragma mark - Video (only audio) on background
Expand All @@ -161,4 +158,21 @@ - (void)playInBackground:(BOOL)play
[self.player performSelector:@selector(play) withObject:nil afterDelay:1.0];
}

#pragma mark - Notifications

- (void)applicationWillResignActiveNotification:(NSNotification*)note
{
[self playInBackground:YES];
}

- (void)applicationWillEnterForegroundNotification:(NSNotification*)note
{
[self playInBackground:NO];
}

- (void)avPlayerVCSetVideoURLNotification:(NSNotification*)note
{
self.videoURL = note.object;
}

@end

0 comments on commit c7632f7

Please sign in to comment.