Skip to content
Open

test #259

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified JPVideoPlayer/JPVideoPlayer.bundle/jp_videoplayer_play@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified JPVideoPlayer/JPVideoPlayer.bundle/jp_videoplayer_play@3x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 13 additions & 2 deletions JPVideoPlayer/JPVideoPlayerControlViews.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#import "JPVideoPlayerProtocol.h"

@class JPVideoPlayerControlProgressView,
JPVideoPlayerControlView;
JPVideoPlayerControlView,MRActivityIndicatorView;

NS_ASSUME_NONNULL_BEGIN

Expand Down Expand Up @@ -52,12 +52,15 @@ UIKIT_EXTERN NSString *JPVideoPlayerControlProgressViewUserDidEndDragNotificatio

@end


@interface JPVideoPlayerControlView : UIView<JPVideoPlayerProtocol>

@property (nonatomic, strong, readonly) UIView<JPVideoPlayerProtocol> *controlBar;

@property (nonatomic, strong, readonly) UIImage *blurImage;



/**
* A designated initializer.
*
Expand Down Expand Up @@ -92,16 +95,20 @@ UIKIT_EXTERN const CGFloat JPVideoPlayerProgressViewElementHeight;

@interface JPVideoPlayerBufferingIndicator : UIView<JPVideoPlayerBufferingProtocol>

@property (nonatomic, strong, readonly)UIActivityIndicatorView *activityIndicator;
@property (nonatomic, strong, readonly)MRActivityIndicatorView *activityIndicator;

@property (nonatomic, strong, readonly)UIVisualEffectView *blurView;

@property (nonatomic, assign, readonly, getter=isAnimating)BOOL animating;

@end

typedef void(^JPVideoPlayerControlViewDoubleClickBlock)(void);

@interface JPVideoPlayerView : UIView

@property (nonatomic, copy) JPVideoPlayerControlViewDoubleClickBlock doubleClickBlock;

/**
* A placeholderView to custom your own business.
*/
Expand Down Expand Up @@ -136,6 +143,10 @@ UIKIT_EXTERN const CGFloat JPVideoPlayerProgressViewElementHeight;
* To control need automatic hide controlView when user touched.
*/
@property (nonatomic, assign, readonly) BOOL needAutoHideControlViewWhenUserTapping;
/**
* A top cover view of viedeo.
*/
@property (nonatomic, strong, readonly) UIView *coverContainerView;

- (instancetype)initWithNeedAutoHideControlViewWhenUserTapping:(BOOL)needAutoHideControlViewWhenUserTapping;

Expand Down
120 changes: 84 additions & 36 deletions JPVideoPlayer/JPVideoPlayerControlViews.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#import "JPVideoPlayerControlViews.h"
#import "JPVideoPlayerCompat.h"
#import "UIView+WebVideoCache.h"
#import "MRActivityIndicatorView.h"
#import "UIView+EnlargeEdge.h"

@interface JPVideoPlayerControlProgressView()

Expand Down Expand Up @@ -103,7 +105,7 @@ - (void)playProgressDidChangeElapsedSeconds:(NSTimeInterval)elapsedSeconds
NSParameterAssert(delta <= 1);
delta = MIN(1, delta);
delta = MAX(0, delta);
[self.dragSlider setValue:delta animated:YES];
[self.dragSlider setValue:delta animated:NO];
self.totalSeconds = totalSeconds;
self.elapsedSeconds = elapsedSeconds;
}
Expand Down Expand Up @@ -279,8 +281,8 @@ @interface JPVideoPlayerControlBar()<JPVideoPlayerProtocol>

@end

static const CGFloat kJPVideoPlayerControlBarButtonWidthHeight = 22;
static const CGFloat kJPVideoPlayerControlBarElementGap = 16;
static const CGFloat kJPVideoPlayerControlBarButtonWidthHeight = 28;
static const CGFloat kJPVideoPlayerControlBarElementGap = 15;
static const CGFloat kJPVideoPlayerControlBarTimeLabelWidth = 68;
@implementation JPVideoPlayerControlBar

