在线视频或直播(RTMP)--ijkplayer学习

最近公司要做直播这块,经过一番摸索,我学习了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

Demo地址:https://github.com/hejintaochenxin/fuck_code

git上传单个文件不能超过100M~ 所以我把这个从项目中剥离了出来 大家可以参考本文最上面的链接自己生成,或者可以私我,我直接发给你~


最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容