WMPlayer是github上的一個(gè)開源框架,在開源庫中算比較完善的一個(gè)庫了试和,支持幾乎所有視頻格式avi讯泣、flv、m3u8阅悍、3gp好渠、RTMP昨稼、RTSP、MKV拳锚、rmvb假栓、wmv、mp4霍掺、mov等匾荆,點(diǎn)贊也有3K左右。
一杆烁、集成其實(shí)很簡單牙丽,將源碼下載下來,直接將下載后的源碼根目錄下的WMPlayer拖進(jìn)到項(xiàng)目中兔魂,看看/WMPlayer/WNPlayer/FFmpeg文件夾中是否有文件烤芦,如果沒有的話,就需要自己編譯FFmpeg析校,或者百度下載一個(gè)即可构罗;
二、去項(xiàng)目setting中設(shè)置
1智玻、設(shè)置Header Search Paths為 $(PROJECT_DIR)/項(xiàng)目名/WMPlayer/WNPlayer/FFmpeg/include
2遂唧、設(shè)置Library Search Paths為 $(PROJECT_DIR)/項(xiàng)目名/WMPlayer/WNPlayer/FFmpeg/lib $(PROJECT_DIR)/WMPlayer/WNPlayer/openssl/lib
3、添加iOS系統(tǒng)的依賴庫
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 = @"視頻監(jiān)控";
? ? self.wnPlayer.urlString = self.path;//可以替換成rtsp協(xié)議的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];
其他的就是代理方法的實(shí)現(xiàn)了:可以根據(jù)自己的需求實(shí)現(xiàn)其代理方法
@protocolWNPlayerDelegate
@optional
//點(diǎn)擊播放暫停按鈕代理方法
-(void)wnplayer:(WNPlayer*)wnplayer clickedPlayOrPauseButton:(UIButton*)playOrPauseBtn;
//點(diǎn)擊關(guān)閉按鈕代理方法
-(void)wnplayer:(WNPlayer*)wnplayer clickedCloseButton:(UIButton*)backBtn;
//點(diǎn)擊全屏按鈕代理方法
-(void)wnplayer:(WNPlayer*)wnplayer clickedFullScreenButton:(UIButton*)fullScreenBtn;
//單擊WMPlayer的代理方法
-(void)wnplayer:(WNPlayer*)wnplayer singleTaped:(UITapGestureRecognizer*)singleTap;
//播放失敗的代理方法
-(void)wnplayerFailedPlay:(WNPlayer*)wnplayer WNPlayerStatus:(WNPlayerStatus)state;
//播放器已經(jīng)拿到視頻的尺寸大小
-(void)wnplayerGotVideoSize:(WNPlayer*)wnplayer videoSize:(CGSize)presentationSize;
//播放完畢的代理方法
-(void)wnplayerFinishedPlay:(WNPlayer*)wnplayer;
@end
喜歡的可以點(diǎn)個(gè)關(guān)注尚困,個(gè)人微信公眾號已經(jīng)開通了:IT科學(xué)技術(shù)蠢箩!可以關(guān)注下,大家一起進(jìn)步成長事甜!