Skip to content

Commit

Permalink
[video_player] [iOS] Fixed a memory leak in the video player plugin. …
Browse files Browse the repository at this point in the history
…(#1660)
  • Loading branch information
shihchanghsiungsonos authored and Chris Yang committed Jul 29, 2019
1 parent f767623 commit 48c5eb1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.10.1+6

* [iOS] Fixed a memory leak with notification observing.

## 0.10.1+5

* Fix race condition while disposing the VideoController.
Expand Down
30 changes: 16 additions & 14 deletions ios/Classes/VideoPlayerPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -82,20 +82,22 @@ - (void)addObservers:(AVPlayerItem*)item {
options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew
context:playbackBufferFullContext];

[[NSNotificationCenter defaultCenter] addObserverForName:AVPlayerItemDidPlayToEndTimeNotification
object:[_player currentItem]
queue:[NSOperationQueue mainQueue]
usingBlock:^(NSNotification* note) {
if (self->_isLooping) {
AVPlayerItem* p = [note object];
[p seekToTime:kCMTimeZero
completionHandler:nil];
} else {
if (self->_eventSink) {
self->_eventSink(@{@"event" : @"completed"});
}
}
}];
// Add an observer that will respond to itemDidPlayToEndTime
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(itemDidPlayToEndTime:)
name:AVPlayerItemDidPlayToEndTimeNotification
object:item];
}

- (void)itemDidPlayToEndTime:(NSNotification*)notification {
if (_isLooping) {
AVPlayerItem* p = [notification object];
[p seekToTime:kCMTimeZero completionHandler:nil];
} else {
if (_eventSink) {
_eventSink(@{@"event" : @"completed"});
}
}
}

static inline CGFloat radiansToDegrees(CGFloat radians) {
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: video_player
description: Flutter plugin for displaying inline video with other Flutter
widgets on Android and iOS.
author: Flutter Team <[email protected]>
version: 0.10.1+5
version: 0.10.1+6
homepage: https://github.com/flutter/plugins/tree/master/packages/video_player

flutter:
Expand Down

0 comments on commit 48c5eb1

Please sign in to comment.