Skip to content

Commit

Permalink
[ASVideoNode] Time observer fix (TextureGroup#604)
Browse files Browse the repository at this point in the history
* [ASVideoNode] Move time observer handling to player observers methods.

* Update CHANGELOG.md.
  • Loading branch information
flovouin authored and bernieperez committed Apr 25, 2018
1 parent 23f224e commit 72f31de
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## master

* Add your own contributions to the next release on the line below this with your name.
- [ASVideoNode] Fix unreleased time observer. [Flo Vouin](https://github.com/flovouin)
- [PINCache] Set a default .byteLimit to reduce disk usage and startup time. [#595](https://github.com/TextureGroup/Texture/pull/595) [Scott Goodson](https://github.com/appleguy)
- [ASNetworkImageNode] Fix deadlock in GIF handling. [#582](https://github.com/TextureGroup/Texture/pull/582) [Garrett Moon](https://github.com/garrettmoon)
- [ASDisplayNode] Add attributed versions of a11y label, hint and value. [#554](https://github.com/TextureGroup/Texture/pull/554) [Alexander Hüllmandel](https://github.com/fruitcoder)
Expand Down
19 changes: 11 additions & 8 deletions Source/ASVideoNode.mm
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,6 @@ - (void)prepareToPlayAsset:(AVAsset *)asset withKeys:(NSArray<NSString *> *)requ
if (self.image == nil && self.URL == nil) {
[self generatePlaceholderImage];
}

__weak __typeof(self) weakSelf = self;
_timeObserverInterval = CMTimeMake(1, _periodicTimeObserverTimescale);
_timeObserver = [_player addPeriodicTimeObserverForInterval:_timeObserverInterval queue:NULL usingBlock:^(CMTime time){
[weakSelf periodicTimeObserver:time];
}];
}

- (void)addPlayerItemObservers:(AVPlayerItem *)playerItem
Expand Down Expand Up @@ -231,10 +225,21 @@ - (void)addPlayerObservers:(AVPlayer *)player
}

[player addObserver:self forKeyPath:kRate options:NSKeyValueObservingOptionNew context:ASVideoNodeContext];

__weak __typeof(self) weakSelf = self;
_timeObserverInterval = CMTimeMake(1, _periodicTimeObserverTimescale);
_timeObserver = [player addPeriodicTimeObserverForInterval:_timeObserverInterval queue:NULL usingBlock:^(CMTime time){
[weakSelf periodicTimeObserver:time];
}];
}

- (void) removePlayerObservers:(AVPlayer *)player
{
if (_timeObserver != nil) {
[player removeTimeObserver:_timeObserver];
_timeObserver = nil;
}

@try {
[player removeObserver:self forKeyPath:kRate context:ASVideoNodeContext];
}
Expand Down Expand Up @@ -836,8 +841,6 @@ - (void)setShouldBePlaying:(BOOL)shouldBePlaying

- (void)dealloc
{
[_player removeTimeObserver:_timeObserver];
_timeObserver = nil;
[self removePlayerItemObservers:_currentPlayerItem];
[self removePlayerObservers:_player];

Expand Down

0 comments on commit 72f31de

Please sign in to comment.