最近公司要做直播这块,经过一番摸索,我学习了ijkplayer这个框架。
1.环境配置这块就不再重复网上的例子很多,为大家推荐一篇讲得相当详细的文章:http://www.jianshu.com/p/4f21af680c19
2.就讲讲具体的使用:
#import "ViewController.h"
#import <IJKMediaFramework/IJKFFMoviePlayerController.h>
@interface ViewController ()
@property(nonatomic,strong)IJKFFMoviePlayerController * player;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
IJKFFOptions *options = [IJKFFOptions optionsByDefault]; //使用默认配置
NSURL * url = [NSURL URLWithString:@"rtmp://live.hkstv.hk.lxdns.com/live/hks"];
self.player = [[IJKFFMoviePlayerController alloc] initWithContentURL:url withOptions:options]; //初始化播放器,播放在线视频或直播(RTMP)
self.player.view.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
self.player.view.frame = self.view.bounds;
self.player.scalingMode = IJKMPMovieScalingModeAspectFit; //缩放模式
self.player.shouldAutoplay = YES; //开启自动播放
self.view.autoresizesSubviews = YES;
[self.view addSubview:self.player.view];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.player prepareToPlay];
}
-(void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
[self.player shutdown];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
@end
git上传单个文件不能超过100M~ 所以我把这个从项目中剥离了出来 大家可以参考本文最上面的链接自己生成,或者可以私我,我直接发给你~
网友评论