Skip to content

Commit

Permalink
Release 3.5.0
Browse files Browse the repository at this point in the history
- Rename `autoDisappearFloatSmallView` to`hiddenFloatSmallViewWhenPlaybackFi…
- Rename `SJPopPromptController` to `SJPromptPopupController`
- 完善 在开启后台播放时, 从后台进入前台后黑屏的问题
  • Loading branch information
changsanjiang committed Jan 4, 2021
1 parent 94c8adf commit 50b1f17
Show file tree
Hide file tree
Showing 11 changed files with 88 additions and 50 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -967,7 +967,7 @@ ___
///
/// 了解更多请前往协议头文件查看
///
@property (nonatomic, strong, null_resettable) id<SJPopPromptController> popPromptController;
@property (nonatomic, strong, null_resettable) id<SJPromptPopupController> promptPopupController;
```

<h3 id="12.1">12.2 配置提示文本</h3>
Expand Down
2 changes: 1 addition & 1 deletion SJBaseVideoPlayer.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'SJBaseVideoPlayer'
s.version = '3.4.5'
s.version = '3.5.0'
s.summary = 'video player.'
s.description = 'https://github.com/changsanjiang/SJBaseVideoPlayer/blob/master/README.md'
s.homepage = 'https://github.com/changsanjiang/SJBaseVideoPlayer'
Expand Down
1 change: 1 addition & 0 deletions SJBaseVideoPlayer/AVPlayer/Core/SJAVMediaPlayerLayerView.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ NS_ASSUME_NONNULL_BEGIN

@interface SJAVMediaPlayerLayerView : UIView<SJMediaPlayerView>
@property (nonatomic, strong, readonly) AVPlayerLayer *layer;
- (void)setScreenshot:(nullable UIImage *)image;
@end

NS_ASSUME_NONNULL_END
25 changes: 25 additions & 0 deletions SJBaseVideoPlayer/AVPlayer/Core/SJAVMediaPlayerLayerView.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
#import "SJAVMediaPlayerLayerView.h"

NS_ASSUME_NONNULL_BEGIN
@interface SJAVMediaPlayerLayerView ()
@property (nonatomic, strong) CALayer *screenshotLayer;
@end

@implementation SJAVMediaPlayerLayerView
@dynamic layer;

Expand All @@ -22,6 +26,9 @@ - (instancetype)initWithFrame:(CGRect)frame {
if ( self ) {
NSKeyValueObservingOptions ops = NSKeyValueObservingOptionNew;
[self.layer addObserver:self forKeyPath:kReadyForDisplay options:ops context:&kReadyForDisplay];

_screenshotLayer = [CALayer.alloc init];
[self.layer addSublayer:_screenshotLayer];
}
return self;
}
Expand All @@ -32,12 +39,25 @@ - (BOOL)isReadyForDisplay {

- (void)setVideoGravity:(SJVideoGravity)videoGravity {
self.layer.videoGravity = videoGravity;
if ( videoGravity == AVLayerVideoGravityResize ) {
_screenshotLayer.contentsGravity = kCAGravityResize;
}
else if ( videoGravity == AVLayerVideoGravityResizeAspect ) {
_screenshotLayer.contentsGravity = kCAGravityResizeAspect;
}
else if ( videoGravity == AVLayerVideoGravityResizeAspectFill ) {
_screenshotLayer.contentsGravity = kCAGravityResizeAspectFill;
}
}

- (SJVideoGravity)videoGravity {
return self.layer.videoGravity;
}

- (void)setScreenshot:(nullable UIImage *)image {
_screenshotLayer.contents = image != nil ? (__bridge id)(image.CGImage) : nil;
}

- (void)dealloc {
[self.layer removeObserver:self forKeyPath:kReadyForDisplay];
}
Expand All @@ -49,5 +69,10 @@ - (void)observeValueForKeyPath:(nullable NSString *)keyPath ofObject:(nullable i
});
}
}

