WMPlayer是github上的一个开源框架,在开源库中算比较完善的一个库了,支持几乎所有视频格式avi、flv、m3u8、3gp、RTMP、RTSP、MKV、rmvb、wmv、mp4、mov等,点赞也有3K左右。
一、集成其实很简单,将源码下载下来,直接将下载后的源码根目录下的WMPlayer拖进到项目中,看看/WMPlayer/WNPlayer/FFmpeg文件夹中是否有文件,如果没有的话,就需要自己编译FFmpeg,或者百度下载一个即可;
二、去项目setting中设置
1、设置Header Search Paths为 $(PROJECT_DIR)/项目名/WMPlayer/WNPlayer/FFmpeg/include
2、设置Library Search Paths为 $(PROJECT_DIR)/项目名/WMPlayer/WNPlayer/FFmpeg/lib $(PROJECT_DIR)/WMPlayer/WNPlayer/openssl/lib
3、添加iOS系统的依赖库
MediaPlayer.framework
AudioToolBox.framework
VideoToolBox.framework
OpenGLES.framework
libiconv.tbd
libbz2.tbd
libz.tbd
使用的代码基本如下:
self.wnPlayer = [[WNPlayer alloc] init];
self.wnPlayer.autoplay = YES;
self.wnPlayer.delegate = self;
self.wnPlayer.repeat = YES;
self.wnPlayer.title = @"视频监控";
self.wnPlayer.urlString = self.path;//可以替换成rtsp协议的url
[self.view addSubview:self.wnPlayer];
[self.wnPlayer mas_remakeConstraints:^(MASConstraintMaker *make) {
if([WNPlayer IsiPhoneX]){
if (self.wnPlayer.playerManager.displayView.contentSize.width/self.wnPlayer.playerManager.displayView.contentSize.height<1) {
make.edges.mas_equalTo(UIEdgeInsetsMake(14, 0, 0, 0));
}else{
make.edges.mas_equalTo(UIEdgeInsetsMake(0, 0, 0, 0));
}
}else{
make.edges.mas_equalTo(UIEdgeInsetsMake(0, 0, 0, 0));
}
}];
[self.wnPlayer openWithTCP:YES optionDic:@{@"headers":@"Cookie:FTN5K=f44da28b"}];
[self.wnPlayer play];
其他的就是代理方法的实现了:可以根据自己的需求实现其代理方法
@protocolWNPlayerDelegate
@optional
//点击播放暂停按钮代理方法
-(void)wnplayer:(WNPlayer*)wnplayer clickedPlayOrPauseButton:(UIButton*)playOrPauseBtn;
//点击关闭按钮代理方法
-(void)wnplayer:(WNPlayer*)wnplayer clickedCloseButton:(UIButton*)backBtn;
//点击全屏按钮代理方法
-(void)wnplayer:(WNPlayer*)wnplayer clickedFullScreenButton:(UIButton*)fullScreenBtn;
//单击WMPlayer的代理方法
-(void)wnplayer:(WNPlayer*)wnplayer singleTaped:(UITapGestureRecognizer*)singleTap;
//播放失败的代理方法
-(void)wnplayerFailedPlay:(WNPlayer*)wnplayer WNPlayerStatus:(WNPlayerStatus)state;
//播放器已经拿到视频的尺寸大小
-(void)wnplayerGotVideoSize:(WNPlayer*)wnplayer videoSize:(CGSize)presentationSize;
//播放完毕的代理方法
-(void)wnplayerFinishedPlay:(WNPlayer*)wnplayer;
@end
喜欢的可以点个关注,个人微信公众号已经开通了:IT科学技术!可以关注下,大家一起进步成长!
网友评论