Expand Down Expand Up @@ -438,7 +440,11 @@ - (void)_setup {
[button setImage:[UIImage imageNamed:[bundlePath stringByAppendingPathComponent:@"jp_videoplayer_play"]] forState:UIControlStateSelected];
[button addTarget:self action:@selector(playButtonDidClick:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:button];

CGRect rc = button.frame;
rc.size.width += 10;
rc.size.height += 10;
button.frame = rc;
[button setEnlargeEdge:15];
button;
});

Expand All @@ -465,8 +471,12 @@ - (void)_setup {
[button setImage:[UIImage imageNamed:[bundlePath stringByAppendingPathComponent:@"jp_videoplayer_landscape"]] forState:UIControlStateNormal];
[button setImage:[UIImage imageNamed:[bundlePath stringByAppendingPathComponent:@"jp_videoplayer_portrait"]] forState:UIControlStateSelected];
[button addTarget:self action:@selector(landscapeButtonDidClick:) forControlEvents:UIControlEventTouchUpInside];
CGRect rc = button.frame;
rc.size.width += 10;
rc.size.height += 10;
button.frame = rc;
[self addSubview:button];

[button setEnlargeEdge:15];
button;
});
}
Expand All @@ -493,7 +503,7 @@ @interface JPVideoPlayerControlView()
@end

static const CGFloat kJPVideoPlayerControlBarHeight = 38;
static const CGFloat kJPVideoPlayerControlBarLandscapeUpOffset = 12;
static const CGFloat kJPVideoPlayerControlBarLandscapeUpOffset = 4;
@implementation JPVideoPlayerControlView

