Skip to content

Commit

Permalink
[expo-av] Fix stability issue due to player-item observers not cleane…
Browse files Browse the repository at this point in the history
…d up (expo#9350)

* [expo-av] Cleanup player-item observers

* [nlc] Add expo-av replay option

* [expo-av] Update changelog
  • Loading branch information
IjzerenHein authored Jul 23, 2020
1 parent be3ad9b commit a3954df
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- Fix audio recording after reload. ([#9283](https://github.com/expo/expo/pull/9283) by [@IjzerenHein](https://github.com/IjzerenHein))
- Fix fullscreen events not emitted on iOS. ([#9323](https://github.com/expo/expo/pull/9323) by [@IjzerenHein](https://github.com/IjzerenHein))
- Prevent debugger break when removing observations. ([#9334](https://github.com/expo/expo/pull/9334) by [@IjzerenHein](https://github.com/IjzerenHein))
- Fix iOS stability issue due to player-item observers not cleaned up. ([#9350](https://github.com/expo/expo/pull/9350) by [@IjzerenHein](https://github.com/IjzerenHein))

## 8.3.0 — 2020-07-08

Expand Down
15 changes: 9 additions & 6 deletions ios/EXAV/EXAVPlayerData.m
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,6 @@ - (void)replayWithStatus:(NSDictionary *)status
} else if ([_player.items count] > 1) {
// There is an item ahead of the current item in the queue, so we can just advance to it (it should be seeked to 0)
// and start to play with `setStatus`.
[self _removeObserversForPlayerItem:_player.currentItem];
[_player advanceToNextItem];
[self setStatus:status resolver:resolve rejecter:reject];
} else {
Expand Down Expand Up @@ -546,11 +545,7 @@ - (void)_tryRemoveObserver:(NSObject *)object forKeyPath:(NSString *)path
- (void)_removeObservers
{
[self _tryRemoveObserver:_player forKeyPath:EXAVPlayerDataObserverStatusKeyPath];

for (AVPlayerItem *item in _items) {
[self _removeObserversForPlayerItem:item];
}

[self _removeObserversForPlayerItems];
[self _tryRemoveObserver:_player forKeyPath:EXAVPlayerDataObserverRateKeyPath];
[self _tryRemoveObserver:_player forKeyPath:EXAVPlayerDataObserverCurrentItemKeyPath];
[self _tryRemoveObserver:_player forKeyPath:EXAVPlayerDataObserverTimeControlStatusPath];
Expand All @@ -564,6 +559,13 @@ - (void)_removeTimeObserver
}
}

- (void)_removeObserversForPlayerItems
{
for (AVPlayerItem *item in _items) {
[self _removeObserversForPlayerItem:item];
}
}

- (void)_removeObserversForPlayerItem:(AVPlayerItem *)playerItem
{
[self _tryRemoveObserver:playerItem forKeyPath:EXAVPlayerDataObserverStatusKeyPath];
Expand Down Expand Up @@ -762,6 +764,7 @@ - (void)observeValueForKeyPath:(NSString *)keyPath
strongSelf.replayResolve = nil;
}
} else if ([keyPath isEqualToString:EXAVPlayerDataObserverCurrentItemKeyPath]) {
[strongSelf _removeObserversForPlayerItems];
[strongSelf _addObserversForPlayerItem:change[NSKeyValueChangeNewKey]];
// Treadmill pattern, see: https://developer.apple.com/videos/play/wwdc2016/503/
AVPlayerItem *removedPlayerItem = change[NSKeyValueChangeOldKey];
Expand Down

0 comments on commit a3954df

Please sign in to comment.