Skip to content

Commit

Permalink
release 3.7.4
Browse files Browse the repository at this point in the history
  • Loading branch information
changsanjiang committed Sep 15, 2022
1 parent d639c47 commit 801c6cf
Show file tree
Hide file tree
Showing 9 changed files with 271 additions and 20 deletions.
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.7.3.4'
s.version = '3.7.4'
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: 0 additions & 1 deletion SJBaseVideoPlayer/AliPlayer/Core/SJAliMediaPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ FOUNDATION_EXTERN NSErrorDomain const SJAliMediaPlayerErrorDomain;
- (instancetype)initWithSource:(__kindof AVPSource *)source config:(nullable AVPConfig *)config cacheConfig:(nullable AVPCacheConfig *)cacheConfig startPosition:(NSTimeInterval)time;

@property (nonatomic) NSTimeInterval trialEndPosition;
@property (nonatomic) BOOL pauseWhenAppDidEnterBackground;
@property (nonatomic) AVPScalingMode scalingMode;
@property (nonatomic) AVPSeekMode seekMode;

Expand Down
12 changes: 2 additions & 10 deletions SJBaseVideoPlayer/AliPlayer/Core/SJAliMediaPlayer.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#import "SJAliMediaPlayer.h"
#import <AliyunPlayer/AliyunPlayer.h>
#import <AliyunPlayer/AliPlayerPictureInPictureDelegate.h>

NS_ASSUME_NONNULL_BEGIN
NSErrorDomain const SJAliMediaPlayerErrorDomain = @"SJAliMediaPlayerErrorDomain";
Expand Down Expand Up @@ -100,7 +101,7 @@ @interface SJAliMediaPlayer ()<AVPDelegate>
@property (nonatomic) SJAssetStatus assetStatus;
@property (nonatomic) CGSize presentationSize;

@property (nonatomic, strong, nullable) AliPlayer *player;
@property (nonatomic, strong, readonly) AliPlayer *player;
@property (nonatomic) AVPStatus playerStatus;
@property (nonatomic) AVPEventType eventType;

Expand All @@ -112,7 +113,6 @@ @interface SJAliMediaPlayer ()<AVPDelegate>
@end

@implementation SJAliMediaPlayer
@synthesize pauseWhenAppDidEnterBackground = _pauseWhenAppDidEnterBackground;
@synthesize playableDuration = _playableDuration;
@synthesize isPlayed = _isPlayed;
@synthesize isReplayed = _isReplayed;
Expand All @@ -130,7 +130,6 @@ - (instancetype)initWithSource:(__kindof AVPSource *)source config:(nullable AVP
_player = AliPlayer.alloc.init;
_player.delegate = (id)_delegateProxy;
_player.playerView = UIView.new;
_pauseWhenAppDidEnterBackground = YES;
_seekMode = AVP_SEEKMODE_INACCURATE;
_needsSeekToStartPosition = time != 0;

Expand All @@ -154,8 +153,6 @@ - (instancetype)initWithSource:(__kindof AVPSource *)source config:(nullable AVP
}

[_player prepare];

[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(applicationDidEnterBackground) name:UIApplicationDidEnterBackgroundNotification object:nil];
}
return self;
}
Expand All @@ -164,7 +161,6 @@ - (void)dealloc {
#ifdef DEBUG
NSLog(@"%d \t %s", (int)__LINE__, __func__);
#endif
[NSNotificationCenter.defaultCenter removeObserver:self];
[_player destroy];
}

Expand Down Expand Up @@ -562,10 +558,6 @@ - (NSTimeInterval)currentTime {
return _seekingInfo.isSeeking ? CMTimeGetSeconds(_seekingInfo.time) : _currentTime;
}

- (void)applicationDidEnterBackground {
if ( self.pauseWhenAppDidEnterBackground ) [self pause];
}

- (BOOL)isPlayedToTrialEndPosition {
return self.trialEndPosition != 0 && self.currentTime >= self.trialEndPosition;
}
Expand Down
20 changes: 20 additions & 0 deletions SJBaseVideoPlayer/AliPlayer/Core/SJAliMediaPlayerInternal.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// SJAliMediaPlayerInternal.h
// Pods
//
// Created by 畅三江 on 2022/9/15.
//

#ifndef SJAliMediaPlayerInternal_h
#define SJAliMediaPlayerInternal_h


#import "SJAliMediaPlayer.h"
#import <AliyunPlayer/AliyunPlayer.h>

