Skip to content

Commit

Permalink
fix: #38, add play back layer.
Browse files Browse the repository at this point in the history
  • Loading branch information
dito010 committed May 22, 2017
1 parent 7e79e57 commit 8a7be3f
Show file tree
Hide file tree
Showing 13 changed files with 82 additions and 47 deletions.
1 change: 1 addition & 0 deletions .swift-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.0
39 changes: 28 additions & 11 deletions JPVideoPlayer/JPVideoPlayerManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -158,21 +158,24 @@ - (nonnull instancetype)initWithCache:(nonnull JPVideoPlayerCache *)cache downlo
NSString *path = [url.absoluteString stringByReplacingOccurrencesOfString:@"file://" withString:@""];
if ([[NSFileManager defaultManager] fileExistsAtPath:path]) {

BOOL needDisplayProgress = [self needDisplayProgressViewWithDownloadingProgressValue:1 playingProgressValue:0];
BOOL needDisplayProgress = [self needDisplayDownloadingProgressViewWithDownloadingProgressValue:1.0];

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
if (needDisplayProgress) {
[showView performSelector:NSSelectorFromString(@"jp_progressViewDownloadingStatusChangedWithProgressValue:") withObject:@1];
}

// display backLayer.
[showView performSelector:NSSelectorFromString(@"displayBackLayer")];
#pragma clang diagnostic pop

[[JPVideoPlayerPlayVideoTool sharedTool] playExistedVideoWithURL:url fullVideoCachePath:path options:options showOnView:showView playingProgress:^(CGFloat progress) {
__strong typeof(wShowView) sShowView = wShowView;
if (!sShowView) return;
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
BOOL needDisplayProgress = [self needDisplayProgressViewWithDownloadingProgressValue:sShowView.downloadProgressValue playingProgressValue:progress];
BOOL needDisplayProgress = [self needDisplayPlayingProgressViewWithPlayingProgressValue:progress];
if (needDisplayProgress) {
[sShowView performSelector:NSSelectorFromString(@"jp_progressViewPlayingStatusChangedWithProgressValue:") withObject:@(progress)];
}
Expand Down Expand Up @@ -243,9 +246,13 @@ - (nonnull instancetype)initWithCache:(nonnull JPVideoPlayerCache *)cache downlo
if (![JPVideoPlayerPlayVideoTool sharedTool].currentPlayVideoItem) {
__strong typeof(wShowView) sShowView = wShowView;
if (!sShowView) return;

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
// display backLayer.
[sShowView performSelector:NSSelectorFromString(@"displayBackLayer")];
#pragma clang diagnostic pop
[[JPVideoPlayerPlayVideoTool sharedTool] playVideoWithURL:url tempVideoCachePath:tempVideoCachedPath options:options videoFileExceptSize:expectedSize videoFileReceivedSize:storedSize showOnView:sShowView playingProgress:^(CGFloat progress) {
BOOL needDisplayProgress = [self needDisplayProgressViewWithDownloadingProgressValue:sShowView.downloadProgressValue playingProgressValue:progress];
BOOL needDisplayProgress = [self needDisplayPlayingProgressViewWithPlayingProgressValue:progress];
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
if (needDisplayProgress) {
Expand Down Expand Up @@ -354,19 +361,21 @@ - (nonnull instancetype)initWithCache:(nonnull JPVideoPlayerCache *)cache downlo

// play video from disk.
if (cacheType==JPVideoPlayerCacheTypeDisk) {
BOOL needDisplayProgressView = [self needDisplayProgressViewWithDownloadingProgressValue:1 playingProgressValue:0];
BOOL needDisplayProgressView = [self needDisplayDownloadingProgressViewWithDownloadingProgressValue:1.0];
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
if (needDisplayProgressView) {
[showView performSelector:NSSelectorFromString(@"jp_progressViewDownloadingStatusChangedWithProgressValue:") withObject:@1];
}
// display backLayer.
[showView performSelector:NSSelectorFromString(@"displayBackLayer")];
#pragma clang diagnostic pop

[[JPVideoPlayerPlayVideoTool sharedTool] playExistedVideoWithURL:url fullVideoCachePath:videoPath options:options showOnView:showView playingProgress:^(CGFloat progress) {
__strong typeof(wShowView) sShowView = wShowView;
if (!sShowView) return;

BOOL needDisplayProgressView = [self needDisplayProgressViewWithDownloadingProgressValue:1 playingProgressValue:progress];
BOOL needDisplayProgressView = [self needDisplayPlayingProgressViewWithPlayingProgressValue:progress];
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
if (needDisplayProgressView) {
Expand Down Expand Up @@ -476,8 +485,16 @@ -(void)playVideoTool:(JPVideoPlayerPlayVideoTool *)videoTool playingStatuDidChan
#pragma mark -----------------------------------------
#pragma mark Private

-(BOOL)needDisplayProgressViewWithDownloadingProgressValue:(CGFloat)downloadingProgress playingProgressValue:(CGFloat)playingProgress{
return self.delegate && ([self.delegate respondsToSelector:@selector(videoPlayerManager:playingProgressDidChanged:)] || [self.delegate respondsToSelector:@selector(videoPlayerManager:downloadingProgressDidChanged:)]) && ([self.delegate videoPlayerManager:self downloadingProgressDidChanged:downloadingProgress] || [self.delegate videoPlayerManager:self playingProgressDidChanged:playingProgress]);
-(BOOL)needDisplayDownloadingProgressViewWithDownloadingProgressValue:(CGFloat)downloadingProgress{
BOOL respond = self.delegate && [self.delegate respondsToSelector:@selector(videoPlayerManager:downloadingProgressDidChanged:)];
BOOL download = [self.delegate videoPlayerManager:self downloadingProgressDidChanged:downloadingProgress];
return respond && download;
}

-(BOOL)needDisplayPlayingProgressViewWithPlayingProgressValue:(CGFloat)playingProgress{
BOOL respond = self.delegate && [self.delegate respondsToSelector:@selector(videoPlayerManager:playingProgressDidChanged:)];
BOOL playing = [self.delegate videoPlayerManager:self playingProgressDidChanged:playingProgress];
return respond && playing;
}

-(void)hideAllIndicatorAndProgressViewsWithURL:(nullable NSURL *)url options:(JPVideoPlayerOptions)options{
Expand Down Expand Up @@ -506,7 +523,7 @@ -(void)hideActivityViewWithURL:(nullable NSURL *)url options:(JPVideoPlayerOptio
}

-(void)hideProgressViewWithURL:(nullable NSURL *)url options:(JPVideoPlayerOptions)options{
if (![self needDisplayProgressViewWithDownloadingProgressValue:0 playingProgressValue:0]) {
if (![self needDisplayPlayingProgressViewWithPlayingProgressValue:0] || ![self needDisplayDownloadingProgressViewWithDownloadingProgressValue:0]) {
return;
}

Expand All @@ -530,7 +547,7 @@ -(void)hideProgressViewWithURL:(nullable NSURL *)url options:(JPVideoPlayerOptio
}

-(void)progressRefreshWithURL:(nullable NSURL *)url options:(JPVideoPlayerOptions)options receiveSize:(NSUInteger)receiveSize exceptSize:(NSUInteger)expectedSize{
if (![self needDisplayProgressViewWithDownloadingProgressValue:(CGFloat)receiveSize/expectedSize playingProgressValue:self.showViews.firstObject.playingProgressValue]) {
if (![self needDisplayDownloadingProgressViewWithDownloadingProgressValue:(CGFloat)receiveSize/expectedSize]) {
return;
}

Expand All @@ -557,7 +574,7 @@ -(void)showProgressViewAndActivityIndicatorViewForView:(UIView *)view options:(J
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
dispatch_main_async_safe(^{
BOOL needDisplayProgress = [self needDisplayProgressViewWithDownloadingProgressValue:0 playingProgressValue:0];
BOOL needDisplayProgress = [self needDisplayDownloadingProgressViewWithDownloadingProgressValue:0] || [self needDisplayPlayingProgressViewWithPlayingProgressValue:0];

if ((options & JPVideoPlayerShowProgressView) && needDisplayProgress) {
[view performSelector:NSSelectorFromString(@"jp_showProgressView")];
Expand Down
8 changes: 5 additions & 3 deletions JPVideoPlayer/UIView+PlayerStatusAndDownloadIndicator.m
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@ -(UIView *)jp_indicatorView{
view.backgroundColor = [UIColor clearColor];
view.userInteractionEnabled = NO;
objc_setAssociatedObject(self, &indicatorViewKey, view, OBJC_ASSOCIATION_RETAIN_NONATOMIC);

self.jp_backgroundLayer.frame = self.bounds;
[self.jp_videoLayerView.layer addSublayer:self.jp_backgroundLayer];
}
return view;
}
Expand All @@ -80,6 +77,11 @@ -(void)jp_perfersDownloadProgressViewColor:(UIColor *)color{
#pragma mark -----------------------------------------
#pragma mark Private

-(void)displayBackLayer{
self.jp_backgroundLayer.frame = self.bounds;
[self.jp_videoLayerView.layer addSublayer:self.jp_backgroundLayer];
}

-(void)refreshIndicatorViewForPortrait{
[self layoutProgressViewForPortrait:self.progressView];
[self layoutActivityIndicatorViewForPortrait:self.activityIndicatorView];
Expand Down
2 changes: 1 addition & 1 deletion JPVideoPlayer/UIView+WebVideoCache.m
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ -(BOOL)videoPlayerManager:(JPVideoPlayerManager *)videoPlayerManager shouldAutoR
return YES;
}

-(void)videoPlayerManager:(JPVideoPlayerManager *)videoPlayerManager playingStatuDidChanged:(JPVideoPlayerPlayingStatus)playingStatus{
-(void)videoPlayerManager:(JPVideoPlayerManager *)videoPlayerManager playingStatusDidChanged:(JPVideoPlayerPlayingStatus)playingStatus{
self.playingStatus = playingStatus;
if (self.jp_videoPlayerDelegate && [self.jp_videoPlayerDelegate respondsToSelector:@selector(playingStatusDidChanged:)]) {
[self.jp_videoPlayerDelegate playingStatusDidChanged:playingStatus];
Expand Down
Binary file removed JPVideoPlayerDemo/OC/.DS_Store
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@
48FD32691EB6FF3B00ACCB05 /* Player */ = {
isa = PBXGroup;
children = (
48FD326C1EB6FF6300ACCB05 /* Present */,
48FD326C1EB6FF6300ACCB05 /* Push */,
48FD326B1EB6FF5E00ACCB05 /* Home */,
);
name = Player;
Expand Down Expand Up @@ -204,14 +204,14 @@
name = Home;
sourceTree = "<group>";
};
48FD326C1EB6FF6300ACCB05 /* Present */ = {
48FD326C1EB6FF6300ACCB05 /* Push */ = {
isa = PBXGroup;
children = (
481650631ED1AA7B00A18412 /* JPVideoPlayerDemoVC_push.h */,
481650641ED1AA7B00A18412 /* JPVideoPlayerDemoVC_push.m */,
481650651ED1AA7B00A18412 /* JPVideoPlayerDemoVC_push.xib */,
);
name = Present;
name = Push;
sourceTree = "<group>";
};
48FD326E1EB701AC00ACCB05 /* QRCode */ = {
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -158,21 +158,24 @@ - (nonnull instancetype)initWithCache:(nonnull JPVideoPlayerCache *)cache downlo
NSString *path = [url.absoluteString stringByReplacingOccurrencesOfString:@"file://" withString:@""];
if ([[NSFileManager defaultManager] fileExistsAtPath:path]) {

BOOL needDisplayProgress = [self needDisplayProgressViewWithDownloadingProgressValue:1 playingProgressValue:0];
BOOL needDisplayProgress = [self needDisplayDownloadingProgressViewWithDownloadingProgressValue:1.0];

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
if (needDisplayProgress) {
[showView performSelector:NSSelectorFromString(@"jp_progressViewDownloadingStatusChangedWithProgressValue:") withObject:@1];
}

// display backLayer.
[showView performSelector:NSSelectorFromString(@"displayBackLayer")];
#pragma clang diagnostic pop

[[JPVideoPlayerPlayVideoTool sharedTool] playExistedVideoWithURL:url fullVideoCachePath:path options:options showOnView:showView playingProgress:^(CGFloat progress) {
__strong typeof(wShowView) sShowView = wShowView;
if (!sShowView) return;
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
BOOL needDisplayProgress = [self needDisplayProgressViewWithDownloadingProgressValue:sShowView.downloadProgressValue playingProgressValue:progress];
BOOL needDisplayProgress = [self needDisplayPlayingProgressViewWithPlayingProgressValue:progress];
if (needDisplayProgress) {
[sShowView performSelector:NSSelectorFromString(@"jp_progressViewPlayingStatusChangedWithProgressValue:") withObject:@(progress)];
}
Expand Down Expand Up @@ -243,9 +246,13 @@ - (nonnull instancetype)initWithCache:(nonnull JPVideoPlayerCache *)cache downlo
if (![JPVideoPlayerPlayVideoTool sharedTool].currentPlayVideoItem) {
__strong typeof(wShowView) sShowView = wShowView;
if (!sShowView) return;

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
// display backLayer.
[sShowView performSelector:NSSelectorFromString(@"displayBackLayer")];
#pragma clang diagnostic pop
[[JPVideoPlayerPlayVideoTool sharedTool] playVideoWithURL:url tempVideoCachePath:tempVideoCachedPath options:options videoFileExceptSize:expectedSize videoFileReceivedSize:storedSize showOnView:sShowView playingProgress:^(CGFloat progress) {
BOOL needDisplayProgress = [self needDisplayProgressViewWithDownloadingProgressValue:sShowView.downloadProgressValue playingProgressValue:progress];
BOOL needDisplayProgress = [self needDisplayPlayingProgressViewWithPlayingProgressValue:progress];
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
if (needDisplayProgress) {
Expand Down Expand Up @@ -354,19 +361,21 @@ - (nonnull instancetype)initWithCache:(nonnull JPVideoPlayerCache *)cache downlo

// play video from disk.
if (cacheType==JPVideoPlayerCacheTypeDisk) {
BOOL needDisplayProgressView = [self needDisplayProgressViewWithDownloadingProgressValue:1 playingProgressValue:0];
BOOL needDisplayProgressView = [self needDisplayDownloadingProgressViewWithDownloadingProgressValue:1.0];
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
if (needDisplayProgressView) {
[showView performSelector:NSSelectorFromString(@"jp_progressViewDownloadingStatusChangedWithProgressValue:") withObject:@1];
}
// display backLayer.
[showView performSelector:NSSelectorFromString(@"displayBackLayer")];
#pragma clang diagnostic pop

[[JPVideoPlayerPlayVideoTool sharedTool] playExistedVideoWithURL:url fullVideoCachePath:videoPath options:options showOnView:showView playingProgress:^(CGFloat progress) {
__strong typeof(wShowView) sShowView = wShowView;
if (!sShowView) return;

BOOL needDisplayProgressView = [self needDisplayProgressViewWithDownloadingProgressValue:1 playingProgressValue:progress];
BOOL needDisplayProgressView = [self needDisplayPlayingProgressViewWithPlayingProgressValue:progress];
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
if (needDisplayProgressView) {
Expand Down Expand Up @@ -476,8 +485,16 @@ -(void)playVideoTool:(JPVideoPlayerPlayVideoTool *)videoTool playingStatuDidChan
#pragma mark -----------------------------------------
#pragma mark Private

-(BOOL)needDisplayProgressViewWithDownloadingProgressValue:(CGFloat)downloadingProgress playingProgressValue:(CGFloat)playingProgress{
return self.delegate && ([self.delegate respondsToSelector:@selector(videoPlayerManager:playingProgressDidChanged:)] || [self.delegate respondsToSelector:@selector(videoPlayerManager:downloadingProgressDidChanged:)]) && ([self.delegate videoPlayerManager:self downloadingProgressDidChanged:downloadingProgress] || [self.delegate videoPlayerManager:self playingProgressDidChanged:playingProgress]);
-(BOOL)needDisplayDownloadingProgressViewWithDownloadingProgressValue:(CGFloat)downloadingProgress{
BOOL respond = self.delegate && [self.delegate respondsToSelector:@selector(videoPlayerManager:downloadingProgressDidChanged:)];
BOOL download = [self.delegate videoPlayerManager:self downloadingProgressDidChanged:downloadingProgress];
return respond && download;
}

-(BOOL)needDisplayPlayingProgressViewWithPlayingProgressValue:(CGFloat)playingProgress{
BOOL respond = self.delegate && [self.delegate respondsToSelector:@selector(videoPlayerManager:playingProgressDidChanged:)];
BOOL playing = [self.delegate videoPlayerManager:self playingProgressDidChanged:playingProgress];
return respond && playing;
}

-(void)hideAllIndicatorAndProgressViewsWithURL:(nullable NSURL *)url options:(JPVideoPlayerOptions)options{
Expand Down Expand Up @@ -506,7 +523,7 @@ -(void)hideActivityViewWithURL:(nullable NSURL *)url options:(JPVideoPlayerOptio
}

-(void)hideProgressViewWithURL:(nullable NSURL *)url options:(JPVideoPlayerOptions)options{
if (![self needDisplayProgressViewWithDownloadingProgressValue:0 playingProgressValue:0]) {
if (![self needDisplayPlayingProgressViewWithPlayingProgressValue:0] || ![self needDisplayDownloadingProgressViewWithDownloadingProgressValue:0]) {
return;
}

Expand All @@ -530,7 +547,7 @@ -(void)hideProgressViewWithURL:(nullable NSURL *)url options:(JPVideoPlayerOptio
}

-(void)progressRefreshWithURL:(nullable NSURL *)url options:(JPVideoPlayerOptions)options receiveSize:(NSUInteger)receiveSize exceptSize:(NSUInteger)expectedSize{
if (![self needDisplayProgressViewWithDownloadingProgressValue:(CGFloat)receiveSize/expectedSize playingProgressValue:self.showViews.firstObject.playingProgressValue]) {
if (![self needDisplayDownloadingProgressViewWithDownloadingProgressValue:(CGFloat)receiveSize/expectedSize]) {
return;
}

Expand All @@ -557,7 +574,7 @@ -(void)showProgressViewAndActivityIndicatorViewForView:(UIView *)view options:(J
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
dispatch_main_async_safe(^{
BOOL needDisplayProgress = [self needDisplayProgressViewWithDownloadingProgressValue:0 playingProgressValue:0];
BOOL needDisplayProgress = [self needDisplayDownloadingProgressViewWithDownloadingProgressValue:0] || [self needDisplayPlayingProgressViewWithPlayingProgressValue:0];

if ((options & JPVideoPlayerShowProgressView) && needDisplayProgress) {
[view performSelector:NSSelectorFromString(@"jp_showProgressView")];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@ -(UIView *)jp_indicatorView{
view.backgroundColor = [UIColor clearColor];
view.userInteractionEnabled = NO;
objc_setAssociatedObject(self, &indicatorViewKey, view, OBJC_ASSOCIATION_RETAIN_NONATOMIC);

self.jp_backgroundLayer.frame = self.bounds;
[self.jp_videoLayerView.layer addSublayer:self.jp_backgroundLayer];
}
return view;
}
Expand All @@ -80,6 +77,11 @@ -(void)jp_perfersDownloadProgressViewColor:(UIColor *)color{
#pragma mark -----------------------------------------
#pragma mark Private

-(void)displayBackLayer{
self.jp_backgroundLayer.frame = self.bounds;
[self.jp_videoLayerView.layer addSublayer:self.jp_backgroundLayer];
}

-(void)refreshIndicatorViewForPortrait{
[self layoutProgressViewForPortrait:self.progressView];
[self layoutActivityIndicatorViewForPortrait:self.activityIndicatorView];
Expand Down
Loading

0 comments on commit 8a7be3f

Please sign in to comment.