Skip to content

Commit

Permalink
fix memory management
Browse files Browse the repository at this point in the history
  • Loading branch information
priore committed May 13, 2016
1 parent 6290e9b commit d48f0bf
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 17 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.2.5'
s.version = '1.2.6'
s.summary = 'AVPlayer with custom controls and full screen features.'
s.license = 'MIT'
s.ios.platform = '7.1'
Expand Down
7 changes: 6 additions & 1 deletion AVPlayerOverlay.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
9F16B0151CD40E340082CC15 /* TableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TableViewController.h; sourceTree = "<group>"; };
9F16B0161CD40E340082CC15 /* TableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = TableViewController.m; sourceTree = "<group>"; };
9F16B0181CD40EC10082CC15 /* Channels.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Channels.plist; sourceTree = "<group>"; };
9F72195E1CE60BDD00948B8B /* AVPlayerOverlay.podspec */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = AVPlayerOverlay.podspec; path = ../AVPlayerOverlay.podspec; sourceTree = "<group>"; };
9F72195F1CE60BDD00948B8B /* LICENSE */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = LICENSE; path = ../LICENSE; sourceTree = "<group>"; };
9F7219601CE60BDD00948B8B /* README.md */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = net.daringfireball.markdown; name = README.md; path = ../README.md; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -82,13 +85,15 @@
9F16AFFF1CD3E3980082CC15 /* Info.plist */,
9F16AFEE1CD3E3980082CC15 /* Supporting Files */,
);
name = AVPlayerOverlay;
path = AVPlayerOverlay;
sourceTree = "<group>";
};
9F16AFEE1CD3E3980082CC15 /* Supporting Files */ = {
isa = PBXGroup;
children = (
9F72195E1CE60BDD00948B8B /* AVPlayerOverlay.podspec */,
9F72195F1CE60BDD00948B8B /* LICENSE */,
9F7219601CE60BDD00948B8B /* README.md */,
9F16B0181CD40EC10082CC15 /* Channels.plist */,
9F16AFEF1CD3E3980082CC15 /* main.m */,
);
Expand Down
34 changes: 19 additions & 15 deletions AVPlayerOverlay/AVPlayer/AVPlayerOverlayVC.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@
@import MediaPlayer;

@interface AVPlayerOverlayVC ()
{
id timeObserver;
BOOL isVideoSliderMoving;
}

@property (nonatomic, weak) UIView *containerView;
@property (nonatomic, weak) UIWindow *mainWindow;
Expand All @@ -29,6 +25,9 @@ @interface AVPlayerOverlayVC ()
@property (nonatomic, strong) UIWindow *window;
@property (nonatomic, strong) MPVolumeView *volume;

@property (nonatomic, strong) id timeObserver;
@property (nonatomic, assign) BOOL isVideoSliderMoving;

@end

@implementation AVPlayerOverlayVC
Expand Down Expand Up @@ -80,6 +79,10 @@ - (void)dealloc
{
_volume = nil;

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

[_window removeFromSuperview], _window = nil;
[_mainWindow makeKeyAndVisible];
}
Expand All @@ -91,20 +94,21 @@ - (void)setPlayer:(AVPlayer *)player

if (_player == nil) {

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

_volumeSlider.value = 1.0;
_videoSlider.value = 0.0;

} else {

__weak typeof(self) wself = self;
timeObserver = [self.player addPeriodicTimeObserverForInterval:CMTimeMakeWithSeconds(1.0 / 60.0, NSEC_PER_SEC)
queue:NULL
usingBlock:^(CMTime time){
[wself updateProgressBar];
}];
self.timeObserver = [self.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 All @@ -122,7 +126,7 @@ - (void)setPlayer:(AVPlayer *)player
- (void)updateProgressBar
{
Float64 duration = CMTimeGetSeconds(_player.currentItem.duration);
if (!isVideoSliderMoving && !isnan(duration)) {
if (!_isVideoSliderMoving && !isnan(duration)) {
_videoSlider.maximumValue = duration;
_videoSlider.value = CMTimeGetSeconds(_player.currentTime);

Expand Down Expand Up @@ -370,19 +374,19 @@ - (void)didVideoSliderTouchUp:(id)sender
[_player seekToTime:seektime toleranceBefore:kCMTimeZero toleranceAfter:kCMTimeZero];
}

isVideoSliderMoving = NO;
_isVideoSliderMoving = NO;
[self autoHidePlayerBar];
}

- (void)didVideoSliderTouchDown:(id)sender
{
isVideoSliderMoving = YES;
_isVideoSliderMoving = YES;
[self autoHidePlayerBar];
}

- (void)videoSliderEnabled:(BOOL)enabled
{
if (!isVideoSliderMoving) {
if (!_isVideoSliderMoving) {
if (enabled && !_videoSlider.isUserInteractionEnabled) {
_videoSlider.userInteractionEnabled = YES;
[UIView animateWithDuration:0.25 animations:^{
Expand Down

0 comments on commit d48f0bf

Please sign in to comment.