NS_ASSUME_NONNULL_BEGIN
@interface SJAliMediaPlayer (Internal)
@property (nonatomic, strong, readonly) AliPlayer *player;
@end
NS_ASSUME_NONNULL_END
#endif /* SJAliMediaPlayerInternal_h */
27 changes: 27 additions & 0 deletions SJBaseVideoPlayer/AliPlayer/Core/SJAliPictureInPictureController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// SJAliPictureInPictureController.h
// SJBaseVideoPlayer.common-AliPlayer-IJKPlayer
//
// Created by 畅三江 on 2022/9/15.
//

#import "SJPictureInPictureControllerDefines.h"
@class SJAliMediaPlayer;

NS_ASSUME_NONNULL_BEGIN
/// 目前仅支持配置: canStartPictureInPictureAutomaticallyFromInline(App进入后台是否自动进入画中画)
///
API_AVAILABLE(ios(15.0)) @interface SJAliPictureInPictureController : NSObject<SJPictureInPictureController>
+ (BOOL)isPictureInPictureSupported;
- (instancetype)initWithPlayer:(SJAliMediaPlayer *)player delegate:(id<SJPictureInPictureControllerDelegate>)delegate;

@property (nonatomic, weak, readonly, nullable) SJAliMediaPlayer *player;

@property (nonatomic) BOOL requiresLinearPlayback;
@property (nonatomic) BOOL canStartPictureInPictureAutomaticallyFromInline;
@property (nonatomic, weak, nullable) id<SJPictureInPictureControllerDelegate> delegate;
@property (nonatomic, readonly) SJPictureInPictureStatus status;
- (void)startPictureInPicture;
- (void)stopPictureInPicture;
@end
NS_ASSUME_NONNULL_END
128 changes: 128 additions & 0 deletions SJBaseVideoPlayer/AliPlayer/Core/SJAliPictureInPictureController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
//
// SJAliPictureInPictureController.m
// SJBaseVideoPlayer.common-AliPlayer-IJKPlayer
//
// Created by 畅三江 on 2022/9/15.
//

#if __has_include(<AliyunPlayer/AliPlayerPictureInPictureDelegate.h>)
#import "SJAliPictureInPictureController.h"
#import <AVKit/AVPictureInPictureController.h>
#import "SJAliMediaPlayerInternal.h"
#import <AliyunPlayer/AliPlayerPictureInPictureDelegate.h>

@interface SJAliPictureInPictureController ()<AliPlayerPictureInPictureDelegate>
@property (nonatomic) SJPictureInPictureStatus status;
@end

@implementation SJAliPictureInPictureController

+ (BOOL)isPictureInPictureSupported {
return AVPictureInPictureController.isPictureInPictureSupported;
}

- (instancetype)initWithPlayer:(SJAliMediaPlayer *)player delegate:(nonnull id<SJPictureInPictureControllerDelegate>)delegate {
self = [super init];
if ( self ) {
_player = player;
_delegate = delegate;
_player.player.pictureInPictureDelegate = self;
}
return self;
}

- (void)setRequiresLinearPlayback:(BOOL)requiresLinearPlayback {
#ifdef DEBUG
NSLog(@"%d - -[%@ %s] 暂未提供相关API", (int)__LINE__, NSStringFromClass([self class]), sel_getName(_cmd));
#endif
}

- (BOOL)requiresLinearPlayback {
#ifdef DEBUG
NSLog(@"%d - -[%@ %s] 暂未提供相关API", (int)__LINE__, NSStringFromClass([self class]), sel_getName(_cmd));
#endif
return NO;
}

- (void)setCanStartPictureInPictureAutomaticallyFromInline:(BOOL)canStartPictureInPictureAutomaticallyFromInline {
if ( canStartPictureInPictureAutomaticallyFromInline != _canStartPictureInPictureAutomaticallyFromInline ) {
_canStartPictureInPictureAutomaticallyFromInline = canStartPictureInPictureAutomaticallyFromInline;
[_player.player setPictureInPictureEnable:canStartPictureInPictureAutomaticallyFromInline];
}
}

- (void)startPictureInPicture {
#ifdef DEBUG
NSLog(@"%d - -[%@ %s] 暂未提供相关API", (int)__LINE__, NSStringFromClass([self class]), sel_getName(_cmd));
#endif
}

- (void)stopPictureInPicture {
//#ifdef DEBUG
// NSLog(@"%d - -[%@ %s] 暂未提供相关API", (int)__LINE__, NSStringFromClass([self class]), sel_getName(_cmd));
//#endif
self.canStartPictureInPictureAutomaticallyFromInline = NO;
}

