最近公司要做直播這塊,經(jīng)過一番摸索,我學習了ijkplayer這個框架。
1.環(huán)境配置這塊就不再重復網(wǎng)上的例子很多,為大家推薦一篇講得相當詳細的文章:http://www.itdecent.cn/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~ 所以我把這個從項目中剝離了出來 大家可以參考本文最上面的鏈接自己生成,或者可以私我,我直接發(fā)給你~
