Skip to content

Commit

Permalink
Feature/january changes 4 (#230)
Browse files Browse the repository at this point in the history
* Fixed adding/removing observers in iOS

* Fixed adding/removing observers in iOS

* Fixed iOS headers not applied issue

* 0.0.46 release
  • Loading branch information
jhomlala authored Jan 14, 2021
1 parent 05a4a07 commit fd4b63e
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 52 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.0.46
* Fixed iOS AVPlayer observer issue.
* Fixed iOS headers not applied issue.

## 0.0.45
* Added Picture in Picture support.
* Added new parameters in BetterPlayerControlsConfiguration: pipMenuIcon and enablePip.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ This plugin is based on [Chewie](https://github.com/brianegan/chewie). Chewie is

```yaml
dependencies:
better_player: ^0.0.45
better_player: ^0.0.46
```
2. Install it
Expand Down
107 changes: 57 additions & 50 deletions ios/Classes/FLTBetterPlayerPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -89,30 +89,33 @@ - (instancetype)initWithFrameUpdater:(FLTFrameUpdater*)frameUpdater {
selector:@selector(onDisplayLink:)];
[_displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];
_displayLink.paused = YES;
self._observersAdded = false;
return self;
}

- (void)addObservers:(AVPlayerItem*)item {
__observersAdded = true;
[item addObserver:self forKeyPath:@"loadedTimeRanges" options:0 context:timeRangeContext];
[item addObserver:self forKeyPath:@"status" options:0 context:statusContext];
[item addObserver:self
forKeyPath:@"playbackLikelyToKeepUp"
options:0
context:playbackLikelyToKeepUpContext];
[item addObserver:self
forKeyPath:@"playbackBufferEmpty"
options:0
context:playbackBufferEmptyContext];
[item addObserver:self
forKeyPath:@"playbackBufferFull"
options:0
context:playbackBufferFullContext];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(itemDidPlayToEndTime:)
name:AVPlayerItemDidPlayToEndTimeNotification
object:item];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playbackStalled:) name:AVPlayerItemPlaybackStalledNotification object:item ];
if (!self._observersAdded){
[item addObserver:self forKeyPath:@"loadedTimeRanges" options:0 context:timeRangeContext];
[item addObserver:self forKeyPath:@"status" options:0 context:statusContext];
[item addObserver:self
forKeyPath:@"playbackLikelyToKeepUp"
options:0
context:playbackLikelyToKeepUpContext];
[item addObserver:self
forKeyPath:@"playbackBufferEmpty"
options:0
context:playbackBufferEmptyContext];
[item addObserver:self
forKeyPath:@"playbackBufferFull"
options:0
context:playbackBufferFullContext];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(itemDidPlayToEndTime:)
name:AVPlayerItemDidPlayToEndTimeNotification
object:item];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playbackStalled:) name:AVPlayerItemPlaybackStalledNotification object:item ];
self._observersAdded = true;
}
}