- (void)setStatus:(SJPictureInPictureStatus)status {
if ( status != _status ) {
_status = status;

if ( [self.delegate respondsToSelector:@selector(pictureInPictureController:statusDidChange:)] ) {
[self.delegate pictureInPictureController:self statusDidChange:status];
}
}
}

#pragma mark - AliPlayerPictureInPictureDelegate

- (void)pictureInPictureControllerWillStartPictureInPicture {
#ifdef SJDEBUG
NSLog(@"%d - -[%@ %s]", (int)__LINE__, NSStringFromClass([self class]), sel_getName(_cmd));
#endif
self.status = SJPictureInPictureStatusStarting;
}

- (void)pictureInPictureControllerDidStartPictureInPicture {
#ifdef SJDEBUG
NSLog(@"%d - -[%@ %s]", (int)__LINE__, NSStringFromClass([self class]), sel_getName(_cmd));
#endif
self.status = SJPictureInPictureStatusRunning;
}

/// 画中画返回app界面,后是否要停止
- (BOOL)pictureInPictureIsPlaybackPaused {
#ifdef SJDEBUG
NSLog(@"%d - -[%@ %s]", (int)__LINE__, NSStringFromClass([self class]), sel_getName(_cmd));
#endif
return NO;
}

- (void)pictureInPictureControllerWillStopPictureInPicture {
#ifdef SJDEBUG
NSLog(@"%d - -[%@ %s]", (int)__LINE__, NSStringFromClass([self class]), sel_getName(_cmd));
#endif
self.status = SJPictureInPictureStatusStopping;
}

- (void)pictureInPictureControllerDidStopPictureInPicture {
#ifdef SJDEBUG
NSLog(@"%d - -[%@ %s]", (int)__LINE__, NSStringFromClass([self class]), sel_getName(_cmd));
#endif
self.status = SJPictureInPictureStatusStopped;
}
@end
#else
@implementation SJAliPictureInPictureController
+ (BOOL)isPictureInPictureSupported {
return NO;
}

- (instancetype)initWithPlayer:(SJAliMediaPlayer *)player delegate:(id<SJPictureInPictureControllerDelegate>)delegate {
return nil;
}

- (void)startPictureInPicture { }
- (void)stopPictureInPicture { }
@end
#endif
96 changes: 90 additions & 6 deletions SJBaseVideoPlayer/AliPlayer/SJAliMediaPlaybackController.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#import "SJAliMediaPlayer.h"
#import "SJAliMediaPlayerLayerView.h"
#import "SJVideoPlayerURLAsset+SJAliMediaPlaybackAdd.h"
#import "SJAliPictureInPictureController.h"

#if __has_include(<SJUIKit/SJRunLoopTaskQueue.h>)
#import <SJUIKit/SJRunLoopTaskQueue.h>
Expand All @@ -18,8 +19,9 @@
#endif

NS_ASSUME_NONNULL_BEGIN
@interface SJAliMediaPlaybackController ()
@interface SJAliMediaPlaybackController ()<SJPictureInPictureControllerDelegate>
@property (nonatomic, strong, nullable) SJVideoPlayerURLAsset *avpTrackMedia;
@property (nonatomic, strong, nullable) SJAliPictureInPictureController *pictureInPictureController API_AVAILABLE(ios(15.0));
@end

