TMPlayer
一个基于 ZFPlayer 的简单 iOS 视频播放器,由 renzifeng 构建。支持竖屏、横屏播放(锁定屏幕方向)。支持调整音量、亮度和进度。扩展支持在线/离线字幕。
特性
- 支持横竖屏播放模式,在横屏模式下也可以锁定屏幕方向
- 支持在线 URL 和本地文件播放
- 支持在 TableviewCell 中播放视频
- 通过屏幕左侧的垂直滑动调整亮度
- 通过屏幕右侧的垂直滑动调整音量
- 通过水平滑动快速前进和后退
- 全屏模式拖动滑块控制进度,显示视频预览
- 下载
- 切换视频分辨率
- 字幕在线/离线(扩展特性)
示例
要运行示例项目,先克隆仓库,然后从 Example 目录运行 pod install
要求
- iOS 8+
- Xcode 8+
安装
TMPlayer 通过 CocoaPods 提供。要安装它,只需将以下行添加到您的 Podfile 中
pod "TMPlayer"
然后,运行以下命令
$ pod install
使用方法(支持 IB 和代码)
设置状态栏颜色
请在 info.plist 中添加“基于视图控制器状态栏外观”字段,并将其更改为 NO
IB 使用
将 IB 从 UIView 拖拽过来,使用 View 类 ZFPlayerView
而不是 UIView
// 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;
// Subtitle
self.playerView.addSubtitle(...);
// 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];
作者
Nguyễn Khánh Ngọc, [email protected]
参考链接:
- https://segmentfault.com/a/1190000004054258
- http://sky-weihao.github.io/2015/10/06/Video-streaming-and-caching-in-iOS/
- https://developer.apple.com/library/prerelease/ios/documentation/AudioVideo/Conceptual/AVFoundationPG/Articles/02_Playback.html#//apple_ref/doc/uid/TP40010188-CH3-SW8
Object-C 播放器
请参阅ZFPlayer,感谢ZFPlayer作者的贡献。
Swift 播放器
请参阅BMPlayer,感谢BMPlayer作者的贡献。
许可
TMPlayer 在MIT许可下可用。有关更多信息,请参阅LICENSE文件。