Demo地址:https://github.com/xttxqjfg/videoDemo,喜欢的可以星星~
为了适应项目的需要,参照网上的例子,对MobileVLCKit做了一个二次封装。
主要功能有全屏、关闭全屏、自动全屏、暂停、播放、快进等基本功能。
项目中用到的是pods来集成MobileVLCKit。pods中的包下载下来在本地看有700多M,集成时保证好网络环境,不然要等很久,不过这700M不会全部加到ipa包中,编译后只有很小的几M。
platform:ios,’8.0’
target “videoDemo” do
pod 'MobileVLCKit', '~> 2.2.2'
end
下面是封装的源代码段
//
// SMAVideoPlayerConst.h
// videoDemo
//
#define kMediaLength self.player.media.length
#define kRGB(r,g,b) [UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:1]
#define kSCREEN_BOUNDS [[UIScreen mainScreen] bounds]
static const CGFloat SMA_ProgressWidth = 3.0f;
static const CGFloat SMA_VideoControlBarHeight = 40.0;
static const CGFloat SMA_VideoControlSliderHeight = 10.0;
static const CGFloat SMA_VideoControlAnimationTimeinterval = 0.3;
static const CGFloat SMA_VideoControlTimeLabelFontSize = 10.0;
static const CGFloat SMA_VideoControlBarAutoFadeOutTimeinterval = 4.0;
static const CGFloat SMA_VideoControlCorrectValue = 3;
static const CGFloat SMA_VideoControlAlertAlpha = 0.75;
#import <UIKit/UIKit.h>
@interface SMAVideoToolsView : UIView
//顶部的工具栏,目前包含关闭按钮
@property (nonatomic,strong) UIView *topBar;
//底部的工具栏,目前包含播放、暂停、全屏、进度条、时间等
@property (nonatomic,strong) UIView *bottomBar;
//播放按钮
@property (nonatomic,strong) UIButton *playBtn;
//暂停按钮
@property (nonatomic,strong) UIButton *pauseBtn;
//全屏按钮
@property (nonatomic, strong) UIButton *fullScreenBtn;
//退出全屏按钮
@property (nonatomic, strong) UIButton *smallScreenBtn;
//进度条
@property (nonatomic, strong) UISlider *progressSlider;
//退出按钮
@property (nonatomic, strong) UIButton *closeBtn;
//时间
@property (nonatomic, strong) UILabel *timeLabel;
//背景层
@property (nonatomic, strong) CALayer *bgLayer;
//动画消失
- (void)animateHide;
//动画显示
- (void)animateShow;
//取消延时执行
- (void)autoFadeOutControlBar;
//取消延时执行
- (void)cancelAutoFadeOutControlBar;
@end
//
// SMAVideoToolsView.m
// videoDemo
//
#import "SMAVideoToolsView.h"
#import <MediaPlayer/MediaPlayer.h>
#import "SMAVideoPlayerConst.h"
@interface SMAVideoToolsView()
//点击手势
@property (nonatomic, strong) UIPanGestureRecognizer *tapGesture;
@end
@implementation SMAVideoToolsView
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self setupView];
}
return self;
}
- (void)layoutSubviews
{
[super layoutSubviews];
self.topBar.frame = CGRectMake(CGRectGetMinX(self.bounds), CGRectGetMinY(self.bounds), CGRectGetWidth(self.bounds), SMA_VideoControlBarHeight);
self.closeBtn.frame = CGRectMake(0, CGRectGetMinX(self.topBar.bounds), CGRectGetWidth(self.closeBtn.bounds), CGRectGetHeight(self.closeBtn.bounds));
self.bottomBar.frame = CGRectMake(CGRectGetMinX(self.bounds), CGRectGetHeight(self.bounds) - SMA_VideoControlBarHeight, CGRectGetWidth(self.bounds), SMA_VideoControlBarHeight);
self.progressSlider.frame = CGRectMake(0, -0, CGRectGetWidth(self.bounds), SMA_VideoControlSliderHeight);
self.playBtn.frame = CGRectMake(CGRectGetMinX(self.bottomBar.bounds), CGRectGetHeight(self.bottomBar.bounds)/2 - CGRectGetHeight(self.playBtn.bounds)/2 + CGRectGetHeight(self.progressSlider.frame) * 0.6, CGRectGetWidth(self.playBtn.bounds), CGRectGetHeight(self.playBtn.bounds));
self.pauseBtn.frame = self.playBtn.frame;
self.fullScreenBtn.frame = CGRectMake(CGRectGetWidth(self.bottomBar.bounds) - CGRectGetWidth(self.fullScreenBtn.bounds) - 5, self.playBtn.frame.origin.y, CGRectGetWidth(self.fullScreenBtn.bounds), CGRectGetHeight(self.fullScreenBtn.bou