- (instancetype)initWithFrame:(CGRect)frame {
Expand Down Expand Up @@ -728,7 +738,7 @@ - (void)playProgressDidChangeElapsedSeconds:(NSTimeInterval)elapsedSeconds
NSParameterAssert(delta <= 1);
delta = MIN(1, delta);
delta = MAX(0, delta);
[self.elapsedProgressView setProgress:delta animated:YES];
[self.elapsedProgressView setProgress:delta animated:NO];
self.totalSeconds = totalSeconds;
self.elapsedSeconds = elapsedSeconds;
}
Expand Down Expand Up @@ -799,13 +809,13 @@ - (NSUInteger)fetchDragStartLocation {

@interface JPVideoPlayerBufferingIndicator()

@property(nonatomic, strong)UIActivityIndicatorView *activityIndicator;
@property(nonatomic, strong)MRActivityIndicatorView *activityIndicator;

@property(nonatomic, strong)UIVisualEffectView *blurView;
//@property(nonatomic, strong)UIVisualEffectView *blurView;

@property(nonatomic, assign, getter=isAnimating)BOOL animating;

@property (nonatomic, strong) UIView *blurBackgroundView;
//@property (nonatomic, strong) UIView *blurBackgroundView;

@end

Expand All @@ -827,12 +837,15 @@ - (void)layoutThatFits:(CGRect)constrainedRect
nearestViewControllerInViewTree:(UIViewController *_Nullable)nearestViewController
interfaceOrientation:(JPVideoPlayViewInterfaceOrientation)interfaceOrientation {
CGSize referenceSize = constrainedRect.size;
self.blurBackgroundView.frame = CGRectMake((referenceSize.width - JPVideoPlayerBufferingIndicatorWidthHeight) * 0.5,
(referenceSize.height - JPVideoPlayerBufferingIndicatorWidthHeight) * 0.5,
JPVideoPlayerBufferingIndicatorWidthHeight,
JPVideoPlayerBufferingIndicatorWidthHeight);
self.activityIndicator.frame = self.blurBackgroundView.bounds;
self.blurView.frame = self.blurBackgroundView.bounds;
// self.blurBackgroundView.frame = CGRectMake((referenceSize.width - JPVideoPlayerBufferingIndicatorWidthHeight) * 0.5,
// (referenceSize.height - JPVideoPlayerBufferingIndicatorWidthHeight) * 0.5,
// JPVideoPlayerBufferingIndicatorWidthHeight,
// JPVideoPlayerBufferingIndicatorWidthHeight);
self.activityIndicator.frame = CGRectMake((referenceSize.width - JPVideoPlayerBufferingIndicatorWidthHeight) * 0.5,
(referenceSize.height - JPVideoPlayerBufferingIndicatorWidthHeight) * 0.5,
JPVideoPlayerBufferingIndicatorWidthHeight,
JPVideoPlayerBufferingIndicatorWidthHeight);
//self.blurView.frame = self.blurBackgroundView.bounds;
}


Expand Down Expand Up @@ -869,28 +882,30 @@ - (void)didFinishBufferingVideoURL:(NSURL *)videoURL {
- (void)_setup{
self.backgroundColor = [UIColor clearColor];

self.blurBackgroundView = ({
UIView *view = [UIView new];
view.backgroundColor = [UIColor colorWithWhite:1 alpha:0.6];
view.layer.cornerRadius = 10;
view.clipsToBounds = YES;
[self addSubview:view];

view;
});

self.blurView = ({
UIVisualEffectView *blurView = [[UIVisualEffectView alloc]initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
[self.blurBackgroundView addSubview:blurView];

blurView;
});
// self.blurBackgroundView = ({
// UIView *view = [UIView new];
// view.backgroundColor = [UIColor colorWithWhite:1 alpha:0.6];
// view.layer.cornerRadius = 10;
// view.clipsToBounds = YES;
// [self addSubview:view];
//
// view;
// });

// self.blurView = ({
// UIVisualEffectView *blurView = [[UIVisualEffectView alloc]initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
// [self.blurBackgroundView addSubview:blurView];
//
// blurView;
// });

self.activityIndicator = ({
UIActivityIndicatorView *indicator = [UIActivityIndicatorView new];
indicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray;
indicator.color = [UIColor colorWithRed:35.0/255 green:35.0/255 blue:35.0/255 alpha:1];
[self.blurBackgroundView addSubview:indicator];
MRActivityIndicatorView *indicator = [MRActivityIndicatorView new];
indicator.tintColor = [UIColor whiteColor];
//indicator.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray;
//indicator.backgroundColor = [UIColor clearColor];
//indicator.color = [UIColor colorWithRed:35.0/255 green:35.0/255 blue:35.0/255 alpha:1];
[self addSubview:indicator];

indicator;
});
Expand All @@ -914,6 +929,8 @@ @interface JPVideoPlayerView()

@property (nonatomic, strong) UIView *userInteractionContainerView;

@property (nonatomic, strong) UIView *coverContainerView;

@property (nonatomic, strong) NSTimer *timer;

@property(nonatomic, assign) BOOL isInterruptTimer;
Expand Down Expand Up @@ -944,6 +961,7 @@ - (void)setFrame:(CGRect)frame {
self.progressContainerView.frame = self.bounds;
self.bufferingIndicatorContainerView.frame = self.bounds;
self.userInteractionContainerView.frame = CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height - kJPVideoPlayerControlBarHeight);
self.coverContainerView.frame = self.bounds;
[self layoutContainerSubviewsWithBounds:CGRectZero center:CGPointZero frame:frame];
[self callLayoutMethodForContainerSubviews];
}
Expand All @@ -962,6 +980,7 @@ - (void)setBounds:(CGRect)bounds {
self.userInteractionContainerView.center.y - bounds.size.height * 0.5,
bounds.size.width,
bounds.size.height - kJPVideoPlayerControlBarHeight);
self.coverContainerView.frame = self.videoContainerView.frame;
[self layoutContainerSubviewsWithBounds:bounds center:CGPointZero frame:CGRectZero];
[self callLayoutMethodForContainerSubviews];
}
Expand All @@ -980,6 +999,7 @@ - (void)setCenter:(CGPoint)center {
center.x - self.userInteractionContainerView.bounds.size.height * 0.5,
self.userInteractionContainerView.bounds.size.width,
self.userInteractionContainerView.bounds.size.height - kJPVideoPlayerControlBarHeight);
self.coverContainerView.frame = self.videoContainerView.frame;
[self layoutContainerSubviewsWithBounds:CGRectZero center:center frame:CGRectZero];
[self callLayoutMethodForContainerSubviews];
}
Expand Down Expand Up @@ -1010,6 +1030,13 @@ - (void)tapGestureDidTap {
}];
}

