-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[video_player] Remove KVO observer on AVPlayerItem on iOS #4683
Conversation
- (void)testPlugin { | ||
FLTVideoPlayerPlugin *plugin = [[FLTVideoPlayerPlugin alloc] init]; | ||
XCTAssertNotNil(plugin); | ||
} |
There was a problem hiding this comment.
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.
@property(nonatomic, readonly) BOOL disposed; | ||
@property(nonatomic, readonly) BOOL isPlaying; | ||
@property(nonatomic) BOOL isLooping; | ||
@property(nonatomic, readonly) BOOL isInitialized; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BOOL
- (void)play; | ||
- (void)pause; | ||
- (void)setIsLooping:(bool)isLooping; | ||
- (void)updatePlayingState; |
There was a problem hiding this comment.
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.
_isInitialized = false; | ||
_isPlaying = false; | ||
_disposed = false; |
There was a problem hiding this comment.
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.
[currentItem removeObserver:self forKeyPath:@"presentationSize"]; | ||
[currentItem removeObserver:self forKeyPath:@"duration"]; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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
.
[self.playersByTextureId | ||
enumerateKeysAndObjectsUsingBlock:^(NSNumber* textureId, FLTVideoPlayer* player, BOOL* stop) { | ||
[self.registry unregisterTexture:textureId.unsignedIntegerValue]; |
There was a problem hiding this comment.
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]; |
There was a problem hiding this comment.
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] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo.
bb43277
to
fd76289
Compare
There was a problem hiding this 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
@@ -1,3 +1,7 @@ | |||
## 2.2.14 | |||
|
|||
* Remove KVO observer on AVPlayerItem on iOS. |
There was a problem hiding this comment.
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)
In #4438 the
AVPlayerItem
presentationSize
andduration
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 ofbool
, lightweight generics, renameplayers
dictionary to the more descriptiveplayersByTextureId
, preferNS_INLINE
tostatic inline
.Fixes flutter/flutter#96849
Pre-launch Checklist
dart format
.)[shared_preferences]
pubspec.yaml
with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.CHANGELOG.md
to add a description of the change, following repository CHANGELOG style.///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.