Skip to content

Commit

Permalink
Release 3.4.1
Browse files Browse the repository at this point in the history
- 添加 `- [SJPlayModel playableAreaInsets]`. 可以设置可播区域的insets
- 添加 `- [SJPlayModel superviewTag]`. 可以多个播放器在同一界面同时播放了
- 添加 `- [SJVideoPlayerPlaybackController requiresLinearPlayback]`. 可以禁止画中画时的快进快退
- 完善 水印视图. 可以调整水印视图的位置及insets了
- 修复 在设置了`pauseWhenAppDidEnterBackground`画中画进入后台后失效的问题
  • Loading branch information
changsanjiang committed Oct 18, 2020
1 parent abaa79c commit 2613d43
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 20 deletions.
20 changes: 13 additions & 7 deletions SJBaseVideoPlayer/AVPlayer/Core/SJAVPictureInPictureController.m
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ - (nullable instancetype)initWithLayer:(AVPlayerLayer *)layer delegate:(id<SJPic
}

- (void)dealloc {
#ifdef DEBUG
#ifdef SJDEBUG
NSLog(@"%d - %s", (int)__LINE__, __func__);
#endif

Expand Down Expand Up @@ -68,6 +68,10 @@ + (BOOL)isPictureInPictureSupported {
}

- (void)startPictureInPicture {
#ifdef SJDEBUG
NSLog(@"%d - -[%@ %s]", (int)__LINE__, NSStringFromClass([self class]), sel_getName(_cmd));
#endif

_wantsPictureInPictureStart = YES;

switch ( self.status ) {
Expand All @@ -86,6 +90,10 @@ - (void)startPictureInPicture {
}

- (void)stopPictureInPicture {
#ifdef SJDEBUG
NSLog(@"%d - -[%@ %s]", (int)__LINE__, NSStringFromClass([self class]), sel_getName(_cmd));
#endif

_wantsPictureInPictureStart = NO;

switch ( self.status ) {
Expand All @@ -109,16 +117,14 @@ - (void)_startPictureInPictureIfReady {
BOOL isReady = (_status == SJPictureInPictureStatusStarting) && _pictureInPictureController.isPictureInPicturePossible;

if ( isReady ) {
[_pictureInPictureController startPictureInPicture];

#ifdef SJDEBUG
NSLog(@"%d - %s", (int)__LINE__, __func__);
#endif
dispatch_async(dispatch_get_main_queue(), ^{
[self->_pictureInPictureController startPictureInPicture];
});
}
}

- (void)_stopPictureInPicture {
[_pictureInPictureController stopPictureInPicture];
[self->_pictureInPictureController stopPictureInPicture];
}

- (void)setStatus:(SJPictureInPictureStatus)status {
Expand Down
35 changes: 23 additions & 12 deletions SJBaseVideoPlayer/AVPlayer/SJAVMediaPlaybackController.m
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ - (void)playerWithMedia:(SJVideoPlayerURLAsset *)media completionHandler:(void (
}

- (void)receivedApplicationDidBecomeActiveNotification {
if (@available(iOS 14.0, *)) {
if ( @available(iOS 14.0, *) ) {
if ( _pictureInPictureController.isEnabled )
return;
}
Expand All @@ -74,7 +74,7 @@ - (void)receivedApplicationDidBecomeActiveNotification {
}

- (void)receivedApplicationDidEnterBackgroundNotification {
if (@available(iOS 14.0, *)) {
if ( @available(iOS 14.0, *) ) {
if ( _pictureInPictureController.isEnabled )
return;
}
Expand All @@ -83,27 +83,24 @@ - (void)receivedApplicationDidEnterBackgroundNotification {
[self pause];
}
else {
SJAVMediaPlayerLayerView *view = self.currentPlayerView;
view.layer.player = nil;
[self _removePlayerForLayerIfNeeded];
}
}

- (void)receivedApplicationWillResignActiveNotification {
if (@available(iOS 14.0, *)) {
if ( @available(iOS 14.0, *) ) {
if ( _pictureInPictureController.isEnabled )
return;
}

// 修复 14.0 后台播放失效的问题
if ( @available(iOS 14.0, *) ) {
if ( !self.pauseWhenAppDidEnterBackground ) {
SJAVMediaPlayerLayerView *view = self.currentPlayerView;
view.layer.player = nil;
}
[self _removePlayerForLayerIfNeeded];
}
}

- (void)replaceMediaForDefinitionMedia:(SJVideoPlayerURLAsset *)definitionMedia {
if (@available(iOS 14.0, *)) {
if ( @available(iOS 14.0, *) ) {
[self cancelPictureInPicture];
}
[SJAVMediaPlayerLoader clearPlayerForMedia:self.media];
Expand Down Expand Up @@ -180,7 +177,7 @@ - (void)setMinBufferedDuration:(NSTimeInterval)minBufferedDuration {

- (void)refresh {
if ( self.media != nil ) [SJAVMediaPlayerLoader clearPlayerForMedia:self.media];
if (@available(iOS 14.0, *)) {
if ( @available(iOS 14.0, *) ) {
[self cancelPictureInPicture];
}
[self cancelGenerateGIFOperation];
Expand All @@ -191,7 +188,7 @@ - (void)refresh {
- (void)stop {
[self cancelGenerateGIFOperation];
[self cancelExportOperation];
if (@available(iOS 14.0, *)) {
if ( @available(iOS 14.0, *) ) {
[self cancelPictureInPicture];
}
[super stop];
Expand All @@ -210,6 +207,20 @@ - (void)_av_playbackTypeDidChange:(NSNotification *)note {
}
}
}

- (void)_removePlayerForLayerIfNeeded {
if ( self.pauseWhenAppDidEnterBackground )
return;

if ( @available(iOS 14.0, *) ) {
if ( _pictureInPictureController != nil && self.timeControlStatus != SJPlaybackTimeControlStatusPaused ) {
return;
}
}

SJAVMediaPlayerLayerView *view = self.currentPlayerView;
view.layer.player = nil;
}
@end


Expand Down
2 changes: 1 addition & 1 deletion SJBaseVideoPlayer/SJBaseVideoPlayer.m
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ + (instancetype)player {
}

+ (NSString *)version {
return @"v3.4.0";
return @"v3.4.1";
}

- (void)setVideoGravity:(SJVideoGravity)videoGravity {
Expand Down

0 comments on commit 2613d43

Please sign in to comment.