Skip to content

Commit

Permalink
添加了两个回调Block(1. 内部改变rate的回调. 2. 屏幕旋转的回调), 调整了stop方法.
Browse files Browse the repository at this point in the history
  • Loading branch information
changsanjiang committed Dec 23, 2017
1 parent d3958a9 commit 40672bc
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 38 deletions.
2 changes: 1 addition & 1 deletion SJVideoPlayer.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Pod::Spec.new do |s|
s.name = 'SJVideoPlayer'
s.version = '1.3.0'
s.version = '1.3.1'
s.summary = 'video player.'
s.description = 'https://github.com/changsanjiang/SJVideoPlayer/blob/master/README.md'
s.homepage = 'https://github.com/changsanjiang/SJVideoPlayer'
Expand Down
4 changes: 0 additions & 4 deletions SJVideoPlayer/GestureControl/SJPlayerGestureControl.m
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ - (void)_addGestureToControlView {
[_targetView addGestureRecognizer:_singleTap];
[_targetView addGestureRecognizer:_doubleTap];
[_targetView addGestureRecognizer:_panGR];

[_singleTap requireGestureRecognizerToFail:_doubleTap];
[_doubleTap requireGestureRecognizerToFail:_panGR];

}

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
Expand Down
1 change: 0 additions & 1 deletion SJVideoPlayer/Model/SJVideoPlayerAssetCarrier.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

NS_ASSUME_NONNULL_BEGIN

extern NSNotificationName const SJ_AVPlayerRateDidChangeNotification;

@interface SJVideoPlayerAssetCarrier : NSObject

Expand Down
2 changes: 0 additions & 2 deletions SJVideoPlayer/Model/SJVideoPlayerAssetCarrier.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
#import <UIKit/UIKit.h>
#import <objc/message.h>

NSNotificationName const SJ_AVPlayerRateDidChangeNotification = @"SJ_AVPlayerRateDidChangeNotification";

/*!
* Refresh interval for timed observations of AVPlayer
*/
Expand Down
17 changes: 17 additions & 0 deletions SJVideoPlayer/Player/SJVideoPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,18 @@ NS_ASSUME_NONNULL_BEGIN
**/
@property (nonatomic, assign, readwrite) float rate;

/*!
* Call when the rate changes.
*
* 调速时调用.
**/
@property (nonatomic, copy, readwrite, nullable) void(^rateChanged)(SJVideoPlayer *player);

/*!
* 当滑动内部的`rate slider`时候调用. 外部改变`rate`不会调用.
**/
@property (nonatomic, copy, readwrite, nullable) void(^internallyChangedRate)(SJVideoPlayer *player, float rate);

/*!
* loading show this.
*/
Expand Down Expand Up @@ -111,6 +121,13 @@ NS_ASSUME_NONNULL_BEGIN
*/
@property (nonatomic, assign, readwrite) BOOL disableRotation;

/*!
* Call when the screen is rotated.
*
* 屏幕旋转的时候调用.
**/
@property (nonatomic, copy, readwrite, nullable) void(^rotatedScreen)(SJVideoPlayer *player, BOOL isFullScreen);

@property (nonatomic, strong, readwrite) AVLayerVideoGravity videoGravity;

@end
Expand Down
44 changes: 34 additions & 10 deletions SJVideoPlayer/Player/SJVideoPlayer.m
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,7 @@ - (SJVideoPlayerMoreSettingSecondaryView *)moreSecondarySettingView {
if ( !self ) return;
if ( !self.asset ) return;
self.rate = rate;
if ( self.internallyChangedRate ) self.internallyChangedRate(self, rate);
};

_moreSettingFooterViewModel.needChangeVolume = ^(float volume) {
Expand Down Expand Up @@ -604,6 +605,7 @@ - (SJOrentationObserver *)orentation {
}];
}
});
if ( self.rotatedScreen ) self.rotatedScreen(self, observer.isFullScreen);
};

