HTMIZFPlayer 2.1.8

HTMIZFPlayer 2.1.8

测试已测试
Lang语言 Obj-CObjective C
许可证 MIT
Released最新版本2017年8月

lqwang521维护。



  • 作者:renzifeng
  • renzifeng

一个简单的基于AVPlayer的iOS视频播放器。支持竖屏、横屏屏幕(锁定屏幕方向)。支持调整音量、亮度及视频进度。

中文说明  ZFPlayer剖析  哪些应用使用ZFPlayer

功能

  • [x] 支持横屏和竖屏播放模式,在横屏模式下也可锁定屏幕方向
  • [x] 支持使用在线URL和本地文件播放
  • [x] 在TableviewCell中播放视频
  • [x] 在屏幕左侧滑动可调整亮度
  • [x] 在屏幕右侧滑动可调整音量
  • [x] 水平滑动可快进和回退
  • [x] 全屏模式下滑动进度条控制器,显示视频预览
  • [x] 下载
  • [x] 切换视频分辨率

要求

  • iOS 7+
  • Xcode 8+

新测试版本

测试版本这是一个测试版本,存在一些错误。

组件

用法(支持IB和代码)

设置状态栏颜色

请在info.plist中添加"View controller-based status bar appearance"字段并将其更改为NO

IB使用

将IB拖动到UIView上,视图类为ZFPlayerView

// view
ZFPlayerControlView *controlView = [[ZFPlayerControlView alloc] init];
// model
ZFPlayerModel *playerModel = [[ZFPlayerModel alloc] init];
playerModel.fatherView = ...
playerModel.videoURL = ...
playerModel.title = ...
[self.playerView playerControlView:controlView playerModel:playerModel];
// delegate
self.playerView.delegate = self;
// auto play the video
[self.playerView autoPlayTheVideo];

ZFPlayerDelegate

/** backBtn event */
- (void)zf_playerBackAction;
/** downloadBtn event */
- (void)zf_playerDownload:(NSString *)url;
代码实现(Masonry)使用方法
self.playerView = [[ZFPlayerView alloc] init];
[self.view addSubview:self.playerView];
[self.playerView mas_makeConstraints:^(MASConstraintMaker *make) {
 	make.top.equalTo(self.view).offset(20);
 	make.left.right.equalTo(self.view);
	// Here a 16:9 aspect ratio, can customize the video aspect ratio
    make.height.equalTo(self.playerView.mas_width).multipliedBy(9.0f/16.0f);
}];
// control view(you can custom)
ZFPlayerControlView *controlView = [[ZFPlayerControlView alloc] init];
// model
ZFPlayerModel *playerModel = [[ZFPlayerModel alloc]init];
playerModel.fatherView = ...
playerModel.videoURL = ...
playerModel.title = ...
[self.playerView playerControlView:controlView playerModel:playerModel];

// delegate
self.playerView.delegate = self;
// auto play the video
[self.playerView autoPlayTheVideo];
设置视频的填充模式
 // Set the fill mode of the video, the default settings (ZFPlayerLayerGravityResizeAspect: wait for a proportional fill, until a dimension reaches the area boundary).
 self.playerView.playerLayerGravity = ZFPlayerLayerGravityResizeAspect;
是否有断点下载功能
 // Default is to close the breakpoint download function, such as the need for this feature set here
 self.playerView.hasDownload = YES;
从XX秒开始播放视频
// Play video from XX seconds
playerModel.seekTime = 15;
自动播放视频,默认不自动播放
// Automatically play the video
[self.playerView autoPlayTheVideo];
设置视频占位图
//  The video placeholder image
// If network image and local image set at the same time, ignore the local image, display the network images
ZFPlayerModel *playerModel = [[ZFPlayerModel alloc]init];
// local image
playerModel.placeholderImage = [UIImage imageNamed: @"..."];
// network image
playerModel.placeholderImageURLString = @"https://xxx.jpg";
self.playerView.playerModel = playerModel;
自定义控制层

self.playerView.controlView = your customView;

您需要在我的.m文件中实现以下方法,您可以参考ZFPlayerControlView.m

/** 
 * Set playaer model 
 */
- (void)zf_playerModel:(ZFPlayerModel *)playerModel;

/** 
 * Show controlView
 */
- (void)zf_playerShowControlView;

/** 
 * Hide controlView
 */
- (void)zf_playerHideControlView;

/** 
 * Reset controlView 
 */
- (void)zf_playerResetControlView;

/** 
 * Reset controlView for resolution
 */
- (void)zf_playerResetControlViewForResolution;

/** 
 * Cancel auto fadeout controlView 
 */
- (void)zf_playerCancelAutoFadeOutControlView;

/** 
 * Begin to play
 */
- (void)zf_playerItemPlaying;

/** 
 * Play end 
 */
- (void)zf_playerPlayEnd;

/** 
 * Has download function
 */
- (void)zf_playerHasDownloadFunction:(BOOL)sender;

/**
 * Resolution function
 */
- (void)zf_playerResolutionArray:(NSArray *)resolutionArray;

/** 
 * PlayBtn state (play or pause)
 */
- (void)zf_playerPlayBtnState:(BOOL)state;

/** 
 * LockBtn state 
 */
- (void)zf_playerLockBtnState:(BOOL)state;

/**
 * DownloadBtn state
 */
- (void)zf_playerDownloadBtnState:(BOOL)state;

/** 
 * Player activity
 */
- (void)zf_playerActivity:(BOOL)animated;

/**
 * Set preview View
 */
- (void)zf_playerDraggedTime:(NSInteger)draggedTime sliderImage:(UIImage *)image;

/**
 * Dragged to control video progress
 
 * @param draggedTime Dragged time for video
 * @param totalTime   Total time for video
 * @param forawrd     Whether fast forward
 * @param preview     Is there a preview
 */
- (void)zf_playerDraggedTime:(NSInteger)draggedTime totalTime:(NSInteger)totalTime isForward:(BOOL)forawrd hasPreview:(BOOL)preview;

/** 
 * Dragged end
 */
- (void)zf_playerDraggedEnd;

/**
 * Normal play

 * @param currentTime Current time for video
 * @param totalTime   Total Time for video
 * @param value       Slider value(0.0~1.0)
 */
- (void)zf_playerCurrentTime:(NSInteger)currentTime totalTime:(NSInteger)totalTime sliderValue:(CGFloat)value;

/** 
 * Progress display buffer
 */
- (void)zf_playerSetProgress:(CGFloat)progress;

/** 
 * Video load failure 
 */
- (void)zf_playerItemStatusFailed:(NSError *)error;

/**
 * Bottom shrink play
 */
- (void)zf_playerBottomShrinkPlay;

/**
 * play on cell
 */
- (void)zf_playerCellPlay;

图片示例

Picture effect

Sound adjustment demonstration

Brightness adjustment demonstration

Fast adjustment demonstration

Progress adjustment demonstration

参考链接:


Swift播放器

请参阅BMPlayer,感谢BMPlayer作者的开放源代码。


联系我

许可证

ZFPlayer遵照MIT许可证提供。有关更多信息,请参阅LICENSE文件。