- (void)layoutSubviews {
[super layoutSubviews];
_screenshotLayer.frame = self.bounds;
}
@end
NS_ASSUME_NONNULL_END
14 changes: 13 additions & 1 deletion SJBaseVideoPlayer/AVPlayer/SJAVMediaPlaybackController.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ - (instancetype)init {
self = [super init];
if ( self ) {
[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(_av_playbackTypeDidChange:) name:SJMediaPlayerPlaybackTypeDidChangeNotification object:nil];
[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(_av_playerViewReadyForDisplay:) name:SJMediaPlayerViewReadyForDisplayNotification object:nil];
}
return self;
}
Expand Down Expand Up @@ -64,7 +65,7 @@ - (void)playerWithMedia:(SJVideoPlayerURLAsset *)media completionHandler:(void (
view.layer.player = player.avPlayer;
return view;
}

- (void)receivedApplicationDidBecomeActiveNotification {
if ( @available(iOS 14.0, *) ) {
if ( _pictureInPictureController.isEnabled )
Expand Down Expand Up @@ -106,6 +107,9 @@ - (void)receivedApplicationWillResignActiveNotification {
return;
}

if ( self.pauseWhenAppDidEnterBackground )
[self.currentPlayerView setScreenshot:self.screenshot];

// 修复 14.0 后台播放失效的问题
if ( @available(iOS 14.0, *) ) {
[self _removePlayerForLayerIfNeeded];
Expand Down Expand Up @@ -232,6 +236,14 @@ - (void)_av_playbackTypeDidChange:(NSNotification *)note {
}
}

- (void)_av_playerViewReadyForDisplay:(NSNotification *)note {
if ( self.currentPlayerView == note.object ) {
if ( self.currentPlayerView.isReadyForDisplay ) {
[self.currentPlayerView setScreenshot:nil];
}
}
}

- (void)_removePlayerForLayerIfNeeded {
if ( self.pauseWhenAppDidEnterBackground )
return;
Expand Down
16 changes: 0 additions & 16 deletions SJBaseVideoPlayer/Common/Implements/SJPopPromptController.h

This file was deleted.

16 changes: 16 additions & 0 deletions SJBaseVideoPlayer/Common/Implements/SJPromptPopupController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// SJPromptPopupController.h
// Pods
//
// Created by 畅三江 on 2019/7/12.
//

#import "SJPromptPopupControllerDefines.h"

NS_ASSUME_NONNULL_BEGIN

@interface SJPromptPopupController : NSObject<SJPromptPopupController>

@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
//
// SJPopPromptController.m
// SJPromptPopupController.m
// Pods
//
// Created by 畅三江 on 2019/7/12.
//

#import "SJPopPromptController.h"
#import "SJPromptPopupController.h"
#if __has_include(<Masonry/Masonry.h>)
#import <Masonry/Masonry.h>
#else
Expand Down Expand Up @@ -58,11 +58,11 @@ - (instancetype)initWithFrame:(CGRect)frame {
@end


@interface SJPopPromptController ()
@interface SJPromptPopupController ()
@property (nonatomic, strong, readonly) NSMutableArray<_SJPopItemContainerView *> *subviews;
@end

@implementation SJPopPromptController
@implementation SJPromptPopupController
@synthesize target = _target;
@synthesize leftMargin = _leftMargin;
@synthesize bottomMargin = _bottomMargin;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
//
// SJPopPromptController.h
// SJPromptPopupController.h
// Pods
//
// Created by 畅三江 on 2019/7/12.
//

#ifndef SJPopPromptControllerProtocol_h
#define SJPopPromptControllerProtocol_h
#ifndef SJPromptPopupControllerProtocol_h
#define SJPromptPopupControllerProtocol_h
#import <UIKit/UIKit.h>

NS_ASSUME_NONNULL_BEGIN
@protocol SJPopPromptController <NSObject>
@protocol SJPromptPopupController <NSObject>
@property (nonatomic) UIEdgeInsets contentInset; ///< default value is UIEdgeInsetsMake(12, 22, 12, 22);
- (void)show:(NSAttributedString *)title;
- (void)show:(NSAttributedString *)title duration:(NSTimeInterval)duration;
Expand All @@ -36,4 +36,4 @@ NS_ASSUME_NONNULL_BEGIN
@end
NS_ASSUME_NONNULL_END

#endif /* SJPopPromptControllerProtocol_h */
#endif /* SJPromptPopupControllerProtocol_h */
6 changes: 3 additions & 3 deletions SJBaseVideoPlayer/SJBaseVideoPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#import "SJDeviceVolumeAndBrightnessManagerDefines.h"
#import "SJFloatSmallViewControllerDefines.h"
#import "SJVideoDefinitionSwitchingInfo.h"
#import "SJPopPromptControllerDefines.h"
#import "SJPromptPopupControllerDefines.h"
#import "SJPlaybackObservation.h"
#import "SJVideoPlayerPresentViewDefines.h"
#import "SJSubtitlesPromptControllerDefines.h"
Expand Down Expand Up @@ -390,7 +390,7 @@ NS_ASSUME_NONNULL_BEGIN
///
/// 了解更多请前往协议头文件查看
///
@property (nonatomic, strong, null_resettable) id<SJPopPromptController> popPromptController;
@property (nonatomic, strong, null_resettable) id<SJPromptPopupController> promptPopupController;
@end


Expand Down Expand Up @@ -731,7 +731,7 @@ NS_ASSUME_NONNULL_BEGIN
///
/// - default value is YES.
///
@property (nonatomic) BOOL autoDisappearFloatSmallView;
@property (nonatomic, getter=isHiddenFloatSmallViewWhenPlaybackFinished) BOOL hiddenFloatSmallViewWhenPlaybackFinished;

///
/// 滚动出去后, 是否暂停. 默认为YES
Expand Down
38 changes: 19 additions & 19 deletions SJBaseVideoPlayer/SJBaseVideoPlayer.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#import "SJPlayerView.h"
#import "SJFloatSmallViewController.h"
#import "SJVideoDefinitionSwitchingInfo+Private.h"
#import "SJPopPromptController.h"
#import "SJPromptPopupController.h"
#import "SJPrompt.h"
#import "SJBaseVideoPlayerConst.h"
#import "SJSubtitlesPromptController.h"
Expand Down Expand Up @@ -88,7 +88,7 @@

struct {
BOOL isAppeared;
BOOL autoDisappearFloatSmallView;
BOOL hiddenFloatSmallViewWhenPlaybackFinished;
} floatSmallViewControl;

} _SJPlayerControlInfo;
Expand Down Expand Up @@ -161,7 +161,7 @@ + (instancetype)player {
}

+ (NSString *)version {
return @"v3.4.3";
return @"v3.5.0";
}

- (void)setVideoGravity:(SJVideoGravity)videoGravity {
Expand Down Expand Up @@ -198,7 +198,7 @@ - (instancetype)init {
_controlInfo->scrollControl.resumePlaybackWhenScrollAppeared = YES;
_controlInfo->playbackControl.autoplayWhenSetNewAsset = YES;
_controlInfo->playbackControl.resumePlaybackWhenPlayerHasFinishedSeeking = YES;
_controlInfo->floatSmallViewControl.autoDisappearFloatSmallView = YES;
_controlInfo->floatSmallViewControl.hiddenFloatSmallViewWhenPlaybackFinished = YES;
_controlInfo->gestureControl.rateWhenLongPressGestureTriggered = 2.0;
_controlInfo->pan.factor = 667;
self.autoManageViewToFitOnScreenOrRotation = YES;
Expand Down Expand Up @@ -1176,7 +1176,7 @@ - (void)playbackController:(id<SJVideoPlayerPlaybackController>)controller curre
}

- (void)playbackController:(id<SJVideoPlayerPlaybackController>)controller playbackDidFinish:(SJFinishedReason)reason {
if ( _floatSmallViewController.isAppeared && self.autoDisappearFloatSmallView ) {
if ( _floatSmallViewController.isAppeared && self.hiddenFloatSmallViewWhenPlaybackFinished ) {
[_floatSmallViewController dismissFloatView];
}

Expand Down Expand Up @@ -2033,11 +2033,11 @@ - (void)_resetFloatSmallViewControllerObserver:(nullable id<SJFloatSmallViewCont
};
}

- (void)setAutoDisappearFloatSmallView:(BOOL)autoDisappearFloatSmallView {
_controlInfo->floatSmallViewControl.autoDisappearFloatSmallView = autoDisappearFloatSmallView;
- (void)setHiddenFloatSmallViewWhenPlaybackFinished:(BOOL)hiddenFloatSmallViewWhenPlaybackFinished {
_controlInfo->floatSmallViewControl.hiddenFloatSmallViewWhenPlaybackFinished = hiddenFloatSmallViewWhenPlaybackFinished;
}
- (BOOL)autoDisappearFloatSmallView {
return _controlInfo->floatSmallViewControl.autoDisappearFloatSmallView;
- (BOOL)isHiddenFloatSmallViewWhenPlaybackFinished {
return _controlInfo->floatSmallViewControl.hiddenFloatSmallViewWhenPlaybackFinished;
}

- (void)setPauseWhenScrollDisappeared:(BOOL)pauseWhenScrollDisappeared {
Expand Down Expand Up @@ -2135,24 +2135,24 @@ - (CGFloat)subtitleHorizontalMinMargin {
#pragma mark - 提示

@implementation SJBaseVideoPlayer (PromptControl)
- (void)setPopPromptController:(nullable id<SJPopPromptController>)popPromptController {
objc_setAssociatedObject(self, @selector(popPromptController), popPromptController, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
if ( popPromptController != nil ) {
[self _setupPopPromptController];
- (void)setPromptPopupController:(nullable id<SJPromptPopupController>)promptPopupController {
objc_setAssociatedObject(self, @selector(promptPopupController), promptPopupController, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
if ( promptPopupController != nil ) {
[self _setupPromptPopupController];
}
}

- (id<SJPopPromptController>)popPromptController {
id<SJPopPromptController>_Nullable controller = objc_getAssociatedObject(self, _cmd);
- (id<SJPromptPopupController>)promptPopupController {
id<SJPromptPopupController>_Nullable controller = objc_getAssociatedObject(self, _cmd);
if ( controller == nil ) {
controller = [SJPopPromptController new];
controller = [SJPromptPopupController new];
objc_setAssociatedObject(self, _cmd, controller, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
[self _setupPopPromptController];
[self _setupPromptPopupController];
}
return controller;
}
- (void)_setupPopPromptController {
id<SJPopPromptController>_Nullable controller = objc_getAssociatedObject(self, @selector(popPromptController));
- (void)_setupPromptPopupController {
id<SJPromptPopupController>_Nullable controller = objc_getAssociatedObject(self, @selector(promptPopupController));
controller.target = self.presentView;
}

Expand Down

0 comments on commit 50b1f17

Please sign in to comment.