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

Commit 5814e2a

Browse files
shihchanghsiungsonosChris Yang
authored andcommitted
[video_player] [iOS] Fixed a memory leak in the video player plugin. (#1660)
1 parent 4c6b10e commit 5814e2a

3 files changed

Lines changed: 21 additions & 15 deletions

File tree

packages/video_player/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.10.1+6
2+
3+
* [iOS] Fixed a memory leak with notification observing.
4+
15
## 0.10.1+5
26

37
* Fix race condition while disposing the VideoController.

packages/video_player/ios/Classes/VideoPlayerPlugin.m

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -82,20 +82,22 @@ - (void)addObservers:(AVPlayerItem*)item {
8282
options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew
8383
context:playbackBufferFullContext];
8484

85-
[[NSNotificationCenter defaultCenter] addObserverForName:AVPlayerItemDidPlayToEndTimeNotification
86-
object:[_player currentItem]
87-
queue:[NSOperationQueue mainQueue]
88-
usingBlock:^(NSNotification* note) {
89-
if (self->_isLooping) {
90-
AVPlayerItem* p = [note object];
91-
[p seekToTime:kCMTimeZero
92-
completionHandler:nil];
93-
} else {
94-
if (self->_eventSink) {
95-
self->_eventSink(@{@"event" : @"completed"});
96-
}
97-
}
98-
}];
85+
// Add an observer that will respond to itemDidPlayToEndTime
86+
[[NSNotificationCenter defaultCenter] addObserver:self
87+
selector:@selector(itemDidPlayToEndTime:)
88+
name:AVPlayerItemDidPlayToEndTimeNotification
89+
object:item];
90+
}
91+
92+
- (void)itemDidPlayToEndTime:(NSNotification*)notification {
93+
if (_isLooping) {
94+
AVPlayerItem* p = [notification object];
95+
[p seekToTime:kCMTimeZero completionHandler:nil];
96+
} else {
97+
if (_eventSink) {
98+
_eventSink(@{@"event" : @"completed"});
99+
}
100+
}
99101
}
100102

101103
static inline CGFloat radiansToDegrees(CGFloat radians) {

packages/video_player/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: video_player
22
description: Flutter plugin for displaying inline video with other Flutter
33
widgets on Android and iOS.
44
author: Flutter Team <flutter-dev@googlegroups.com>
5-
version: 0.10.1+5
5+
version: 0.10.1+6
66
homepage: https://github.com/flutter/plugins/tree/master/packages/video_player
77

88
flutter:

0 commit comments

Comments
 (0)