_orentation.rotationCondition = ^BOOL(SJOrentationObserver * _Nonnull observer) {
Expand Down Expand Up @@ -1105,6 +1107,7 @@ - (NSURL *)assetURL {
- (void)setAsset:(SJVideoPlayerAssetCarrier *)asset {
[self stop];
objc_setAssociatedObject(self, @selector(asset), asset, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
if ( !asset ) return;
_presentView.asset = asset;
_controlView.asset = asset;

Expand Down Expand Up @@ -1267,28 +1270,33 @@ - (SJVideoPlayerAssetCarrier *)asset {
return objc_getAssociatedObject(self, _cmd);
}

- (void)_clearAsset {
if ( self.generatePreviewImages && !self.asset.hasBeenGeneratedPreviewImages ) [self.asset cancelPreviewImagesGeneration];
objc_setAssociatedObject(self, @selector(asset), nil, OBJC_ASSOCIATION_ASSIGN);
}

- (void)setMoreSettings:(NSArray<SJVideoPlayerMoreSetting *> *)moreSettings {
objc_setAssociatedObject(self, @selector(moreSettings), moreSettings, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
NSMutableSet<SJVideoPlayerMoreSetting *> *moreSettingsM = [NSMutableSet new];
[moreSettings enumerateObjectsUsingBlock:^(SJVideoPlayerMoreSetting * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
[self addSetting:obj container:moreSettingsM];
[self _addSetting:obj container:moreSettingsM];
}];

[moreSettingsM enumerateObjectsUsingBlock:^(SJVideoPlayerMoreSetting * _Nonnull obj, BOOL * _Nonnull stop) {
[self dressSetting:obj];
[self _dressSetting:obj];
}];
self.moreSettingView.moreSettings = moreSettings;
}

- (void)addSetting:(SJVideoPlayerMoreSetting *)setting container:(NSMutableSet<SJVideoPlayerMoreSetting *> *)moreSttingsM {
- (void)_addSetting:(SJVideoPlayerMoreSetting *)setting container:(NSMutableSet<SJVideoPlayerMoreSetting *> *)moreSttingsM {
[moreSttingsM addObject:setting];
if ( !setting.showTowSetting ) return;
[setting.twoSettingItems enumerateObjectsUsingBlock:^(SJVideoPlayerMoreSettingSecondary * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
[self addSetting:(SJVideoPlayerMoreSetting *)obj container:moreSttingsM];
[self _addSetting:(SJVideoPlayerMoreSetting *)obj container:moreSttingsM];
}];
}

- (void)dressSetting:(SJVideoPlayerMoreSetting *)setting {
- (void)_dressSetting:(SJVideoPlayerMoreSetting *)setting {
if ( !setting.clickedExeBlock ) return;
void(^clickedExeBlock)(SJVideoPlayerMoreSetting *model) = [setting.clickedExeBlock copy];
__weak typeof(self) _self = self;
Expand Down Expand Up @@ -1378,7 +1386,7 @@ - (BOOL)generatePreviewImages {
}

- (void)setClickedBackEvent:(void (^)(SJVideoPlayer *player))clickedBackEvent {
objc_setAssociatedObject(self, @selector(clickedBackEvent), clickedBackEvent, OBJC_ASSOCIATION_COPY);
objc_setAssociatedObject(self, @selector(clickedBackEvent), clickedBackEvent, OBJC_ASSOCIATION_COPY_NONATOMIC);
}

- (void (^)(SJVideoPlayer * _Nonnull))clickedBackEvent {
Expand All @@ -1391,7 +1399,15 @@ - (void)setDisableRotation:(BOOL)disableRotation {

- (BOOL)disableRotation {
return [objc_getAssociatedObject(self, _cmd) boolValue];
}
}

- (void)setRotatedScreen:(void (^)(SJVideoPlayer * _Nonnull, BOOL))rotatedScreen {
objc_setAssociatedObject(self, @selector(rotatedScreen), rotatedScreen, OBJC_ASSOCIATION_COPY_NONATOMIC);
}

- (void (^)(SJVideoPlayer * _Nonnull, BOOL))rotatedScreen {
return objc_getAssociatedObject(self, _cmd);
}

- (void)setVideoGravity:(AVLayerVideoGravity)videoGravity {
objc_setAssociatedObject(self, @selector(videoGravity), videoGravity, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
Expand Down Expand Up @@ -1419,12 +1435,20 @@ - (float)rate {
return [objc_getAssociatedObject(self, _cmd) floatValue];
}

- (void)setRateChanged:(void (^)(SJVideoPlayer * _Nonnull))rateChanged {
objc_setAssociatedObject(self, @selector(rateChanged), rateChanged, OBJC_ASSOCIATION_COPY_NONATOMIC);
}

- (void (^)(SJVideoPlayer * _Nonnull))rateChanged {
return objc_getAssociatedObject(self, _cmd);
}

- (void)setRateChanged:(void (^)(SJVideoPlayer * _Nonnull))rateChanged {
objc_setAssociatedObject(self, @selector(rateChanged), rateChanged, OBJC_ASSOCIATION_COPY_NONATOMIC);
- (void)setInternallyChangedRate:(void (^)(SJVideoPlayer * _Nonnull, float))internallyChangedRate {
objc_setAssociatedObject(self, @selector(internallyChangedRate), internallyChangedRate, OBJC_ASSOCIATION_COPY_NONATOMIC);
}

- (void (^)(SJVideoPlayer * _Nonnull, float))internallyChangedRate {
return objc_getAssociatedObject(self, _cmd);
}

@end
Expand Down Expand Up @@ -1464,7 +1488,7 @@ - (void)stop {
});
if ( !self.asset ) return;
[self _pause];
if ( self.generatePreviewImages && !self.asset.hasBeenGeneratedPreviewImages ) [self.asset cancelPreviewImagesGeneration];
[self _clearAsset];
}

- (void)jumpedToTime:(NSTimeInterval)time completionHandler:(void (^ __nullable)(BOOL finished))completionHandler {
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,4 @@
<Bucket
type = "0"
version = "2.0">
<Breakpoints>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.ExceptionBreakpoint">
<BreakpointContent
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
scope = "0"
stopOnStyle = "0">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket>
1 change: 0 additions & 1 deletion SJVideoPlayerProject/SJVideoPlayerProject/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ @implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationPortrait;
[UIApplication sharedApplication].statusBarHidden = NO;
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
// Override point for customization after application launch.
return YES;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#import "PlayerViewController.h"
#import "SJVideoPlayer.h"
#import <Masonry.h>

#import <SJUIFactory/SJUIFactory.h>

#define Player [SJVideoPlayer sharedPlayer]

Expand All @@ -22,21 +22,19 @@ @implementation PlayerViewController
- (void)viewDidLoad {
[super viewDidLoad];

self.view.backgroundColor = [UIColor blackColor];
self.view.backgroundColor = [UIColor whiteColor];
Player.view.backgroundColor = [UIColor whiteColor];

[self.view addSubview:Player.view];
[Player.view mas_makeConstraints:^(MASConstraintMaker *make) {
make.center.offset(0);
make.top.offset(SJ_is_iPhoneX() ? 34 : 20);
make.leading.trailing.offset(0);
make.height.equalTo(Player.view.mas_width).multipliedBy(9.0f / 16);
}];

Player.placeholder = [UIImage imageNamed:@"test"];
// http://video.cdn.lanwuzhe.com/1493370091000dfb1
// http://vod.lanwuzhe.com/d09d3a5f9ba4491fa771cd63294ad349%2F0831eae12c51428fa7aed3825c511370-5287d2089db37e62345123a1be272f8b.mp4
// Player.asset = [[SJVideoPlayerAssetCarrier alloc] initWithAssetURL:[[NSBundle mainBundle] URLForResource:@"sample.mp4" withExtension:nil] beginTime:10];

Player.asset = [[SJVideoPlayerAssetCarrier alloc] initWithAssetURL:[NSURL URLWithString:@"http://vod.lanwuzhe.com/d09d3a5f9ba4491fa771cd63294ad349%2F0831eae12c51428fa7aed3825c511370-5287d2089db37e62345123a1be272f8b.mp4"] beginTime:10];

__weak typeof(self) _self = self;
Player.clickedBackEvent = ^(SJVideoPlayer * _Nonnull player) {
__strong typeof(_self) self = _self;
Expand All @@ -45,6 +43,15 @@ - (void)viewDidLoad {
[self.navigationController popViewControllerAnimated:YES];
};

Player.rotatedScreen = ^(SJVideoPlayer * _Nonnull player, BOOL isFullScreen) {
if ( isFullScreen ) {
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
}
else {
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
}
};

[self _setPlayerMoreSettingItems];

// Do any additional setup after loading the view.
Expand Down

0 comments on commit 40672bc

Please sign in to comment.