ijkplayer

导入准备(省去茫茫多的打包集成步骤):

1.ijkplayer用法简介
  • 只需要有推流url地址即可
  • 注:最好真机测试,模拟器卡、不流畅
2.抓取数据
- (void)loadData
{
    // 映客数据url
    NSString *urlStr = @"http://116.211.167.106/api/live/aggregation?uid=133825214&interest=1";

    // 请求数据
    AFHTTPSessionManager *mgr = [AFHTTPSessionManager manager];
    mgr.responseSerializer = [AFJSONResponseSerializer serializer];
    mgr.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/plain", nil];
    [mgr GET:urlStr parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, NSDictionary * _Nullable responseObject) {

        _liveData = [MXLiveModel mj_objectArrayWithKeyValuesArray:responseObject[@"lives"]];

        [_tableView reloadData];

    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {

        NSLog(@"%@",error);

    }];
}
3.获取拉流url
- (void)viewDidLoad {
    [super viewDidLoad];

    self.view.backgroundColor = [UIColor whiteColor];

    // 设置直播占位图片
    NSURL *imageUrl = [NSURL URLWithString:[NSString stringWithFormat:@"http://img.meelive.cn/%@",_live.creator.portrait]];
    [self.imageView sd_setImageWithURL:imageUrl placeholderImage:nil];

    // 拉流地址
    NSURL *url = [NSURL URLWithString:_liveData.stream_addr];

    // 创建IJKFFMoviePlayerController:专门用来直播,传入拉流地址
    IJKFFMoviePlayerController *playerVc = [[IJKFFMoviePlayerController alloc] initWithContentURL:url withOptions:nil];

    // 准备播放
    [playerVc prepareToPlay];

    _player = playerVc;

    playerVc.view.frame = [UIScreen mainScreen].bounds;

    [self.view insertSubview:playerVc.view atIndex:1];

}
4.结束播放
  • 界面不播放,一定要记得结束播放,否则会报内存溢出
socket
- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];

    // 界面消失,一定要记得停止播放
    [_player pause];
    [_player stop];
}