@implementation SJAliMediaPlaybackController
Expand All @@ -30,6 +32,10 @@ - (instancetype)init {
_seekMode = AVP_SEEKMODE_INACCURATE;

[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(_onTrackReadyWithNote:) name:SJAliMediaPlayerOnTrackReadyNotification object:nil];

if (@available(iOS 15.0, *)) {
[NSNotificationCenter.defaultCenter addObserver:self selector:@selector(_ali_assetStatusDidChange:) name:SJMediaPlayerAssetStatusDidChangeNotification object:nil];
}
}
return self;
}
Expand All @@ -42,7 +48,6 @@ - (void)playerWithMedia:(SJVideoPlayerURLAsset *)media completionHandler:(void (
if ( !self ) return;
SJAliMediaPlayer *player = [SJAliMediaPlayer.alloc initWithSource:media.source config:media.avpConfig cacheConfig:media.avpCacheConfig startPosition:media.startPosition];
player.seekMode = self.seekMode;
player.pauseWhenAppDidEnterBackground = self.pauseWhenAppDidEnterBackground;
if ( completionHandler ) completionHandler(player);
});
}
Expand All @@ -52,15 +57,38 @@ - (void)playerWithMedia:(SJVideoPlayerURLAsset *)media completionHandler:(void (
return [SJAliMediaPlayerLayerView.alloc initWithPlayer:player];
}

- (void)setPauseWhenAppDidEnterBackground:(BOOL)pauseWhenAppDidEnterBackground {
[super setPauseWhenAppDidEnterBackground:pauseWhenAppDidEnterBackground];
}

- (void)setSeekMode:(AVPSeekMode)seekMode {
_seekMode = seekMode;
self.currentPlayer.seekMode = seekMode;
}

- (void)refresh {
if ( @available(iOS 15.0, *) ) {
[self cancelPictureInPicture];
}
[super refresh];
}

- (void)stop {
if ( @available(iOS 15.0, *) ) {
[self cancelPictureInPicture];
}
[super stop];
}

- (void)receivedApplicationDidEnterBackgroundNotification {
if ( @available(iOS 15.0, *) ) {
// if ( _pictureInPictureController.status == SJPictureInPictureStatusStarting ||
// _pictureInPictureController.status == SJPictureInPictureStatusRunning ) {
// return;
// }
if ( _pictureInPictureController != nil )
return;
}

[super receivedApplicationDidEnterBackgroundNotification];
}

#pragma mark -

- (void)setMinBufferedDuration:(NSTimeInterval)minBufferedDuration {
Expand All @@ -83,6 +111,62 @@ - (SJPlaybackType)playbackType {
return SJPlaybackTypeUnknown;
}

#pragma mark - PiP

- (void)_ali_assetStatusDidChange:(NSNotification *)note API_AVAILABLE(ios(15.0)) {
if ( self.currentPlayer == note.object && self.canStartPictureInPictureAutomaticallyFromInline && self.assetStatus == SJAssetStatusReadyToPlay ) {
[self prepareForPictureInPicture];
}
}

- (BOOL)isPictureInPictureSupported API_AVAILABLE(ios(14.0)) {
if ( @available(iOS 15.0, *) ) return SJAliPictureInPictureController.isPictureInPictureSupported;
return NO;
}

- (void)setCanStartPictureInPictureAutomaticallyFromInline:(BOOL)canStartPictureInPictureAutomaticallyFromInline API_AVAILABLE(ios(14.2)) {
[super setCanStartPictureInPictureAutomaticallyFromInline:canStartPictureInPictureAutomaticallyFromInline];
if ( @available(iOS 15.0, *) ) {
if ( canStartPictureInPictureAutomaticallyFromInline ) [self prepareForPictureInPicture];
}
}

- (void)prepareForPictureInPicture API_AVAILABLE(ios(15.0)) {
if ( _pictureInPictureController == nil && self.assetStatus == SJAssetStatusReadyToPlay ) {
_pictureInPictureController = [SJAliPictureInPictureController.alloc initWithPlayer:self.currentPlayer delegate:self];
_pictureInPictureController.canStartPictureInPictureAutomaticallyFromInline = self.canStartPictureInPictureAutomaticallyFromInline;
}
}

- (void)stopPictureInPicture API_AVAILABLE(ios(14.0)) {
if ( @available(iOS 15.0, *) ) {
[_pictureInPictureController stopPictureInPicture];
_pictureInPictureController = nil;
}
else {
[super stopPictureInPicture];
}
}

- (void)cancelPictureInPicture API_AVAILABLE(ios(14.0)) {
if ( @available(iOS 15.0, *) ) {
[_pictureInPictureController stopPictureInPicture];
_pictureInPictureController = nil;
}
}

- (void)pictureInPictureController:(id<SJPictureInPictureController>)controller statusDidChange:(SJPictureInPictureStatus)status API_AVAILABLE(ios(14.0)) {
if ( [self.delegate respondsToSelector:@selector(playbackController:pictureInPictureStatusDidChange:)] ) {
[self.delegate playbackController:self pictureInPictureStatusDidChange:status];
}
}

- (void)pictureInPictureController:(id<SJPictureInPictureController>)controller restoreUserInterfaceForPictureInPictureStopWithCompletionHandler:(void (^)(BOOL))completionHandler API_AVAILABLE(ios(14.0)) {
#ifdef DEBUG
NSLog(@"%d - -[%@ %s] 暂未提供相关API", (int)__LINE__, NSStringFromClass([self class]), sel_getName(_cmd));
#endif
}

#pragma mark - mark

- (void)_onTrackReadyWithNote:(NSNotification *)note {
Expand Down
Loading

0 comments on commit 801c6cf

Please sign in to comment.