Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions packages/video_player/ios/Classes/VideoPlayerPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ @interface FLTVideoPlayer : NSObject <FlutterTexture, FlutterStreamHandler>
@property(nonatomic, readonly) bool isPlaying;
@property(nonatomic) bool isLooping;
@property(nonatomic, readonly) bool isInitialized;
@property(nonatomic, assign) id notificationObserverId;
- (instancetype)initWithURL:(NSURL*)url frameUpdater:(FLTFrameUpdater*)frameUpdater;
- (void)play;
- (void)pause;
Expand Down Expand Up @@ -82,14 +83,13 @@ - (void)addObservers:(AVPlayerItem*)item {
options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew
context:playbackBufferFullContext];

[[NSNotificationCenter defaultCenter] addObserverForName:AVPlayerItemDidPlayToEndTimeNotification
_notificationObserverId = [[NSNotificationCenter defaultCenter] addObserverForName:AVPlayerItemDidPlayToEndTimeNotification
Copy link
Contributor

Choose a reason for hiding this comment

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

It might be cleaner to just use the addObserver:self here since we are just using mainQueue. This way we can separate the observing implementation out of the addObservers method.

object:[_player currentItem]
queue:[NSOperationQueue mainQueue]
usingBlock:^(NSNotification* note) {
if (self->_isLooping) {
AVPlayerItem* p = [note object];
[p seekToTime:kCMTimeZero
completionHandler:nil];
[p seekToTime:kCMTimeZero];
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems not related.

} else {
if (self->_eventSink) {
self->_eventSink(@{@"event" : @"completed"});
Expand Down Expand Up @@ -395,7 +395,7 @@ - (void)dispose {
forKeyPath:@"playbackBufferFull"
context:playbackBufferFullContext];
[_player replaceCurrentItemWithPlayerItem:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self];
[[NSNotificationCenter defaultCenter] removeObserver:_notificationObserverId];
Copy link
Contributor

Choose a reason for hiding this comment

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

This can be unchanged if we use the addObserver: method as I mentioned in the other comment.

[_eventChannel setStreamHandler:nil];
}

Expand Down