Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

[video_player] Remove KVO observer on AVPlayerItem on iOS #4683

Merged
merged 4 commits into from
Jan 21, 2022

Conversation

jmagman
Copy link
Member

@jmagman jmagman commented Jan 20, 2022

In #4438 the AVPlayerItem presentationSize and duration properties are KVO observed, but the observation was not removed when the texture is disposed. Remove the observer.

Also clean up a few things in the plugin, like using BOOL instead of bool, lightweight generics, rename players dictionary to the more descriptive playersByTextureId, prefer NS_INLINE to static inline.

Fixes flutter/flutter#96849

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the relevant style guides and ran the auto-formatter. (Unlike the flutter/flutter repo, the flutter/plugins repo does use dart format.)
  • I signed the CLA.
  • The title of the PR starts with the name of the plugin surrounded by square brackets, e.g. [shared_preferences]
  • I listed at least one issue that this PR fixes in the description above.
  • I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.
  • I updated CHANGELOG.md to add a description of the change, following repository CHANGELOG style.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

Comment on lines -15 to -18
- (void)testPlugin {
FLTVideoPlayerPlugin *plugin = [[FLTVideoPlayerPlugin alloc] init];
XCTAssertNotNil(plugin);
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This smoke test is no longer needed, the other tests also validate plugin instantiation.

Comment on lines +40 to +43
@property(nonatomic, readonly) BOOL disposed;
@property(nonatomic, readonly) BOOL isPlaying;
@property(nonatomic) BOOL isLooping;
@property(nonatomic, readonly) BOOL isInitialized;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BOOL

Comment on lines -47 to -50
- (void)play;
- (void)pause;
- (void)setIsLooping:(bool)isLooping;
- (void)updatePlayingState;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to declare methods in the interface when the methods are only used within the class.

Comment on lines -220 to -222
_isInitialized = false;
_isPlaying = false;
_disposed = false;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to set ivars to false in init. Should be NO anyway.

Comment on lines +458 to +459
[currentItem removeObserver:self forKeyPath:@"presentationSize"];
[currentItem removeObserver:self forKeyPath:@"duration"];
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two lines are the actual fix.

@@ -486,7 +475,8 @@ - (void)dispose {
@interface FLTVideoPlayerPlugin () <FLTVideoPlayerApi>
@property(readonly, weak, nonatomic) NSObject<FlutterTextureRegistry>* registry;
@property(readonly, weak, nonatomic) NSObject<FlutterBinaryMessenger>* messenger;
@property(readonly, strong, nonatomic) NSMutableDictionary* players;
@property(readonly, strong, nonatomic)
NSMutableDictionary<NSNumber*, FLTVideoPlayer*>* playersByTextureId;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lightweight generic, rename to indicate the key is the textureId.

Comment on lines +529 to +531
[self.playersByTextureId
enumerateKeysAndObjectsUsingBlock:^(NSNumber* textureId, FLTVideoPlayer* player, BOOL* stop) {
[self.registry unregisterTexture:textureId.unsignedIntegerValue];
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use enumerateKeysAndObjectsUsingBlock instead of looking up the value inside the key loop.

[player seekTo:[input.position intValue]];
[_registry textureFrameAvailable:input.textureId.intValue];
FLTVideoPlayer* player = self.playersByTextureId[input.textureId];
[player seekTo:input.position.intValue];
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't scrub this file for dot notation, just updated a few spots where it's inconsistent within the same line.

// Input range [-pi, pi] or [-180, 180]
CGFloat degrees = GLKMathRadiansToDegrees((float)radians);
if (degrees < 0) {
// Convert -90 to 270 and -180 to 180
return degrees + 360;
}
// Output degrees in between [0, 360[
// Output degrees in between [0, 360]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo.

Copy link
Contributor

@cyanglaz cyanglaz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks for the clean-ups

@jmagman jmagman added the waiting for tree to go green (Use "autosubmit") This PR is approved and tested, but waiting for the tree to be green to land. label Jan 21, 2022
@@ -1,3 +1,7 @@
## 2.2.14

* Remove KVO observer on AVPlayerItem on iOS.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Removes

(Per the new CHANGELOG style guide for the repo)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
p: video_player platform-ios waiting for tree to go green (Use "autosubmit") This PR is approved and tested, but waiting for the tree to be green to land.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Crashed: com.apple.main-thread : Foundation _NSKeyValueObservationInfoGetObservances
4 participants