- (void)tapGestureDidDoubleTap {
NSLog(@"双击视频");
if(self.doubleClickBlock) {
self.doubleClickBlock();
}
}

- (void)layoutContainerSubviewsWithBounds:(CGRect)bounds center:(CGPoint)center frame:(CGRect)frame {
for(UIView *view in self.controlContainerView.subviews){
if(!CGRectIsEmpty(frame)){
Expand Down Expand Up @@ -1083,6 +1110,13 @@ - (void)callLayoutMethodForContainerSubviews {
for(UIView<JPVideoPlayerProtocol> *view in self.bufferingIndicatorContainerView.subviews){
if([view respondsToSelector:@selector(layoutThatFits:nearestViewControllerInViewTree:interfaceOrientation:)]){
[view layoutThatFits:self.bounds
nearestViewControllerInViewTree:nearestViewController
interfaceOrientation:[self fetchCurrentInterfaceOrientation]];
}
}
for(UIView<JPVideoPlayerProtocol> *view in self.coverContainerView.subviews){
if([view respondsToSelector:@selector(layoutThatFits:nearestViewControllerInViewTree:interfaceOrientation:)]){
[view layoutThatFits:self.bounds
nearestViewControllerInViewTree:nearestViewController
interfaceOrientation:[self fetchCurrentInterfaceOrientation]];
}
Expand Down Expand Up @@ -1163,6 +1197,20 @@ - (void)_setup {
[self.userInteractionContainerView addGestureRecognizer:tapGestureRecognizer];
[self startTimer];
}

UITapGestureRecognizer* doubleTapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGestureDidDoubleTap)];
doubleTapGestureRecognizer.numberOfTapsRequired = 2;
[self.userInteractionContainerView addGestureRecognizer:doubleTapGestureRecognizer];

self.coverContainerView = ({
UIView *view = [UIView new];
view.backgroundColor = [UIColor clearColor];
[self addSubview:view];
view.userInteractionEnabled = NO;

view;
});

[NSNotificationCenter.defaultCenter addObserver:self
selector:@selector(didReceiveUserStartDragNotification)
name:JPVideoPlayerControlProgressViewUserDidStartDragNotification
Expand Down
53 changes: 53 additions & 0 deletions JPVideoPlayer/MRActivityIndicatorView.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//
// MRActivityIndicatorView.h
// MRProgress
//
// Created by 余龙泽 on 14-2-7.
// Copyright (c) 2014年 icephone. All rights reserved.
//

#import <UIKit/UIKit.h>


/**
Use an activity indicator to show that a task is in progress. An activity indicator appears as a circle slice that is
either spinning or stopped.
*/
@interface MRActivityIndicatorView : UIControl {
@package
BOOL _animating;
}

/**
A Boolean value that controls whether the receiver is hidden when the animation is stopped.

If the value of this property is YES (the default), the receiver sets its hidden property (UIView) to YES when receiver
is not animating. If the hidesWhenStopped property is NO, the receiver is not hidden when animation stops. You stop an
animating progress indicator with the stopAnimating method.
*/
@property(nonatomic) BOOL hidesWhenStopped;

/**
Starts the animation of the progress indicator.

When the progress indicator is animated, the gear spins to indicate indeterminate progress. The indicator is animated
until stopAnimating is called.
*/
- (void)startAnimating;

/**
Stops the animation of the progress indicator.

Call this method to stop the animation of the progress indicator started with a call to startAnimating. When animating
is stopped, the indicator is hidden, unless hidesWhenStopped is NO.
*/
- (void)stopAnimating;

/**
Returns whether the receiver is animating.

@return YES if the receiver is animating, otherwise NO.
*/
- (BOOL)isAnimating;

@end
Loading