- (void)removeVideoOutput {
Expand Down Expand Up @@ -148,22 +151,24 @@ - (void)clear {
}

- (void) removeObservers{
__observersAdded = false;
[[_player currentItem] removeObserver:self forKeyPath:@"status" context:statusContext];
[[_player currentItem] removeObserver:self
forKeyPath:@"loadedTimeRanges"
context:timeRangeContext];
[[_player currentItem] removeObserver:self
forKeyPath:@"playbackLikelyToKeepUp"
context:playbackLikelyToKeepUpContext];
[[_player currentItem] removeObserver:self
forKeyPath:@"playbackBufferEmpty"
context:playbackBufferEmptyContext];
[[_player currentItem] removeObserver:self
forKeyPath:@"playbackBufferFull"
context:playbackBufferFullContext];
[[NSNotificationCenter defaultCenter] removeObserver:self name:AVPlayerItemPlaybackStalledNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self];
if (self._observersAdded){
[[_player currentItem] removeObserver:self forKeyPath:@"status" context:statusContext];
[[_player currentItem] removeObserver:self
forKeyPath:@"loadedTimeRanges"
context:timeRangeContext];
[[_player currentItem] removeObserver:self
forKeyPath:@"playbackLikelyToKeepUp"
context:playbackLikelyToKeepUpContext];
[[_player currentItem] removeObserver:self
forKeyPath:@"playbackBufferEmpty"
context:playbackBufferEmptyContext];
[[_player currentItem] removeObserver:self
forKeyPath:@"playbackBufferFull"
context:playbackBufferFullContext];
[[NSNotificationCenter defaultCenter] removeObserver:self name:AVPlayerItemPlaybackStalledNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self];
self._observersAdded = false;
}
}

- (void)itemDidPlayToEndTime:(NSNotification*)notification {
Expand Down Expand Up @@ -283,13 +288,15 @@ - (void)setDataSourceURL:(NSURL*)url withKey:(NSString*)key withHeaders:(NSDicti
NSURL *proxyURL = [KTVHTTPCache proxyURLWithOriginalURL:url];
item = [AVPlayerItem playerItemWithURL:proxyURL];
} else {
item = [AVPlayerItem playerItemWithURL:url];
AVURLAsset* asset = [AVURLAsset URLAssetWithURL:url
options:@{@"AVURLAssetHTTPHeaderFieldsKey" : headers}];
item = [AVPlayerItem playerItemWithAsset:asset];
}

if (@available(iOS 10.0, *) && overriddenDuration > 0) {
item.forwardPlaybackEndTime = CMTimeMake(overriddenDuration/1000, 1);
}

return [self setDataSourcePlayerItem:item withKey:key];
}

Expand Down Expand Up @@ -357,7 +364,7 @@ - (void)observeValueForKeyPath:(NSString*)path
end = endTime;
}
}

[values addObject:@[ @(start), @(end) ]];
}
_eventSink(@{@"event" : @"bufferingUpdate", @"values" : values, @"key" : _key});
Expand Down Expand Up @@ -407,10 +414,10 @@ - (void)updatePlayingState {
_displayLink.paused = YES;
return;
}
if (__observersAdded == false){
if (!self._observersAdded){
[self addObservers:[_player currentItem]];
}

if (_isPlaying) {
[_player play];
} else {
Expand Down Expand Up @@ -480,7 +487,7 @@ - (int64_t)duration {
if (!CMTIME_IS_INVALID(_player.currentItem.forwardPlaybackEndTime)) {
time = [[_player currentItem] forwardPlaybackEndTime];
}

return FLTCMTimeToMillis(time);
}

Expand Down Expand Up @@ -622,15 +629,15 @@ - (void)pictureInPictureControllerDidStartPictureInPicture:(AVPictureInPictureCo
}

- (void)pictureInPictureControllerWillStopPictureInPicture:(AVPictureInPictureController *)pictureInPictureController API_AVAILABLE(ios(9.0)){

}

- (void)pictureInPictureControllerWillStartPictureInPicture:(AVPictureInPictureController *)pictureInPictureController {

}

- (void)pictureInPictureController:(AVPictureInPictureController *)pictureInPictureController failedToStartPictureInPictureWithError:(NSError *)error {

}

- (void)pictureInPictureController:(AVPictureInPictureController *)pictureInPictureController restoreUserInterfaceForPictureInPictureStopWithCompletionHandler:(void (^)(BOOL))completionHandler {
Expand Down Expand Up @@ -958,13 +965,13 @@ - (void) stopOtherUpdateListener: (FLTBetterPlayer*) player{
[playerToRemoveListener.player removeTimeObserver: timeObserverId];
}
[_timeObserverIdDict removeAllObjects];

}


- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {


if ([@"init" isEqualToString:call.method]) {
// Allow audio playback when the Ring/Silent switch is set to silent
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
Expand Down Expand Up @@ -1086,13 +1093,13 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
return;
}
}

result([NSNumber numberWithBool:false]);
} else if ([@"disablePictureInPicture" isEqualToString:call.method]){
[player disablePictureInPicture];
[player setPictureInPicture:false];
}

else {
result(FlutterMethodNotImplemented);
}
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: better_player
description: Advanced video player based on video_player and Chewie. It's solves many typical use cases and it's easy to run.
version: 0.0.45
version: 0.0.46
authors:
- Jakub Homlala <jhomlala@gmail.com>
homepage: https://github.com/jhomlala/betterplayer
Expand Down

0 comments on commit fd4b63e

Please sign in to comment.